This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 1e9+7;
#define deb(x) cout<<#x<<": "<<x<<endl
int iceil(int a, int b) {
return (a + b - 1) / b;
}
vector<pair<int,pair<int,int>>> edges;
int parent[500001];
int find_ds(int x){
if(parent[x]==x) return(x);
return(parent[x]=find_ds(parent[x]));
}
void union_ds(int a,int b){
a=find_ds(a),b=find_ds(b);
parent[a]=b;
}
vector<pair<int,int>> adj[500001];
int maximum_minimum[500001];
void dfs(int node,int par,int till_now){
maximum_minimum[node]=till_now;
for(auto x:adj[node]){
//deb(x.second);
if(par==x.first) continue;
dfs(x.first,node,min(till_now,x.second));
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(20);
#ifdef strawberryshaker2005
freopen("input.txt", "r", stdin);
#endif
int n,k,q;
cin>>n>>k>>q;
for(int i=1;i<=n;i++) parent[i]=i;
for(int i=0;i<k;i++){
int a,b,c;
cin>>a>>b>>c;
edges.push_back({c,{a,b}});
//edges.push_back({c,{b,a}});
}
sort(edges.begin(),edges.end());
reverse(edges.begin(),edges.end());
for(auto e:edges){
int one=e.second.first,two=e.second.second,three=e.first;
if(find_ds(one)==find_ds(two)) continue;
adj[one].push_back({two,three});
adj[two].push_back({one,three});
union_ds(one,two);
}
dfs(1,-1,mod);
//for(int i=1;i<=n;i++) cout<<maximum_minimum[i]<<" ";cout<<endl;
for(int i=0;i<q;i++){
int f;cin>>f;
cout<<maximum_minimum[f]<<endl;
}
return(0);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |