POJ-1797-Heavy Transportation
2013-07-31 18:11
253 查看
题目大意是说给出n个顶点和m条边,每个边都有最大承载量,要求求出从1点运送货物到n点,求能运送货物的最大重量。
其实就是求出1->n的所有路径中最小权值的最大值
用spfa可以做,
代码:
其实就是求出1->n的所有路径中最小权值的最大值
用spfa可以做,
代码:
#include<cstdio> #include<cstring> #include<iostream> #include<queue> using namespace std; const int maxn=1e6+100; const int inf=1<<29; int e,n,m,pnt[maxn],nxt[maxn],head[1010],cost[maxn],dist[maxn]; bool vis[1010]; queue<int> q; void AddEdge(int u,int v,int c) { pnt[e]=v;nxt[e]=head[u];cost[e]=c;head[u]=e++; } int Spfa(int st,int ed) { memset(dist,0,sizeof(dist)); memset(vis,0,sizeof(vis)); q.push(st); vis[st]=1; dist[st]=inf; while(!q.empty()) { int u=q.front(); vis[u]=0; q.pop(); for(int i=head[u];i!=-1;i=nxt[i]) { int v=pnt[i]; if(dist[v]<min(dist[u],cost[i])) { dist[v]=min(dist[u],cost[i]); if(!vis[v]) { q.push(v); vis[v]=1; } } } } return dist[ed]; } int main() { int T,cas=1; scanf("%d",&T); while(T--) { memset(head,-1,sizeof(head)); e=0; scanf("%d%d",&n,&m); while(m--) { int u,v,c; scanf("%d%d%d",&u,&v,&c); AddEdge(u,v,c); AddEdge(v,u,c); } printf("Scenario #%d:\n",cas++); printf("%d\n",Spfa(1,n)); printf("\n"); } return 0; }
相关文章推荐
- POJ 1797 Heavy Transportation (Prime 最大生成树)
- POJ 1797
- poj 1797 并查集 / floyd(超时)
- POJ 1797 Heavy Transportation
- POJ 1797
- poj 1797 Heavy Transportation
- poj 1797 Heavy Transportation
- POJ 1797 Heavy Transportation
- poj1797——Heavy Transportation(最大生成树)
- poj 1797(dijkstra变形)
- poj1797
- POJ 1797 - Heavy Transportation
- POJ 1797 - Heavy Transportation(dijkstra变形)
- ACM征途——第一次上传poj 1797作为纪念
- Heavy Transportation POJ - 1797 --- 最短路思维的最大承载量(最大生成树)
- POJ 1797 Heavy Transportation(二分+并查集/kruskal)
- poj 1797 Heavy Transportation
- poj 1797 Heavy Transportation 用的dp的思想
- POJ 1797 Heavy Transportation(最大生成树/最短路变形)
- Heavy Transportation POJ - 1797