# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
82397 | 2018-10-30T12:19:55 Z | farukkastamonuda | Sightseeing (NOI14_sightseeing) | C++14 | 452 ms | 34700 KB |
#include <bits/stdc++.h> #define fi first #define se second #define lo long long #define inf 1000000009 #define md 1000000007 #define li 500005 #define mp make_pair #define pb push_back #define mid (start+end)/2 using namespace std; int n,m,q,x,y,z,d[li],fa[li]; pair<int, pair<int,int> > p[li]; vector<int> par[li]; void unite(int val,int a,int b){ a=fa[a],b=fa[b]; if(a==b) return ; if(fa[1]==a){ for(int i=0;i<(int)par[b].size();i++) d[par[b][i]]=val; } else if(fa[1]==b){ for(int i=0;i<(int)par[a].size();i++) d[par[a][i]]=val; } if((int)par[a].size()<(int)par[b].size()) swap(a,b); for(int i=0;i<(int)par[b].size();i++){ int go=par[b][i]; fa[go]=a; par[a].pb(go); } par[b].clear(); } int main(){ scanf("%d %d %d",&n,&m,&q); for(int i=1;i<=n;i++){ fa[i]=i; par[i].pb(i); } for(int i=1;i<=m;i++){ scanf("%d %d %d",&x,&y,&z); p[i]=mp(z,mp(x,y)); } sort(p+1,p+m+1); reverse(p+1,p+m+1); for(int i=1;i<=m;i++){ unite(p[i].fi,p[i].se.fi,p[i].se.se); } for(int i=1;i<=q;i++){ scanf("%d",&x); printf("%d\n",d[x]); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 12152 KB | Output is correct |
2 | Correct | 12 ms | 12284 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 12284 KB | Output is correct |
2 | Correct | 13 ms | 12284 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 70 ms | 14724 KB | Output is correct |
2 | Correct | 42 ms | 14724 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 452 ms | 34700 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |