Submission #347995

# Submission time Handle Problem Language Result Execution time Memory
347995 2021-01-14T02:47:09 Z arnold518 Swapping Cities (APIO20_swap) C++14
37 / 100
2000 ms 8448 KB
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;
const int MAXM = 2e5;

int N, M;

struct Edge
{
	int u, v, w;
};
Edge E[MAXM+10];

int deg[MAXN+10], val[MAXN+10], cnt[MAXN+10], sz[MAXN+10];

struct UF
{
	int par[MAXN+10];

	void init()
	{
		for(int i=1; i<=N; i++)
		{
			par[i]=i;
		}		
	}

	int Find(int x)
	{
		if(x==par[x]) return x;
		return par[x]=Find(par[x]);
	}
}uf;

void init(int _N, int _M, vector<int> _U, vector<int> _V, vector<int> _W)
{
	N=_N; M=_M;
	for(int i=1; i<=M; i++)
	{
		int u=_U[i-1]+1, v=_V[i-1]+1, w=_W[i-1];
		E[i]={u, v, w};
	}
	sort(E+1, E+M+1, [&](const Edge &p, const Edge &q)
	{
		return p.w<q.w;
	});

}
int getMinimumFuelCapacity(int X, int Y)
{
	X++; Y++;
	uf.init();
	for(int i=1; i<=N; i++)
	{
		deg[i]=0;
		val[i]=0;
		cnt[i]=0;
		sz[i]=1;
	}
	for(int i=1; i<=M; i++)
	{
		int u=E[i].u, v=E[i].v, w=E[i].w;
		deg[u]++; deg[v]++;

		int uu=uf.Find(u), vv=uf.Find(v);

		if(uu==vv)
		{
			val[uu]=max(val[uu], deg[u]);
			val[uu]=max(val[uu], deg[v]);
			cnt[uu]++;
		}
		else
		{
			uf.par[vv]=uu;
			val[uu]=max(val[uu], val[vv]);
			cnt[uu]+=cnt[vv];
			sz[uu]+=sz[vv];
			val[uu]=max(val[uu], deg[u]);
			val[uu]=max(val[uu], deg[v]);
			cnt[uu]++;
		}

		int XX=uf.Find(X), YY=uf.Find(Y);
		if(XX!=YY) continue;
		if(val[XX]>=3) return w;
		if(val[XX]==2 && cnt[XX]==sz[XX]) return w;
	}
	return -1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 41 ms 4560 KB Output is correct
10 Correct 62 ms 5380 KB Output is correct
11 Correct 62 ms 5264 KB Output is correct
12 Correct 66 ms 5588 KB Output is correct
13 Correct 64 ms 5972 KB Output is correct
14 Execution timed out 2096 ms 4816 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Execution timed out 2080 ms 6672 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 41 ms 4560 KB Output is correct
11 Correct 62 ms 5380 KB Output is correct
12 Correct 62 ms 5264 KB Output is correct
13 Correct 66 ms 5588 KB Output is correct
14 Correct 64 ms 5972 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 7 ms 1356 KB Output is correct
25 Correct 63 ms 5588 KB Output is correct
26 Correct 64 ms 5588 KB Output is correct
27 Correct 63 ms 5584 KB Output is correct
28 Correct 64 ms 5728 KB Output is correct
29 Correct 63 ms 5484 KB Output is correct
30 Correct 61 ms 5192 KB Output is correct
31 Correct 66 ms 5588 KB Output is correct
32 Correct 63 ms 5588 KB Output is correct
33 Correct 53 ms 5588 KB Output is correct
34 Correct 71 ms 5584 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 492 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 492 KB Output is correct
41 Correct 1 ms 492 KB Output is correct
42 Correct 1 ms 492 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 2 ms 492 KB Output is correct
45 Correct 88 ms 6528 KB Output is correct
46 Correct 63 ms 5716 KB Output is correct
47 Correct 66 ms 5716 KB Output is correct
48 Correct 72 ms 5852 KB Output is correct
49 Correct 65 ms 6892 KB Output is correct
50 Correct 52 ms 5612 KB Output is correct
51 Correct 73 ms 5868 KB Output is correct
52 Correct 98 ms 7044 KB Output is correct
53 Correct 96 ms 7660 KB Output is correct
54 Correct 111 ms 8448 KB Output is correct
55 Correct 55 ms 5716 KB Output is correct
56 Correct 111 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 41 ms 4560 KB Output is correct
10 Correct 62 ms 5380 KB Output is correct
11 Correct 62 ms 5264 KB Output is correct
12 Correct 66 ms 5588 KB Output is correct
13 Correct 64 ms 5972 KB Output is correct
14 Execution timed out 2096 ms 4816 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 41 ms 4560 KB Output is correct
11 Correct 62 ms 5380 KB Output is correct
12 Correct 62 ms 5264 KB Output is correct
13 Correct 66 ms 5588 KB Output is correct
14 Correct 64 ms 5972 KB Output is correct
15 Execution timed out 2096 ms 4816 KB Time limit exceeded
16 Halted 0 ms 0 KB -