poj3411 Paid Roads
2024-09-08 10:48:32
思路:
搜索。注意点和边都有可能经过多次。
实现:
#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 ;
}
最新文章
- Docker与CI持续集成/CD
- 微信小程序之明源商城系列-01-商城介绍及开发准备
- smartupload 上传与下载(转载)
- C# Winform程序获取外网IP地址
- 【bzoj1066】[SCOI2007]蜥蜴 网络最大流
- 关于Objective-C Associated Objects
- 201521123112《Java程序设计》第9周学习总结
- 实验吧_天下武功唯快不破&;让我进去(哈希长度拓展攻击)
- Ajax_简介: 异步的 JS 和 XML_原生写 ajax 分析其原理_jquery_ajax_art-template
- Py之set操作【转载】
- yii2 中excel表导出
- Windows 10 将MySQL5.5升级为MySQL5.7
- abp中linq的应用
- 2018.3 江苏省计算机等级考试 C语言 编程题答案
- ASP.Net MVC(2) 之目录结构
- rnn-手写数字识别-网络结构-shape
- HTML Tables
- 手动部署一个单节点kubernetes
- [Java]Get与Post,客户端跳转与服务器端跳转
- error:undefined reference to &#39;net_message_processor::net_message_processor()&#39;