Submission #82403

# Submission time Handle Problem Language Result Execution time Memory
82403 2018-10-30T12:38:41 Z farukkastamonuda Sightseeing (NOI14_sightseeing) C++14
25 / 25
3341 ms 99588 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
#define pi pair<int, pair<int,int> >
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,greater<pi>());
	//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:30: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:33: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:50: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 13 ms 12152 KB Output is correct
2 Correct 12 ms 12276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 12276 KB Output is correct
2 Correct 13 ms 12276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 14456 KB Output is correct
2 Correct 43 ms 14456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2167 ms 65308 KB Output is correct
2 Correct 3341 ms 99588 KB Output is correct