답안 #82390

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
82390 2018-10-30T11:57:52 Z farukkastamonuda 관광 (NOI14_sightseeing) C++14
15 / 25
3500 ms 222580 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);
			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:35: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:37: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:43: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 12 ms 12124 KB Output is correct
2 Correct 12 ms 12280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 12496 KB Output is correct
2 Correct 14 ms 12496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 15608 KB Output is correct
2 Correct 57 ms 15888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3521 ms 222580 KB Time limit exceeded
2 Halted 0 ms 0 KB -