답안 #40970

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
40970 2018-02-10T15:11:06 Z Kerim 관광 (NOI14_sightseeing) C++14
25 / 25
3169 ms 98640 KB
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx") 
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include "bits/stdc++.h"
#define MAXN 500009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N=1e5+7;
int ata[MAXN],ans[MAXN],sz[MAXN];
pair<int,PII> arr[MAXN*10];
vector<PII>adj[MAXN];
int tap(int x){
	if(ata[x]==x)
		return x;
	return ata[x]=tap(ata[x]);		
}
bool merge(int x,int y,int val){
	if((x=tap(x))==(y=tap(y)))
		return 0;
	if(sz[x]<sz[y])
		swap(x,y);
	sz[x]+=sz[y];	
	ata[y]=x;return 1;
}
void dfs(int nd,int pr,int mn){
	ans[nd]=mn;
	tr(it,adj[nd])
		if(it->ff!=pr)
			dfs(it->ff,nd,min(mn,it->ss));
}
int main(){
    //~ freopen("file.in", "r", stdin);
    int n,m,q;
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<=n;i++)	
		ata[i]=i,sz[i]=1;
	for(int i=1;i<=m;i++){
		int u,v,w;
		scanf("%d%d%d",&u,&v,&w);
		arr[i]=mp(w,mp(u,v));
	}
	sort(arr+1,arr+m+1);
	for(int i=m;i>=1;i--){
		int w=arr[i].ff;
		int u=arr[i].ss.ff;
		int v=arr[i].ss.ss;
		if(merge(u,v,w)){
			adj[u].pb(mp(v,w));
			adj[v].pb(mp(u,w));
		}
	}
	dfs(1,-1,INF);
	while(q--){
		int x;
		scanf("%d",&x);
		printf("%d\n",ans[x]);
	}
	return 0;
}

Compilation message

sightseeing.cpp: In function 'int main()':
sightseeing.cpp:52:29: 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:57:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d",&u,&v,&w);
                           ^
sightseeing.cpp:73:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&x);
                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 12024 KB Output is correct
2 Correct 11 ms 12128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 12168 KB Output is correct
2 Correct 12 ms 12236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 14684 KB Output is correct
2 Correct 42 ms 14684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2110 ms 66992 KB Output is correct
2 Correct 3169 ms 98640 KB Output is correct