Submission #406084

# Submission time Handle Problem Language Result Execution time Memory
406084 2021-05-17T08:18:43 Z amunduzbaev Swapping Cities (APIO20_swap) C++14
17 / 100
2000 ms 23428 KB
#include "swap.h"
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define int long long
template<class T> bool umin(T& a, const T b) { if(a > b) { a = b; return 1; } return 0; }
template<class T> bool umax(T& a, const T b) { if(a < b) { a = b; return 1; } return 0; }

const int NN = 1e5+5;
int mx = 0, ok, res, d[NN], n, m;
vector<pair<int, int>> edges[NN];
vector<pair<int, int>> mm;
vector<int> tte[NN];

void init(int32_t N, int32_t M,
	vector<int32_t> a, vector<int32_t> b, vector<int32_t> c) {
	n = N, m = M;
	for(int i=0;i<m;i++){
		edges[a[i]].pb({b[i], c[i]});
		edges[b[i]].pb({a[i], c[i]});
		tte[a[i]].pb(c[i]);
		tte[b[i]].pb(c[i]);
		mx = max(mx, (int)c[i]);
	}
	
	for(int i=0;i<n;i++) sort(tte[i].begin(), tte[i].end());
	for(int i=0;i<m;i++) ok &= (min(a[i], b[i]) == 0);
	if(ok){
		for(int i=0;i<m;i++) d[max(a[i], b[i])] = c[i];
		for(int i=1;i<n;i++) mm.pb({d[i], i});
		sort(mm.begin(), mm.end());
		mm.resize(3);
	} else ok = -1;
}

/*

5 6
0 1 4
0 2 4
1 2 1
1 3 2
2 3 3
1 4 10
3
1 2
2 4
0 1

*/

const int mod = 1e9+7;
int mn[NN], par[NN], bad[NN];
int mn2[NN];

int32_t getMinimumFuelCapacity(int32_t x, int32_t y) {
	priority_queue<pair<int, int>> qq;
	qq.push({0, x});
	memset(mn, 127, sizeof mn);
	memset(mn2, 127, sizeof mn2);
	memset(bad, 0, sizeof bad);
	memset(par, 0, sizeof par);
	par[x] = -1;
	mn[x] = 0;
	while(!qq.empty()){
		auto u = qq.top(); qq.pop();
		if(mn[u.ss] < -u.ff) continue;
		for(auto x : edges[u.ss]) if(umin(mn[x.ff], max(mn[u.ss], x.ss))) par[x.ff] = u.ss, qq.push({-mn[x.ff], x.ff});
	}
	for(int i=0;i<n;i++) if(sz(tte[i]) >= 3) mn2[i] = tte[i][2], qq.push({-tte[i][2], i});
	while(!qq.empty()){
		auto u = qq.top(); qq.pop();
		if(mn2[u.ss] < -u.ff) continue;
		for(auto x : edges[u.ss]) if(umin(mn2[x.ff], max(mn2[u.ss], x.ss))) qq.push({-mn2[x.ff], x.ff});
	} int trr = mn[y], tt = y;
	vector<int> bads;
	while(~tt){
		bads.pb(tt);
		bad[tt] = 1;
		tt = par[tt];
	} int rr = mod;
	
	//for(int i=0;i<n;i++) cout<<mn2[i]<<" ";
	//cout<<"\n";
	//for(int i=0;i<n;i++) cout<<mn[i]<<" ";
	//cout<<"\n";
	
	for(int i=0;i<n;i++){
		if(bad[i]){
			if(i == y || i == x) umin(rr, mn2[i]);
			else {
				int mn = mod;
				for(auto x : edges[i]){
					if(bad[x.ff]) continue;
					umin(mn, x.ss);
				} umin(rr, mn);
			}
		}
	} for(int i=0;i<sz(bads)-1;i++){
		int a = bads[i], b = bads[i+1];
		qq.push({0, x});
		for(int i=0;i<n;i++) mn[i] = mod;
		mn[x] = 0;
		while(!qq.empty()){
			auto u = qq.top(); qq.pop();
			if(mn[u.ss] < -u.ff) continue;
			for(auto x : edges[u.ss]){
				if((x.ff == a && u.ss == b) || (x.ff == b && u.ss == a)) continue;
				if(umin(mn[x.ff], max(mn[u.ss], x.ss))) qq.push({-mn[x.ff], x.ff});
			}
		} umin(rr, mn[y]);
	}
	
	if(rr == mod) return -1;
	return max(rr, trr);
}

