Submission #405933

# Submission time Handle Problem Language Result Execution time Memory
405933 2021-05-17T05:15:47 Z amunduzbaev Swapping Cities (APIO20_swap) C++14
0 / 100
2 ms 2636 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

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;

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]});
		mx = max(mx, (int)c[i]);
	}
	
	if(n == m) res = mx;
	else if(n - 1 == n){
		res = -1;
		ok = 1;
		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});
			mm.resize(3);
		}
	} sort(mm.begin(), mm.end());
}

/*

5 5
1 0 1
2 1 2
3 2 3
4 3 4
4 0 5
5
0 1
1 2
2 3
3 4
4 0

*/

int32_t getMinimumFuelCapacity(int32_t x, int32_t y) {
	if(!ok) return res;
	if(x > y) swap(x, y);
	if(n == 2) return -1;
	if(x == 0){
		if(y == mm[0].ss || y == mm[1].ss || y == mm[2].ss) return max({mm[0].ff, mm[1].ff, mm[2].ff});
		else return max({d[y], mm[0].ff, mm[1].ff});
	} else {
		if(n == 3) return -1;
		if((mm[0].ss == y || mm[1].ss == y) && (mm[0].ss == x || mm[1].ss == x)) return max({d[x], d[y], mm[2].ff});
		else if(x == mm[0].ss || y == mm[0].ss) return max({d[x], d[y], mm[1].ff});
		else return max({d[x], d[y], mm[0].ff});
	} 
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2636 KB Output isn't correct
2 Halted 0 ms 0 KB -