답안 #594946

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
594946 2022-07-13T07:35:33 Z 8e7 낙하산 고리들 (IOI12_rings) C++17
100 / 100
1544 ms 125096 KB
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r){
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 1000005
#define pii pair<int, int>
#define ff first
#define ss second

struct DSU{
	int par[maxn], siz[maxn];
	void init(int n){
		for (int i = 0;i < n;i++) par[i] = i, siz[i] = 1;
	}
	int find(int a){
		return a == par[a] ? a : (par[a] = find(par[a]));
	}
	bool Union(int a, int b){
		a = find(a), b = find(b);
		if (a == b) return 0;
		if (siz[a] < siz[b]) swap(a, b);
		par[b] = a;
		siz[a] += siz[b];
		return 1;
	}
};
struct graph{ //maintaining a graph of nodes with deg <= 2
	DSU d;
	int deg[maxn];
	int cycle = 0, ignore = -1, count = 0;
	bool good = 1;
	int maxdeg = 0;
	void addedge(int u, int v){
		if (u == ignore || v == ignore) return;
		deg[u]++, deg[v]++;
		maxdeg = max(maxdeg, max(deg[u], deg[v]));
		if (maxdeg > 2) {
			good = 0;
			return;
		}
		if (!d.Union(u, v)) {
			cycle++;	
			if (cycle > 1) good = 0;
			else count = d.siz[d.find(u)];
		}	
	}	
} g;
vector<int> adj[maxn];
vector<pii> ed;
int N;
void Init(int N_) {
	N = N_;
	g.d.init(N);
}
graph cand[4];
int idx = 0;
void Link(int A, int B) {
	adj[A].push_back(B);
	adj[B].push_back(A);
	ed.push_back({A, B});
	if (g.maxdeg < 3) {
		g.addedge(A, B);
		if (g.maxdeg >= 3) {
			if (g.deg[B] >= 3) swap(A, B);
			adj[A].push_back(A);
			for (int i:adj[A]) {
				graph &tmp = cand[idx++];
				tmp.d.init(N);
				tmp.ignore = i;
				for (auto p:ed) tmp.addedge(p.ff, p.ss);
			}
			adj[A].pop_back();
		}
	} else {
		for (auto &t:cand){
			t.addedge(A, B);	
		}
	}
}

int CountCritical() {
	if (g.good) {
		if (g.cycle == 1) return g.count;
		else return N;
	} else {
		int ret = 0;
		for (int t = 0;t < idx;t++) {
			if (cand[t].good && cand[t].cycle == 0) ret++;
		}
		return ret;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23804 KB Output is correct
2 Correct 14 ms 24276 KB Output is correct
3 Correct 14 ms 24404 KB Output is correct
4 Correct 12 ms 23892 KB Output is correct
5 Correct 17 ms 23988 KB Output is correct
6 Correct 15 ms 24176 KB Output is correct
7 Correct 13 ms 24240 KB Output is correct
8 Correct 17 ms 24020 KB Output is correct
9 Correct 16 ms 24464 KB Output is correct
10 Correct 14 ms 24404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 359 ms 50344 KB Output is correct
2 Correct 962 ms 102060 KB Output is correct
3 Correct 872 ms 117024 KB Output is correct
4 Correct 995 ms 74596 KB Output is correct
5 Correct 1006 ms 74624 KB Output is correct
6 Correct 1014 ms 73324 KB Output is correct
7 Correct 861 ms 116244 KB Output is correct
8 Correct 1439 ms 115320 KB Output is correct
9 Correct 1544 ms 121512 KB Output is correct
10 Correct 672 ms 72380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23804 KB Output is correct
2 Correct 14 ms 24276 KB Output is correct
3 Correct 14 ms 24404 KB Output is correct
4 Correct 12 ms 23892 KB Output is correct
5 Correct 17 ms 23988 KB Output is correct
6 Correct 15 ms 24176 KB Output is correct
7 Correct 13 ms 24240 KB Output is correct
8 Correct 17 ms 24020 KB Output is correct
9 Correct 16 ms 24464 KB Output is correct
10 Correct 14 ms 24404 KB Output is correct
11 Correct 18 ms 24404 KB Output is correct
12 Correct 19 ms 25044 KB Output is correct
13 Correct 22 ms 24944 KB Output is correct
14 Correct 16 ms 24788 KB Output is correct
15 Correct 17 ms 25264 KB Output is correct
16 Correct 16 ms 24404 KB Output is correct
17 Correct 17 ms 25044 KB Output is correct
18 Correct 18 ms 25684 KB Output is correct
19 Correct 16 ms 24476 KB Output is correct
20 Correct 17 ms 25072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23804 KB Output is correct
2 Correct 14 ms 24276 KB Output is correct
3 Correct 14 ms 24404 KB Output is correct
4 Correct 12 ms 23892 KB Output is correct
5 Correct 17 ms 23988 KB Output is correct
6 Correct 15 ms 24176 KB Output is correct
7 Correct 13 ms 24240 KB Output is correct
8 Correct 17 ms 24020 KB Output is correct
9 Correct 16 ms 24464 KB Output is correct
10 Correct 14 ms 24404 KB Output is correct
11 Correct 18 ms 24404 KB Output is correct
12 Correct 19 ms 25044 KB Output is correct
13 Correct 22 ms 24944 KB Output is correct
14 Correct 16 ms 24788 KB Output is correct
15 Correct 17 ms 25264 KB Output is correct
16 Correct 16 ms 24404 KB Output is correct
17 Correct 17 ms 25044 KB Output is correct
18 Correct 18 ms 25684 KB Output is correct
19 Correct 16 ms 24476 KB Output is correct
20 Correct 17 ms 25072 KB Output is correct
21 Correct 29 ms 26016 KB Output is correct
22 Correct 42 ms 27264 KB Output is correct
23 Correct 47 ms 28228 KB Output is correct
24 Correct 54 ms 31648 KB Output is correct
25 Correct 25 ms 30036 KB Output is correct
26 Correct 52 ms 32896 KB Output is correct
27 Correct 48 ms 29180 KB Output is correct
28 Correct 75 ms 33556 KB Output is correct
29 Correct 58 ms 32136 KB Output is correct
30 Correct 71 ms 29936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23804 KB Output is correct
2 Correct 14 ms 24276 KB Output is correct
3 Correct 14 ms 24404 KB Output is correct
4 Correct 12 ms 23892 KB Output is correct
5 Correct 17 ms 23988 KB Output is correct
6 Correct 15 ms 24176 KB Output is correct
7 Correct 13 ms 24240 KB Output is correct
8 Correct 17 ms 24020 KB Output is correct
9 Correct 16 ms 24464 KB Output is correct
10 Correct 14 ms 24404 KB Output is correct
11 Correct 359 ms 50344 KB Output is correct
12 Correct 962 ms 102060 KB Output is correct
13 Correct 872 ms 117024 KB Output is correct
14 Correct 995 ms 74596 KB Output is correct
15 Correct 1006 ms 74624 KB Output is correct
16 Correct 1014 ms 73324 KB Output is correct
17 Correct 861 ms 116244 KB Output is correct
18 Correct 1439 ms 115320 KB Output is correct
19 Correct 1544 ms 121512 KB Output is correct
20 Correct 672 ms 72380 KB Output is correct
21 Correct 18 ms 24404 KB Output is correct
22 Correct 19 ms 25044 KB Output is correct
23 Correct 22 ms 24944 KB Output is correct
24 Correct 16 ms 24788 KB Output is correct
25 Correct 17 ms 25264 KB Output is correct
26 Correct 16 ms 24404 KB Output is correct
27 Correct 17 ms 25044 KB Output is correct
28 Correct 18 ms 25684 KB Output is correct
29 Correct 16 ms 24476 KB Output is correct
30 Correct 17 ms 25072 KB Output is correct
31 Correct 29 ms 26016 KB Output is correct
32 Correct 42 ms 27264 KB Output is correct
33 Correct 47 ms 28228 KB Output is correct
34 Correct 54 ms 31648 KB Output is correct
35 Correct 25 ms 30036 KB Output is correct
36 Correct 52 ms 32896 KB Output is correct
37 Correct 48 ms 29180 KB Output is correct
38 Correct 75 ms 33556 KB Output is correct
39 Correct 58 ms 32136 KB Output is correct
40 Correct 71 ms 29936 KB Output is correct
41 Correct 201 ms 43296 KB Output is correct
42 Correct 608 ms 99316 KB Output is correct
43 Correct 285 ms 82348 KB Output is correct
44 Correct 631 ms 125096 KB Output is correct
45 Correct 743 ms 117680 KB Output is correct
46 Correct 650 ms 77956 KB Output is correct
47 Correct 848 ms 78864 KB Output is correct
48 Correct 486 ms 107900 KB Output is correct
49 Correct 653 ms 77068 KB Output is correct
50 Correct 679 ms 76436 KB Output is correct
51 Correct 306 ms 79684 KB Output is correct
52 Correct 571 ms 105760 KB Output is correct
53 Correct 456 ms 108572 KB Output is correct
54 Correct 1132 ms 114256 KB Output is correct
55 Correct 1039 ms 122124 KB Output is correct