# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
82401 | 2018-10-30T12:35:04 Z | farukkastamonuda | Sightseeing (NOI14_sightseeing) | C++14 | 3500 ms | 199116 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*10]; vector< pair<int,int> > v[li]; void dfs(int node,int ata,int val){ d[node]=val; for(int i=0;i<(int)v[node].size();i++){ int go=v[node][i].fi; int knr=v[node][i].se; if(go==ata) continue; dfs(go,node,min(val,knr)); } } int dsu(int x){ if(fa[x]==x) return x; return fa[x]=dsu(fa[x]); } int main(){ scanf("%d %d %d",&n,&m,&q); for(int i=1;i<=n;i++) fa[i]=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++){ int w=p[i].fi; int xx=p[i].se.fi; int yy=p[i].se.se; if(dsu(xx)!=dsu(yy)){ fa[dsu(xx)]=dsu(yy); v[xx].pb(mp(yy,w)); v[yy].pb(mp(xx,w)); } } dfs(1,-1,(1<<30)); 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 | 13 ms | 12152 KB | Output is correct |
2 | Correct | 13 ms | 12152 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 12192 KB | Output is correct |
2 | Correct | 14 ms | 12252 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 63 ms | 14428 KB | Output is correct |
2 | Correct | 49 ms | 14428 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2413 ms | 67064 KB | Output is correct |
2 | Execution timed out | 3541 ms | 199116 KB | Time limit exceeded |