Submission #484540

# Submission time Handle Problem Language Result Execution time Memory
484540 2021-11-04T10:09:49 Z BackNoob Crocodile's Underground City (IOI11_crocodile) C++14
100 / 100
435 ms 55520 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define endl '\n'
#define MASK(i) (1LL << (i))
#define ull unsigned long long
#define ld long double
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define BIT(x , i) ((x >> (i)) & 1) 
#define TASK "task"
#define sz(s) (int) (s).size()

using namespace std;
const int mxN = 3e5 + 227;
const int inf = 1e9 + 277;
const int mod = 1e9 + 7;
const ll infll = 1e18 + 7;
const int base = 307;
const int LOG = 20;
 
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
	if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
	if (a < b) {a = b; return true;} return false;
}

int n , m , k;
vector<pair<int , int>> adj[mxN];
bool exitnode[mxN];
ll dp1[mxN] , dp2[mxN];


ll travel_plan(int n , int m , int r[][2] , int l[] , int k , int p[])
{	

	for(int i = 0 ; i < m ; i++) {
		int u = r[i][0];
		int v = r[i][1];
		int c = l[i];
		++u; ++v;
		adj[u].pb({v , c});
		adj[v].pb({u , c});
	}


	memset(dp1, 0x3f , sizeof dp1);
	memset(dp2, 0x3f , sizeof dp2);
	priority_queue <pair<ll , int>, vector <pair<ll , int>> , greater<pair<ll , int>>> pq;
	for(int i = 0 ; i < k ; i++) {
		exitnode[p[i] + 1] = true;
 		pq.push({dp1[p[i] + 1] = dp2[p[i] + 1] = 0 , p[i] + 1});
	}
	while(!pq.empty()) {
		int u = pq.top().se;
		ll d = pq.top().fi;
		pq.pop();
		if(d > dp2[u]) continue;

		for(auto it : adj[u]) {
			int v = it.fi;
			int c = it.se;
			if(dp1[v] > d + c) {
				if(dp2[v] > dp1[v])  {
					dp2[v] = dp1[v];
					pq.push({dp2[v] , v});
				}
				dp1[v] = d + c;
			}
			else {
				if(dp2[v] > d + c) {
					dp2[v] = d + c;
					pq.push({d + c , v});
				}
			}
		}
	}
	return dp2[1];

}

 
# Verdict Execution time Memory Grader output
1 Correct 5 ms 11980 KB Output is correct
2 Correct 5 ms 11980 KB Output is correct
3 Correct 5 ms 11980 KB Output is correct
4 Correct 7 ms 12108 KB Output is correct
5 Correct 5 ms 12108 KB Output is correct
6 Correct 5 ms 12108 KB Output is correct
7 Correct 6 ms 12108 KB Output is correct
8 Correct 7 ms 12108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 11980 KB Output is correct
2 Correct 5 ms 11980 KB Output is correct
3 Correct 5 ms 11980 KB Output is correct
4 Correct 7 ms 12108 KB Output is correct
5 Correct 5 ms 12108 KB Output is correct
6 Correct 5 ms 12108 KB Output is correct
7 Correct 6 ms 12108 KB Output is correct
8 Correct 7 ms 12108 KB Output is correct
9 Correct 6 ms 12236 KB Output is correct
10 Correct 5 ms 11980 KB Output is correct
11 Correct 6 ms 12108 KB Output is correct
12 Correct 9 ms 12364 KB Output is correct
13 Correct 8 ms 12492 KB Output is correct
14 Correct 6 ms 11980 KB Output is correct
15 Correct 8 ms 12108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 11980 KB Output is correct
2 Correct 5 ms 11980 KB Output is correct
3 Correct 5 ms 11980 KB Output is correct
4 Correct 7 ms 12108 KB Output is correct
5 Correct 5 ms 12108 KB Output is correct
6 Correct 5 ms 12108 KB Output is correct
7 Correct 6 ms 12108 KB Output is correct
8 Correct 7 ms 12108 KB Output is correct
9 Correct 6 ms 12236 KB Output is correct
10 Correct 5 ms 11980 KB Output is correct
11 Correct 6 ms 12108 KB Output is correct
12 Correct 9 ms 12364 KB Output is correct
13 Correct 8 ms 12492 KB Output is correct
14 Correct 6 ms 11980 KB Output is correct
15 Correct 8 ms 12108 KB Output is correct
16 Correct 345 ms 51348 KB Output is correct
17 Correct 61 ms 19012 KB Output is correct
18 Correct 76 ms 20344 KB Output is correct
19 Correct 435 ms 55520 KB Output is correct
20 Correct 226 ms 46020 KB Output is correct
21 Correct 34 ms 15420 KB Output is correct
22 Correct 240 ms 41060 KB Output is correct