Submission #82400

# Submission time Handle Problem Language Result Execution time Memory
82400 2018-10-30T12:34:24 Z farukkastamonuda Sightseeing (NOI14_sightseeing) C++14
15 / 25
730 ms 263168 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< 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

sightseeing.cpp: In function 'int main()':
sightseeing.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d",&n,&m,&q);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
sightseeing.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d",&x,&y,&z);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
sightseeing.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&x);
   ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 12152 KB Output is correct
2 Correct 12 ms 12156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 12216 KB Output is correct
2 Correct 12 ms 12232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 14536 KB Output is correct
2 Correct 43 ms 14536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 730 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -