/* Bismillahir Rahmanir Rahim
Solution-Using BFS
*/
#include<bits/stdc++.h>
#define fi(n, m) for(int i=n; i<=m; i++)
#define fd(n, m) for(int i=n; i>=m; i--)
#define inf 100009
using namespace std;
vector<int>vt[105], cost[105];
int dis[105], zz;
void bfs(int st){
queue<int>q;
q.push(st);
dis[st]=0;
int p, sz, temp, xx;
while(!q.empty()){
p=q.front();
q.pop();
sz=vt[p].size();
fi(0, sz-1){
xx=vt[p][i];
temp=max(dis[p], cost[p][i]);
if(temp<dis[xx]){
dis[xx]=temp;
q.push(xx);
}
}
}
}
int main(){
int t, cs=1, n, m, u, v, w, tt, q, ans;
while(1){
cin>>n>>m>>q;
if(n==0&&m==0&&q==0)break;
if(cs!=1)cout<<endl;
fi(0, m-1){
cin>>u>>v>>w;
vt[u].push_back(v);
vt[v].push_back(u);
cost[u].push_back(w);
cost[v].push_back(w);
}
cout<<"Case #"<<cs++<<endl;
while(q--){
fi(1, n) dis[i]=inf;
cin>>tt>>zz;
bfs(tt);
if(dis[zz]==inf)cout<<"no path"<<endl;
else cout<<dis[zz]<<endl;
}
fi(0, n){
vt[i].clear();
cost[i].clear();
}
}
return 0;
}
|
Friday, March 10, 2017
Solution of UVa 10048 Audiophobia
Subscribe to:
Post Comments (Atom)
-
#include<bits/stdc++.h> #define ll long long using namespace std ; ll n , k , t_case ; ll bigmod ( ll b , ll p , ll m...
-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 ...
-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3...
No comments:
Post a Comment