답안 #78667

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
78667 2018-10-07T01:26:50 Z thebes 관광 (NOI14_sightseeing) C++14
25 / 25
3084 ms 257620 KB
#include <bits/stdc++.h>
using namespace std;

const int MN = 5e5+5;
int N, M, Q, i, x, y, ds[MN], ans[MN];
struct ed{int x, y, w;}e[10*MN];
int fnd(int x){return ds[x]=ds[x]==x?x:fnd(ds[x]);}
vector<pair<int,int>> adj[MN];
void dfs(int n,int p,int w){
    ans[n] = w;
    for(auto v : adj[n])
        if(v.first!=p) dfs(v.first,n,min(w,v.second));
}
int main(){
    for(scanf("%d%d%d",&N,&M,&Q),i=1;i<=M;i++)
        scanf("%d%d%d",&e[i].x,&e[i].y,&e[i].w);
    sort(e+1,e+M+1,[](ed i,ed j){return i.w>j.w;});
    for(i=1;i<=N;i++) ds[i]=i;
    for(i=1;i<=M;i++){
        x=e[i].x, y=e[i].y;
        if(fnd(x)!=fnd(y)){
            ds[fnd(x)]=fnd(y);
            adj[x].push_back({y,e[i].w});
            adj[y].push_back({x,e[i].w});
        }
    }
    dfs(1, 0, 1<<30);
    for(;Q;Q--){
        scanf("%d",&x);
        printf("%d\n",ans[x]);
    }
    return 0;
}

Compilation message

sightseeing.cpp: In function 'int main()':
sightseeing.cpp:15:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(scanf("%d%d%d",&N,&M,&Q),i=1;i<=M;i++)
         ~~~~~~~~~~~~~~~~~~~~~~~~^~~~
sightseeing.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d",&e[i].x,&e[i].y,&e[i].w);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sightseeing.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&x);
         ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12152 KB Output is correct
2 Correct 11 ms 12288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 12396 KB Output is correct
2 Correct 13 ms 12396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 15464 KB Output is correct
2 Correct 43 ms 16156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2036 ms 125620 KB Output is correct
2 Correct 3084 ms 257620 KB Output is correct