hdu 1142 A Walk Through the Forest
来源:互联网 发布:拜特软件 编辑:程序博客网 时间:2024/06/03 20:29
无聊的一题
#include<iostream>#include<queue>#include<cstring>#include<vector>#define maxn 1010#define inf 1<<30using namespace std;int n,m;vector<int>mapp[maxn];int vaule[maxn][maxn];int d[maxn];int dp[maxn];void init(){for(int i=0;i<=n;i++) mapp[i].clear(),d[i]=inf,dp[i]=0;dp[2]=1;for(int i=0;i<=n;i++){for(int j=0;j<=n;j++) vaule[i][j]=inf;}}void input(){for(int i=0;i<m;i++){int x,y,z;cin>>x>>y>>z;if(vaule[x][y]==inf){mapp[x].push_back(y);mapp[y].push_back(x);}if(z<vaule[x][y]){vaule[x][y]=z;vaule[y][x]=z;}}}void bfs(){queue<int>q;int x,y;x=2;d[2]=0;q.push(x);while(q.size()){int x=q.front();q.pop();for(int i=0;i<mapp[x].size();i++){y=mapp[x][i];if(d[y]>d[x]+vaule[x][y]){d[y]=d[x]+vaule[x][y];q.push(y);}}}//for(int i=1;i<=n;i++) cout<<d[i]<<" ";//cout<<endl;}int dfs(int x){if(dp[x]) return dp[x];for(int i=0;i<mapp[x].size();i++){int y=mapp[x][i];if(d[y]<d[x]){dp[x]+=dfs(y);}}return dp[x];}int main(){cin.sync_with_stdio(false);while(cin>>n>>m&&n){init();input();bfs();cout<<dfs(1)<<endl;}return 0;}
0 0
- HDU 1142 A Walk Through the Forest
- A Walk Through the Forest HDU 1142
- hdu 1142 A Walk Through the Forest
- Hdu-1142 A Walk Through the Forest
- hdu 1142 A Walk Through the Forest
- HDU 1142 A Walk Through the Forest
- HDU 1142 A Walk Through the Forest
- hdu 1142 A Walk Through the Forest
- HDU 1142 A Walk Through the Forest
- HDU 1142 A Walk Through the Forest
- HDU 1142 A Walk Through the Forest
- hdu 1142 A Walk Through the Forest
- hdu 1142 A Walk Through the Forest
- hdu 1142 A Walk Through the Forest
- hdu 1142 A Walk Through the Forest
- HDU 1142 A Walk Through the Forest
- hdu 1142 A Walk Through the Forest
- hdu 1142 A Walk Through the Forest
- Dinic
- HTTP返回代码 201 304 404 500等代表的含义
- 同步构造(下)
- 0826Android基础Gallery+GridView+Spinner+AutoCompleteTextView+ExpandableListView
- 从BL1跳转到BL2
- hdu 1142 A Walk Through the Forest
- 二分图最大匹配
- MYSQL 字符串函数
- hdu 1695 GCD (欧拉函数+容斥原理+线性筛法)
- DexClassLoader的使用
- 线段树 POJ2777 Count Color
- docker cloudstack issue
- 【HDOJ 1021】 Fibonacci Again (矩阵快速幂(裸))
- Http请求与响应