#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(a,b,c)for(int a=b;a<c;a++)
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
int p[500005];
int fs(int x)
{
if(p[x]==x)return x;
return p[x]=fs(p[x]);
}
void ms(int x,int y)
{
p[fs(x)]=fs(y);
}
int V,E,Q;
vector<pair<int,pii>>edges;
vector<pair<int,int>>adj[500005];
int ans[500005];
signed main(void)
{
ios_base::sync_with_stdio(0);cin.tie(0);
iota(p,p+500005,0);
cin>>V>>E>>Q;
FOR(i,0,E){
int a,b,q;
cin>>a>>b>>q;
edges.pb(mp(-q,mp(a,b)));
edges.pb(mp(-q,mp(b,a)));
}
sort(edges.begin(),edges.end());
for(auto e:edges){
auto &[a,b]=e.second;
if(fs(a)==fs(b))continue;
adj[a].pb(mp(b,-e.first));adj[b].pb(mp(a,-e.first));
ms(a,b);
}
queue<int>q;
FOR(i,0,500005)ans[i]=1000000;
q.push(1);
ans[1]=1000001;
while(!q.empty()){
int c=q.front();q.pop();
for(auto &[n,qu]:adj[c]){
if(ans[n]!=1000000)continue;
ans[n]=min(qu,ans[c]);
q.push(n);
}
}
FOR(i,0,Q){
int q;cin>>q;
cout<<ans[q]<<'\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
19796 KB |
Output is correct |
2 |
Correct |
11 ms |
19820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
20116 KB |
Output is correct |
2 |
Correct |
10 ms |
19864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
24056 KB |
Output is correct |
2 |
Correct |
37 ms |
23444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1906 ms |
213016 KB |
Output is correct |
2 |
Runtime error |
1207 ms |
262144 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |