思路:

搜索。注意点和边都有可能经过多次。

实现:

 #include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
const int MAXN = , INF = 0x3f3f3f3f;
int n, m;
struct edge
{
int to, c, p, r;
};
vector<edge> G[MAXN];
int vis[MAXN]; int dfs(int now)
{
if (now == n)
return ;
int ans = INF;
for (int i = ; i < G[now].size(); i++)
{
if (vis[G[now][i].to] > ) continue;
vis[G[now][i].to]++;
int x = dfs(G[now][i].to) + G[now][i].r;
ans = min(ans, x);
int y = INF;
if (vis[G[now][i].c])
y = dfs(G[now][i].to) + G[now][i].p;
ans = min(ans, y);
vis[G[now][i].to]--;
}
return ans;
} int main()
{
cin >> n >> m;
int a, b, c, p, r;
for (int i = ; i < m; i++)
{
cin >> a >> b >> c >> p >> r;
G[a].push_back(edge{b, c, p, r});
}
vis[] = true;
int ans = dfs();
if (ans == INF) puts("impossible");
else cout << ans << endl;
return ;
}

最新文章

  1. Docker与CI持续集成/CD
  2. 微信小程序之明源商城系列-01-商城介绍及开发准备
  3. smartupload 上传与下载(转载)
  4. C# Winform程序获取外网IP地址
  5. 【bzoj1066】[SCOI2007]蜥蜴 网络最大流
  6. 关于Objective-C Associated Objects
  7. 201521123112《Java程序设计》第9周学习总结
  8. 实验吧_天下武功唯快不破&amp;让我进去(哈希长度拓展攻击)
  9. Ajax_简介: 异步的 JS 和 XML_原生写 ajax 分析其原理_jquery_ajax_art-template
  10. Py之set操作【转载】
  11. yii2 中excel表导出
  12. Windows 10 将MySQL5.5升级为MySQL5.7
  13. abp中linq的应用
  14. 2018.3 江苏省计算机等级考试 C语言 编程题答案
  15. ASP.Net MVC(2) 之目录结构
  16. rnn-手写数字识别-网络结构-shape
  17. HTML Tables
  18. 手动部署一个单节点kubernetes
  19. [Java]Get与Post,客户端跳转与服务器端跳转
  20. error:undefined reference to &#39;net_message_processor::net_message_processor()&#39;

热门文章

  1. Servlet的客户端请求
  2. mysql设置datetime默认值为now
  3. java代码判断文件类型(判断文件后缀名)
  4. css 實現微信聊天類似的氣泡
  5. 文本分类——NaiveBayes
  6. swift编程语言基础教程 中文版
  7. Oracle新建数据库
  8. 约瑟夫环问题(Josephus)
  9. 剑指offer面试题18-树的子结构
  10. 代理ip 测试