Submission #299813

# Submission time Handle Problem Language Result Execution time Memory
299813 2020-09-15T18:02:29 Z jacobtpl Swapping Cities (APIO20_swap) C++14
37 / 100
2000 ms 12140 KB
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define INF 1100000000
#define sz(x) (int)(x).size()
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define ii pair<int,int>

int n,m;
vector<pair<int,ii> > edges;
int p[100005];
int deg[100005];
int maxdeg[100005],deg1[100005];

void init_uf() {
	for (int i=0;i<n;i++) {
		p[i]=i;
		deg[i]=maxdeg[i]=deg1[i]=0;
	}
}
int find(int x) {
	return (p[x]==x)?x:(p[x]=find(p[x]));
}
void join(int x,int y) {
	int a=find(x),b=find(y);
	if (a!=b) {
		maxdeg[b]=max(maxdeg[b],maxdeg[a]);
		deg1[b]+=deg1[a];
		p[a]=b;
	}
}
bool same(int x,int y) {
	return (find(x)==find(y));
}

void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
	n=N;
	m=M;
	for (int i=0;i<m;i++) {
		edges.pb(mp(W[i],mp(U[i],V[i])));
	}
	sort(all(edges));
}

int getMinimumFuelCapacity(int x, int y) {
	init_uf();
	for (auto e:edges) {
		int w=e.first;
		int a=e.second.first;
		int b=e.second.second;

		if (deg[a]==0) deg1[find(a)]++;
		if (deg[a]==1) deg1[find(a)]--;
		deg[a]++;
		maxdeg[find(a)]=max(maxdeg[find(a)],deg[a]);

		if (deg[b]==0) deg1[find(b)]++;
		if (deg[b]==1) deg1[find(b)]--;
		deg[b]++;
		maxdeg[find(b)]=max(maxdeg[find(b)],deg[b]);

		if (!same(a,b)) join(a,b);

		if (same(x,y)) {
			int v=find(x);
			if (maxdeg[v]>2) return w;
			if (maxdeg[v]==2 && deg1[v]==0) return w;
		}
	}
	return -1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 55 ms 4208 KB Output is correct
10 Correct 81 ms 4720 KB Output is correct
11 Correct 87 ms 4592 KB Output is correct
12 Correct 91 ms 4848 KB Output is correct
13 Correct 84 ms 5076 KB Output is correct
14 Execution timed out 2040 ms 4500 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Execution timed out 2070 ms 6672 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 2 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 55 ms 4208 KB Output is correct
11 Correct 81 ms 4720 KB Output is correct
12 Correct 87 ms 4592 KB Output is correct
13 Correct 91 ms 4848 KB Output is correct
14 Correct 84 ms 5076 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 9 ms 1312 KB Output is correct
25 Correct 88 ms 6228 KB Output is correct
26 Correct 87 ms 6356 KB Output is correct
27 Correct 87 ms 6228 KB Output is correct
28 Correct 86 ms 6128 KB Output is correct
29 Correct 86 ms 6252 KB Output is correct
30 Correct 81 ms 5748 KB Output is correct
31 Correct 93 ms 6588 KB Output is correct
32 Correct 92 ms 6228 KB Output is correct
33 Correct 71 ms 6228 KB Output is correct
34 Correct 97 ms 6640 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 2 ms 512 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 2 ms 512 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 2 ms 512 KB Output is correct
45 Correct 116 ms 10092 KB Output is correct
46 Correct 90 ms 6228 KB Output is correct
47 Correct 89 ms 6360 KB Output is correct
48 Correct 93 ms 6640 KB Output is correct
49 Correct 86 ms 9964 KB Output is correct
50 Correct 68 ms 7152 KB Output is correct
51 Correct 96 ms 7664 KB Output is correct
52 Correct 128 ms 10732 KB Output is correct
53 Correct 134 ms 11500 KB Output is correct
54 Correct 149 ms 12140 KB Output is correct
55 Correct 76 ms 6228 KB Output is correct
56 Correct 152 ms 11244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 55 ms 4208 KB Output is correct
10 Correct 81 ms 4720 KB Output is correct
11 Correct 87 ms 4592 KB Output is correct
12 Correct 91 ms 4848 KB Output is correct
13 Correct 84 ms 5076 KB Output is correct
14 Execution timed out 2040 ms 4500 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 55 ms 4208 KB Output is correct
11 Correct 81 ms 4720 KB Output is correct
12 Correct 87 ms 4592 KB Output is correct
13 Correct 91 ms 4848 KB Output is correct
14 Correct 84 ms 5076 KB Output is correct
15 Execution timed out 2040 ms 4500 KB Time limit exceeded
16 Halted 0 ms 0 KB -