답안 #82391

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
82391 2018-10-30T12:00:02 Z farukkastamonuda 관광 (NOI14_sightseeing) C++14
15 / 25
3500 ms 131180 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];
bool vis[li];
vector< pair<int,int> > v[li];
void bfs(){
	priority_queue< pair<int,int> > q;
	q.push(mp(inf,1));
	while(!q.empty()){
		pair<int,int> temp=q.top();
		q.pop();
		int seh=temp.se;
		int cst=temp.fi;
		if(vis[seh]) continue;
		vis[seh]=true;
		d[seh]=cst;
		for(int i=0;i<(int)v[seh].size();i++){
			int go=v[seh][i].fi;
			int knr=v[seh][i].se;
			int nw=min(knr,cst);
			if(vis[go]==false)
				q.push(mp(nw,go));
		}
	}
}
int main(){
	scanf("%d %d %d",&n,&m,&q);
	for(int i=1;i<=m;i++){
		scanf("%d %d %d",&x,&y,&z);
		v[x].pb(mp(y,z));
		v[y].pb(mp(x,z));
	}
	bfs();
	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:36: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:38: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:44:8: 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 12 ms 12276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 12360 KB Output is correct
2 Correct 13 ms 12360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 14448 KB Output is correct
2 Correct 50 ms 14448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3538 ms 131180 KB Time limit exceeded
2 Halted 0 ms 0 KB -