Submission #390005

# Submission time Handle Problem Language Result Execution time Memory
390005 2021-04-15T04:49:32 Z strawberry2005 Sightseeing (NOI14_sightseeing) C++17
25 / 25
3324 ms 128732 KB
#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
1 Correct 7 ms 11980 KB Output is correct
2 Correct 7 ms 12080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12108 KB Output is correct
2 Correct 7 ms 12100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 15120 KB Output is correct
2 Correct 45 ms 14772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2202 ms 69620 KB Output is correct
2 Correct 3324 ms 128732 KB Output is correct