Submission #117592

# Submission time Handle Problem Language Result Execution time Memory
117592 2019-06-16T18:00:25 Z KieranHorgan Crocodile's Underground City (IOI11_crocodile) C++17
89 / 100
1008 ms 98336 KB
#include "crocodile.h"
#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define int long long
#define ll long long
#define ld double
#define pii pair<int,int>
#define rand() abs((rand()<<15)|rand())
#define randll() abs(((long long)rand()<<30)|rand())

vector<pair<int,int>> AdjList[1000005];
int dist1[100005];
int dist2[100005];

// signed main() {
// 	ios_base::sync_with_stdio(false);
// 	cin.tie(NULL);
// 	long long seed;
// 	asm("rdtsc" : "=A"(seed));
// 	srand(seed);

signed travel_plan(signed N, signed M, signed R[][2], signed L[], signed K, signed P[]) {
	for(int i = 0; i < M; i++) {
		AdjList[R[i][0]].push_back({L[i], R[i][1]});
		AdjList[R[i][1]].push_back({L[i], R[i][0]});
	}

	// int n, m, k;
	// cin >> n >> m >> k;
	// for(int i = 0; i < m; i++) {
		// int u, v, w;
		// cin >> u >> v >> w;
		// AdjList[u].push_back({w,v});
		// AdjList[v].push_back({w,u});
	// }
	// vector<int> destination(k);
	// for(auto &x: destination)
		// cin >> x;
	int n=N;
	int m=M;
	int k=K;
	vector<int> destination;
	for(int i = 0; i < k; i++)
		destination.push_back(P[i]);

	memset(dist1, 63, sizeof(dist1));
	memset(dist2, 63, sizeof(dist2));
	priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;
	for(auto x: destination) {
		pq.push({0,x});
		dist1[x]=0;
		dist2[x]=0;
	}
	while(!pq.empty()) {
		int u = pq.top().second;
		int w = pq.top().first; pq.pop();
		if(w > dist2[u]) continue;
		// cerr << u << ": " << dist2[u] << endl;
		for(auto v: AdjList[u])
			if(dist2[u]+v.first < dist1[v.second]) {
				// cerr << " " << u << "->" << v.second << endl;
				dist2[v.second] = dist1[v.second];
				dist1[v.second] = dist2[u] + v.first;
				if(dist2[v.second])
					pq.push({dist2[v.second], v.second});
			} else if(dist2[u]+v.first < dist2[v.second]) {
				// cerr << "  " << u << "->" << v.second << endl;
				dist2[v.second] = dist2[u] + v.first;
				pq.push({dist2[v.second], v.second});
			}
	}

	// cout << dist2[0] << endl;
	return dist2[0];
}

Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:41:6: warning: unused variable 'n' [-Wunused-variable]
  int n=N;
      ^
crocodile.cpp:42:6: warning: unused variable 'm' [-Wunused-variable]
  int m=M;
      ^
# Verdict Execution time Memory Grader output
1 Correct 23 ms 25472 KB Output is correct
2 Correct 23 ms 25336 KB Output is correct
3 Correct 23 ms 25472 KB Output is correct
4 Correct 24 ms 25472 KB Output is correct
5 Correct 24 ms 25472 KB Output is correct
6 Correct 23 ms 25428 KB Output is correct
7 Correct 24 ms 25464 KB Output is correct
8 Correct 24 ms 25472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 25472 KB Output is correct
2 Correct 23 ms 25336 KB Output is correct
3 Correct 23 ms 25472 KB Output is correct
4 Correct 24 ms 25472 KB Output is correct
5 Correct 24 ms 25472 KB Output is correct
6 Correct 23 ms 25428 KB Output is correct
7 Correct 24 ms 25464 KB Output is correct
8 Correct 24 ms 25472 KB Output is correct
9 Correct 38 ms 25840 KB Output is correct
10 Correct 23 ms 25472 KB Output is correct
11 Correct 24 ms 25528 KB Output is correct
12 Correct 26 ms 26104 KB Output is correct
13 Correct 25 ms 26232 KB Output is correct
14 Correct 23 ms 25472 KB Output is correct
15 Correct 23 ms 25592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 25472 KB Output is correct
2 Correct 23 ms 25336 KB Output is correct
3 Correct 23 ms 25472 KB Output is correct
4 Correct 24 ms 25472 KB Output is correct
5 Correct 24 ms 25472 KB Output is correct
6 Correct 23 ms 25428 KB Output is correct
7 Correct 24 ms 25464 KB Output is correct
8 Correct 24 ms 25472 KB Output is correct
9 Correct 38 ms 25840 KB Output is correct
10 Correct 23 ms 25472 KB Output is correct
11 Correct 24 ms 25528 KB Output is correct
12 Correct 26 ms 26104 KB Output is correct
13 Correct 25 ms 26232 KB Output is correct
14 Correct 23 ms 25472 KB Output is correct
15 Correct 23 ms 25592 KB Output is correct
16 Correct 643 ms 90808 KB Output is correct
17 Correct 124 ms 37868 KB Output is correct
18 Correct 166 ms 40176 KB Output is correct
19 Correct 1008 ms 98336 KB Output is correct
20 Correct 360 ms 77384 KB Output is correct
21 Correct 79 ms 31352 KB Output is correct
22 Incorrect 369 ms 72948 KB Output isn't correct