#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int MAXN = 5e5+5;
int par[MAXN];
int ans[MAXN];
int sz[MAXN];
vector<pair<int,int>> v1[MAXN];
vector<pair<int,pair<int,int>>> edges;
int find(int a){
if(par[a] == a){
return a;
}
return par[a] = find(par[a]);
}
void unite(int a,int b){
a = find(a);
b = find(b);
if(a==b){
return;
}
if(sz[a]<sz[b]){
swap(a,b);
}
par[b] = a;
sz[a] +=sz[b];
}
void dfs(int curr,int par,int weight){
ans[curr] = weight;
for(auto x:v1[curr]){
if(x.first!=par){
dfs(x.first,curr,min(weight,x.second));
}
}
}
int main(){
int n,m,q;
cin>>n>>m>>q;
for(int i=1;i<=n;i++){
par[i] = i;
sz[i] = 1;
}
for(int i=1;i<=m;i++){
int x,y,w;
cin>>x>>y>>w;
edges.push_back(make_pair(w,make_pair(x,y)));
}
sort(edges.begin(),edges.end());
reverse(edges.begin(),edges.end());
for(auto x:edges){
int w = x.first;
int a = x.second.first;
int b = x.second.second;
if(find(a)!=find(b)){
unite(a,b);
v1[a].push_back(make_pair(b,w));
v1[b].push_back(make_pair(a,w));
}
}
dfs(1,1,1e9);
for(int i=1;i<=q;i++){
int x;
cin>>x;
cout<<ans[x]<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
12152 KB |
Output is correct |
2 |
Correct |
16 ms |
12152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
12280 KB |
Output is correct |
2 |
Correct |
18 ms |
12152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
129 ms |
15380 KB |
Output is correct |
2 |
Correct |
106 ms |
14932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3555 ms |
104008 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |