답안 #223749

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
223749 2020-04-16T09:45:24 Z staniewzki 낙하산 고리들 (IOI12_rings) C++17
100 / 100
861 ms 48336 KB
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for(int i = 0; i < n; i++)
 
template<class T> int size(T && a) { return (int) a.size(); }
 
struct Graph {
	vector<int> rep, deg;
	int excluded = -1;
 
	int find(int x) {
		return rep[x] < 0 ? x : rep[x] = find(rep[x]);
	}
 
	int bicomp = -1;
	int get_cycle() {
		return -rep[find(bicomp)];
	}
 
	void join(int x, int y) {
		x = find(x), y = find(y);
		if(x == y) {
			if(bicomp == -1) bicomp = x;
			else bicomp = -2;
			return;
		}
		if(rep[x] > rep[y]) swap(x, y);
		rep[x] += rep[y];
		rep[y] = x;
	}
 
	int max_deg = 0;
	void add_edge(int a, int b) {
		if(a == excluded || b == excluded)
			return;
		max_deg = max(max_deg, ++deg[a]);
		max_deg = max(max_deg, ++deg[b]);
		join(a, b);
	}
 
	Graph(int n = 0, int e = -1) : rep(n, -1), deg(n), excluded(e) {}
};
 
int n;
vector<pair<int, int>> edges;
Graph graph;
vector<Graph> without;
 
void Init(int N) {
	n = N;
	graph = Graph(n);
}
 
void Link(int A, int B) {
	edges.emplace_back(A, B);
	if(graph.max_deg < 3) {
		graph.add_edge(A, B);
		if(graph.max_deg == 3) {
			if(graph.deg[A] != 3)
				swap(A, B);
 
			vector<int> crit = {A};
			for(auto &[u, v] : edges) {
				if(u == A) crit.emplace_back(v);
				if(v == A) crit.emplace_back(u);
			}
 
			for(int x : crit) {
				without.emplace_back(n, x);
				for(auto &[u, v] : edges)
					without.back().add_edge(v, u);		
			}
		}
	}
	else {
		for(auto &g : without)
			g.add_edge(A, B);
	}
}
 
int CountCritical() {
	if(graph.max_deg < 3) {
		if(graph.bicomp == -1) return n;
		if(graph.bicomp == -2) return 0;
		return graph.get_cycle();
	}
	else {
		int ret = 0;
		for(auto &g : without) {
			if(g.bicomp == -1 && g.max_deg < 3)
				ret++;
		}
		return ret;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 6 ms 640 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 6 ms 512 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 6 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 209 ms 8684 KB Output is correct
2 Correct 686 ms 40100 KB Output is correct
3 Correct 861 ms 47880 KB Output is correct
4 Correct 496 ms 16612 KB Output is correct
5 Correct 471 ms 16616 KB Output is correct
6 Correct 471 ms 16484 KB Output is correct
7 Correct 809 ms 48144 KB Output is correct
8 Correct 753 ms 44376 KB Output is correct
9 Correct 794 ms 47448 KB Output is correct
10 Correct 420 ms 16612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 6 ms 640 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 6 ms 512 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 6 ms 640 KB Output is correct
11 Correct 6 ms 640 KB Output is correct
12 Correct 9 ms 896 KB Output is correct
13 Correct 9 ms 1024 KB Output is correct
14 Correct 7 ms 896 KB Output is correct
15 Correct 7 ms 1280 KB Output is correct
16 Correct 8 ms 640 KB Output is correct
17 Correct 8 ms 1024 KB Output is correct
18 Correct 9 ms 1408 KB Output is correct
19 Correct 8 ms 640 KB Output is correct
20 Correct 9 ms 896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 6 ms 640 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 6 ms 512 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 6 ms 640 KB Output is correct
11 Correct 6 ms 640 KB Output is correct
12 Correct 9 ms 896 KB Output is correct
13 Correct 9 ms 1024 KB Output is correct
14 Correct 7 ms 896 KB Output is correct
15 Correct 7 ms 1280 KB Output is correct
16 Correct 8 ms 640 KB Output is correct
17 Correct 8 ms 1024 KB Output is correct
18 Correct 9 ms 1408 KB Output is correct
19 Correct 8 ms 640 KB Output is correct
20 Correct 9 ms 896 KB Output is correct
21 Correct 19 ms 1280 KB Output is correct
22 Correct 28 ms 1920 KB Output is correct
23 Correct 35 ms 2172 KB Output is correct
24 Correct 53 ms 4736 KB Output is correct
25 Correct 21 ms 4480 KB Output is correct
26 Correct 43 ms 4852 KB Output is correct
27 Correct 38 ms 2292 KB Output is correct
28 Correct 44 ms 4980 KB Output is correct
29 Correct 34 ms 4864 KB Output is correct
30 Correct 42 ms 2300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 6 ms 640 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 6 ms 512 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 6 ms 640 KB Output is correct
11 Correct 209 ms 8684 KB Output is correct
12 Correct 686 ms 40100 KB Output is correct
13 Correct 861 ms 47880 KB Output is correct
14 Correct 496 ms 16612 KB Output is correct
15 Correct 471 ms 16616 KB Output is correct
16 Correct 471 ms 16484 KB Output is correct
17 Correct 809 ms 48144 KB Output is correct
18 Correct 753 ms 44376 KB Output is correct
19 Correct 794 ms 47448 KB Output is correct
20 Correct 420 ms 16612 KB Output is correct
21 Correct 6 ms 640 KB Output is correct
22 Correct 9 ms 896 KB Output is correct
23 Correct 9 ms 1024 KB Output is correct
24 Correct 7 ms 896 KB Output is correct
25 Correct 7 ms 1280 KB Output is correct
26 Correct 8 ms 640 KB Output is correct
27 Correct 8 ms 1024 KB Output is correct
28 Correct 9 ms 1408 KB Output is correct
29 Correct 8 ms 640 KB Output is correct
30 Correct 9 ms 896 KB Output is correct
31 Correct 19 ms 1280 KB Output is correct
32 Correct 28 ms 1920 KB Output is correct
33 Correct 35 ms 2172 KB Output is correct
34 Correct 53 ms 4736 KB Output is correct
35 Correct 21 ms 4480 KB Output is correct
36 Correct 43 ms 4852 KB Output is correct
37 Correct 38 ms 2292 KB Output is correct
38 Correct 44 ms 4980 KB Output is correct
39 Correct 34 ms 4864 KB Output is correct
40 Correct 42 ms 2300 KB Output is correct
41 Correct 155 ms 8148 KB Output is correct
42 Correct 401 ms 39008 KB Output is correct
43 Correct 255 ms 39028 KB Output is correct
44 Correct 545 ms 45028 KB Output is correct
45 Correct 584 ms 48336 KB Output is correct
46 Correct 386 ms 15972 KB Output is correct
47 Correct 419 ms 15972 KB Output is correct
48 Correct 400 ms 45036 KB Output is correct
49 Correct 397 ms 18404 KB Output is correct
50 Correct 406 ms 18016 KB Output is correct
51 Correct 275 ms 33772 KB Output is correct
52 Correct 497 ms 38188 KB Output is correct
53 Correct 375 ms 44524 KB Output is correct
54 Correct 699 ms 40932 KB Output is correct
55 Correct 797 ms 43364 KB Output is correct