-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLightOj1002.cpp
60 lines (59 loc) · 1.36 KB
/
LightOj1002.cpp
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<bits/stdc++.h>
using namespace std;
const int mx=100005;
const int inf=0x3f3f3f3f;
#define node second
#define dis first
#define pb push_back
#define pii pair<int,int>
vector<pii>adj[mx];
int dis[mx];
void dijksatra(int start)
{
int temp;
priority_queue<pii,vector<pii>,greater<pii>>q;
q.push(pii(0,start));
dis[start]=0;
while(!q.empty())
{
int n=q.top().node;
int d=q.top().dis;
q.pop();
for(int i=0;i<adj[n].size();i++)
{
int a=adj[n][i].node;
int b=adj[n][i].dis;
temp=max(d,b);
if(temp<dis[a]) {
dis[a]=temp;
q.push(pii(dis[a],a));
}
}
}
}
int main()
{
int node,edge,t,n,m,i,j,u,v,w,start;
cin>>t;
for(i=1;i<=t;i++)
{
cin>>node>>edge;
for(j=0;j<edge;j++)
{
cin>>u>>v>>w;
adj[u].pb(pii(w,v));
adj[v].pb(pii(w,u));
}
cin>>start;
// memset(dis,200001,sizeof(dis));
for(j=0;j<=node;j++) dis[j]=200001;
dijksatra(start);
cout<<"Case "<<i<<":"<<endl;
for(j=0;j<node;j++)
{
if(dis[j]==200001) cout<<"Impossible"<<endl;
else cout<<dis[j]<<endl;
}
memset(adj,0,sizeof(adj));
}
}