# Verdict Execution time Memory Grader output
1 Correct 6 ms 8012 KB Output is correct
2 Correct 5 ms 8012 KB Output is correct
3 Correct 6 ms 8012 KB Output is correct
4 Correct 12 ms 8140 KB Output is correct
5 Correct 20 ms 8140 KB Output is correct
6 Correct 29 ms 8140 KB Output is correct
7 Correct 43 ms 8228 KB Output is correct
8 Correct 51 ms 8140 KB Output is correct
9 Execution timed out 2070 ms 16480 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8012 KB Output is correct
2 Correct 5 ms 8012 KB Output is correct
3 Execution timed out 2077 ms 23428 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8012 KB Output is correct
2 Correct 5 ms 8012 KB Output is correct
3 Correct 6 ms 8012 KB Output is correct
4 Correct 12 ms 8140 KB Output is correct
5 Correct 20 ms 8140 KB Output is correct
6 Correct 29 ms 8140 KB Output is correct
7 Correct 43 ms 8228 KB Output is correct
8 Correct 51 ms 8140 KB Output is correct
9 Correct 6 ms 8012 KB Output is correct
10 Correct 12 ms 8140 KB Output is correct
11 Correct 33 ms 8140 KB Output is correct
12 Correct 34 ms 8216 KB Output is correct
13 Correct 17 ms 8224 KB Output is correct
14 Correct 19 ms 8140 KB Output is correct
15 Correct 19 ms 8140 KB Output is correct
16 Correct 37 ms 8140 KB Output is correct
17 Correct 45 ms 8236 KB Output is correct
18 Correct 16 ms 8240 KB Output is correct
19 Correct 16 ms 8252 KB Output is correct
20 Correct 50 ms 8140 KB Output is correct
21 Correct 25 ms 8140 KB Output is correct
22 Correct 14 ms 8316 KB Output is correct
23 Correct 22 ms 8228 KB Output is correct
24 Correct 85 ms 8332 KB Output is correct
25 Correct 30 ms 8268 KB Output is correct
26 Correct 195 ms 8344 KB Output is correct
27 Correct 34 ms 8236 KB Output is correct
28 Correct 43 ms 8268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8012 KB Output is correct
2 Correct 6 ms 8012 KB Output is correct
3 Correct 5 ms 8012 KB Output is correct
4 Correct 6 ms 8012 KB Output is correct
5 Correct 12 ms 8140 KB Output is correct
6 Correct 20 ms 8140 KB Output is correct
7 Correct 29 ms 8140 KB Output is correct
8 Correct 43 ms 8228 KB Output is correct
9 Correct 51 ms 8140 KB Output is correct
10 Execution timed out 2070 ms 16480 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8012 KB Output is correct
2 Correct 5 ms 8012 KB Output is correct
3 Correct 6 ms 8012 KB Output is correct
4 Correct 12 ms 8140 KB Output is correct
5 Correct 20 ms 8140 KB Output is correct
6 Correct 29 ms 8140 KB Output is correct
7 Correct 43 ms 8228 KB Output is correct
8 Correct 51 ms 8140 KB Output is correct
9 Execution timed out 2070 ms 16480 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8012 KB Output is correct
2 Correct 6 ms 8012 KB Output is correct
3 Correct 5 ms 8012 KB Output is correct
4 Correct 6 ms 8012 KB Output is correct
5 Correct 12 ms 8140 KB Output is correct
6 Correct 20 ms 8140 KB Output is correct
7 Correct 29 ms 8140 KB Output is correct
8 Correct 43 ms 8228 KB Output is correct
9 Correct 51 ms 8140 KB Output is correct
10 Execution timed out 2070 ms 16480 KB Time limit exceeded
11 Halted 0 ms 0 KB -