답안 #492634

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
492634 2021-12-08T08:26:37 Z Biaz 관광 (NOI14_sightseeing) C++17
25 / 25
1954 ms 196864 KB
#include <bits/stdc++.h>
//#define int long long
//#define double long double
#define Nanase_Kurumi_aka_menhera_chan_is_mine ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pi pair<int, int>
#define ALL(i) i.begin(),i.end()
#define gcd(i,j) __gcd(i,j)
#define fi first
#define se second
#define eps 0.00000001
#define ist insert
#define DNE nullptr
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC optimize("O2")
int max(int x,int y){return x>=y?x:y;}
int min(int x,int y){return x>=y?y:x;}
using namespace std;
typedef int ll;
const int N=500005;
const int M=5000005;
const int MOD=1000000007;//998244353;
const int INF=2147483647;//1000000000000000000;

int n,m,Q;
struct I{
    int a,b,c;
    bool operator<(I const& rh)const{
        return c>rh.c;
    }
}e[M];
int p[N];
int res[N];
vector<pi> adj[N];
int boss(int a){return a==p[a]?a:p[a]=boss(p[a]);}
inline void merge(int a,int b){
    if (a<b) swap(a,b);
    p[a]=b;
}
void dfs(int v,int pre,int c){
    res[v]=c;
    for (auto &i:adj[v])
        if (i.fi!=pre)
            dfs(i.fi,v,min(c,i.se));
}
inline void sol(){
    cin >>n>>m>>Q;
    for (int i=0;i<m;i++)
        cin >>e[i].a>>e[i].b>>e[i].c;
    sort(e,e+m);
    for (int i=1;i<=n;i++) p[i]=i;
    for (int i=0;i<m;i++){
        int x=boss(e[i].a),y=boss(e[i].b);
        if (x==y) continue;
        merge(x,y);
        adj[e[i].a].pb({e[i].b,e[i].c});
        adj[e[i].b].pb({e[i].a,e[i].c});
    }
    dfs(1,1,INF);
    for (int i=0,t;i<Q;i++){
        cin >>t;
        cout <<res[t]<<'\n';
    }
}
signed main(){
    Nanase_Kurumi_aka_menhera_chan_is_mine
    int _=1;
    //cin >>_;
    while (_--) sol();
    return 0;
}
/*
4 4 2
1 2 10
1 3 30
2 4 20
3 4 5
3
4*/
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11980 KB Output is correct
2 Correct 6 ms 11980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12060 KB Output is correct
2 Correct 6 ms 12084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 14208 KB Output is correct
2 Correct 26 ms 14028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1337 ms 66476 KB Output is correct
2 Correct 1954 ms 196864 KB Output is correct