Submission #99540

# Submission time Handle Problem Language Result Execution time Memory
99540 2019-03-04T20:16:56 Z jhnah917 Crocodile's Underground City (IOI11_crocodile) C++14
100 / 100
816 ms 45292 KB
#include "crocodile.h"
#include <vector>
#include <queue>
#include <utility>
using namespace std;

typedef pair<int, int> p;
vector<p> g[101010];
priority_queue<p> pq;
int dist1[101010], dist2[101010];
int visit[101010];

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
	for(int i=0; i<=N; i++) dist1[i] = dist2[i] = 1e9+7;
	for(int i=0; i<M; i++){
		int s = R[i][0], e = R[i][1], w = L[i];
		g[s].push_back({e, w});
		g[e].push_back({s, w});
	}
	for(int i=0; i<K; i++){
		dist1[P[i]] = dist2[P[i]] = 0;
		pq.push({0, P[i]});
	}
	
	while(!pq.empty()){
		int now = pq.top().second, cost = -pq.top().first;
		pq.pop();
		if(visit[now]) continue;
		visit[now] = 1;
		
		for(auto i : g[now]){
			int nxt = i.first, nxtCost = i.second;
			if(visit[nxt]) continue;
			//first
			if(dist1[nxt] > dist2[now] + nxtCost){
				dist2[nxt] = dist1[nxt];
				dist1[nxt] = dist2[now] + nxtCost;
				if(dist2[nxt] < 1e9+7) pq.push({-dist2[nxt], nxt});
			}
			//second
			else if(dist2[nxt] > dist2[now] + nxtCost){
				dist2[nxt] = dist2[now] + nxtCost;
				pq.push({-dist2[nxt], nxt});
			}
		}
	}
	
	return dist2[0];
}

Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:26:30: warning: unused variable 'cost' [-Wunused-variable]
   int now = pq.top().second, cost = -pq.top().first;
                              ^~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
3 Correct 4 ms 2816 KB Output is correct
4 Correct 5 ms 2816 KB Output is correct
5 Correct 5 ms 2816 KB Output is correct
6 Correct 4 ms 2688 KB Output is correct
7 Correct 6 ms 2816 KB Output is correct
8 Correct 4 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
3 Correct 4 ms 2816 KB Output is correct
4 Correct 5 ms 2816 KB Output is correct
5 Correct 5 ms 2816 KB Output is correct
6 Correct 4 ms 2688 KB Output is correct
7 Correct 6 ms 2816 KB Output is correct
8 Correct 4 ms 2816 KB Output is correct
9 Correct 7 ms 2944 KB Output is correct
10 Correct 4 ms 2688 KB Output is correct
11 Correct 6 ms 2816 KB Output is correct
12 Correct 8 ms 3072 KB Output is correct
13 Correct 9 ms 3200 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Correct 5 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
3 Correct 4 ms 2816 KB Output is correct
4 Correct 5 ms 2816 KB Output is correct
5 Correct 5 ms 2816 KB Output is correct
6 Correct 4 ms 2688 KB Output is correct
7 Correct 6 ms 2816 KB Output is correct
8 Correct 4 ms 2816 KB Output is correct
9 Correct 7 ms 2944 KB Output is correct
10 Correct 4 ms 2688 KB Output is correct
11 Correct 6 ms 2816 KB Output is correct
12 Correct 8 ms 3072 KB Output is correct
13 Correct 9 ms 3200 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Correct 5 ms 2816 KB Output is correct
16 Correct 656 ms 41260 KB Output is correct
17 Correct 88 ms 10872 KB Output is correct
18 Correct 108 ms 12240 KB Output is correct
19 Correct 816 ms 45292 KB Output is correct
20 Correct 347 ms 36700 KB Output is correct
21 Correct 44 ms 6392 KB Output is correct
22 Correct 377 ms 31992 KB Output is correct