답안 #108259

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
108259 2019-04-28T11:25:12 Z SecretAgent007 악어의 지하 도시 (IOI11_crocodile) C++17
0 / 100
2 ms 384 KB
#include <bits/stdc++.h>
using namespace std;

//#define int long long 

const long long INF = 1e18;

int travel_plan(int n, int m, int r[][2], int l[], int k, int p[]){
	
	set< int > exit;
	
	for(int i = 0; i < k; i++){
		exit.insert(p[i]);
	}
	
	vector< vector< pair<long long, long long> > > Graph(n);
	
	for(int i = 0; i < m; i++){
		Graph[r[i][0]].push_back(make_pair(l[i], r[i][1]));
		Graph[r[i][1]].push_back(make_pair(l[i], r[i][0]));
	}
	
	for(int i = 0; i < n; i++){
		sort(Graph[i].begin(), Graph[i].end());
	}
	
	priority_queue< pair<long long, long long>, vector< pair<long long, long long> >, greater< pair<long long, long long> > > pq;
	
	vector< long long > dist(n, INF);
	
	dist[0] = 0;
	pq.push(make_pair(0,0));
	
	long long ans = INF;
	
	while(!pq.empty()){
		
		pair<int, int> pa = pq.top();
		pq.pop();
		
		if(dist[pa.second] != pa.first) continue;
		
		bool verif = false;
		
		for(auto a : Graph[pa.second]){
			
			if(!verif && exit.count(a.second)){
				verif = true;
				continue;
			}
			
			if(dist[a.second] > a.first+pa.first){
				dist[a.second] = a.first+pa.first;
				pq.push(make_pair(dist[a.second],a.second));
			}
			
			if(exit.count(a.second)){
				ans = min(ans, (long long)a.first+pa.first);
			}
			
		}
		
	}
	
	return ans;
} 
/*
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, m, k;
	cin >> n >> m >> k;
	
	int r[m][2];
	int l[m];
	int p[k];
	
	for(int i = 0; i < m; i++){
		cin >> r[i][0] >> r[i][1];
	}
	for(int i = 0; i < m; i++){
		cin >> l[i];
	}
	for(int i = 0; i < k; i++){
		cin >> p[i];
	}
	
	cout << travel_plan(n,m,r,l,k,p) << endl;
}
*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -