Submission #406083

# Submission time Handle Problem Language Result Execution time Memory
406083 2021-05-17T08:18:26 Z amunduzbaev Swapping Cities (APIO20_swap) C++14
Compilation error
0 ms 0 KB
#include "swap.h"
#include "bits/stdc++.h"
#include "grader.cpp"
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);
}

Compilation message

/usr/bin/ld: /tmp/ccP9dOrB.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccW15mYB.o:swap.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status