Codeforces 107A. Dorm Water Supply 搜图
来源:互联网 发布:金宝学圻家印 知乎 编辑:程序博客网 时间:2024/04/29 23:54
有m条边,n个点,每个点都至多有一个入水口和一个出水口,要求找到所有的水塔以及路径中最短的边。
#include <iostream>#include <cstring>using namespace std;struct ANS{ int u; int v; int d;}ans[1111];int cnt;int n,m;int next[1111]={0};int cost[1111]={0};int pre[1111]={0};bool v[1111]={0};void dfs(int i);void dfs(int i,int flow){ v[i]=true; if (next[i]==0) { ans[cnt].d=flow; ans[cnt].v=i; return; } int j=next[i]; if (cost[j]<flow&&cost[j]!=0) { dfs(j,cost[j]); } else { dfs(j,flow); }}int main(){ cnt=0; cin>>n>>m; for (int i=1;i<=m;i++) { int a,b,k; cin>>a>>b>>k; next[a]=b; pre[b]=a; cost[a]=k; } for (int i=1;i<=n;i++) { if (!v[i]&&pre[i]==0&&next[i]!=0) { ans[cnt].u=i; dfs(i,cost[i]); cnt++; } } cout<<cnt<<endl; for (int i=0;i<cnt;i++) { cout<<ans[i].u<<" "<<ans[i].v<<" "<<ans[i].d<<endl; } return 0;}
- Codeforces 107A. Dorm Water Supply 搜图
- codeforces 4A water
- UVALive-6528 Disjoint water supply
- Water Tree CodeForces
- Codeforces Round #352 (Div. 2) A. Summer Camp __ water problem
- You must supply a layout_width attr
- You must supply a layout_width attribute.解决办法
- You must supply a layout_height attribute
- A simple water problem
- A water problem
- A water problem
- hdu5832 A water problem
- A water problem
- A water problem
- A water problem
- A water problem
- A water problem
- HDU5832-A water problem
- 使用VB将ASP代码封装生成DLL文件
- JS----检测各浏览器及版本
- 有声读物交流
- Xcode使用 (—)
- c#声音 Speech 坏境的问题
- Codeforces 107A. Dorm Water Supply 搜图
- apache重写指令
- 用Visual Basic实现Office助手
- 防止你的Java程序被反编译的方法
- c++ socket通信例程
- 相似图片搜索的原理(一)
- Twitter Storm 实时数据处理框架分析总结
- HDU 1160 FatMouse's Speed
- Solr中参数说明