Submission #347355

# Submission time Handle Problem Language Result Execution time Memory
347355 2021-01-12T15:53:16 Z Mefarnis Crocodile's Underground City (IOI11_crocodile) C++14
100 / 100
574 ms 64100 KB
#include <bits/stdc++.h>
#include "crocodile.h"
#define fi first
#define se second
#define maxn 100000
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> pi;

struct datum {
	int u;
	LL dist;
	datum(int _u , LL _dist) {
		u = _u;
		dist = _dist;
	}
};

bool operator<(const datum& a , const datum& b) {
	return a.dist > b.dist;
}

bool mark[maxn];
LL dist[maxn][2];
vector<pi> adj[maxn];
priority_queue<datum> heap;

int travel_plan(int n, int m, int e[][2], int c[], int k, int p[]) {
	for( int i = 0 ; i < m ; i++ ) {
		int u = e[i][0];
		int v = e[i][1];
		int d = c[i];
		adj[u].pb(pi(v,d));
		adj[v].pb(pi(u,d));
	}
	for( int i = 0 ; i < n ; i++ ) {
		mark[i] = false;
		dist[i][0] = dist[i][1] = (1LL<<60);
	}
	for( int i = 0 ; i < k ; i++ ) {
		dist[p[i]][0] = 0;
		dist[p[i]][1] = 0;
		heap.push(datum(p[i],0));
	}
	while(!heap.empty()) {
		datum dt = heap.top();
		heap.pop();
		int u = dt.u;
		LL du = dt.dist;
		if(u == 0)
			break;
		if(mark[u])
			continue;
		mark[u] = true;
		int deg = adj[u].size();
		for( int i = 0 ; i < deg ; i++ ) {
			int v = adj[u][i].fi;
			LL dv = du + adj[u][i].se;
			if(!mark[v]) {
				LL bef = dist[v][1];
				if(dv <= dist[v][0]) {
					dist[v][1] = dist[v][0];
					dist[v][0] = dv;
				}
				else if(dv <= dist[v][1])
					dist[v][1] = dv;
				if(dist[v][1] < bef)
					heap.push(datum(v,dist[v][1]));
			}
		}
	}
	return dist[0][1];
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 3 ms 2796 KB Output is correct
5 Correct 3 ms 2796 KB Output is correct
6 Correct 3 ms 2796 KB Output is correct
7 Correct 3 ms 2796 KB Output is correct
8 Correct 3 ms 2796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 3 ms 2796 KB Output is correct
5 Correct 3 ms 2796 KB Output is correct
6 Correct 3 ms 2796 KB Output is correct
7 Correct 3 ms 2796 KB Output is correct
8 Correct 3 ms 2796 KB Output is correct
9 Correct 4 ms 3052 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 3 ms 2796 KB Output is correct
12 Correct 6 ms 3180 KB Output is correct
13 Correct 5 ms 3180 KB Output is correct
14 Correct 3 ms 2796 KB Output is correct
15 Correct 3 ms 2796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 3 ms 2796 KB Output is correct
5 Correct 3 ms 2796 KB Output is correct
6 Correct 3 ms 2796 KB Output is correct
7 Correct 3 ms 2796 KB Output is correct
8 Correct 3 ms 2796 KB Output is correct
9 Correct 4 ms 3052 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 3 ms 2796 KB Output is correct
12 Correct 6 ms 3180 KB Output is correct
13 Correct 5 ms 3180 KB Output is correct
14 Correct 3 ms 2796 KB Output is correct
15 Correct 3 ms 2796 KB Output is correct
16 Correct 496 ms 58980 KB Output is correct
17 Correct 78 ms 14700 KB Output is correct
18 Correct 92 ms 16108 KB Output is correct
19 Correct 574 ms 64100 KB Output is correct
20 Correct 316 ms 49516 KB Output is correct
21 Correct 39 ms 8044 KB Output is correct
22 Correct 335 ms 46600 KB Output is correct