답안 #15785

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
15785 2015-07-26T11:10:50 Z myungwoo 낙하산 고리들 (IOI12_rings) C++14
100 / 100
2403 ms 52392 KB
#include <vector>
using namespace std;

#define MAXN 1000006
#define mp make_pair
#define pb push_back
#define sz(v) ((int)(v).size())
typedef pair<int,int> pii;

static int N,deg[MAXN],par[MAXN],size[MAXN];
static int _par[4][MAXN],_deg[4][MAXN],_target[4];
static int cycle_cnt,cycle_size;
static bool sw,_valid[4];
static vector<pii> edges;

int find(int n,int p[MAXN]=par){ return p[n]==n?n:(p[n]=find(p[n],p)); }

void Init(int n)
{
	int i;
	N = n;
	for (i=1;i<=N;i++) par[i] = i, size[i] = 1;
}

void addEdge(int a,int b)
{
	int i;
	for (i=0;i<4;i++){
		if (_target[i] == a || _target[i] == b) continue;
		if (++_deg[i][a] == 3) _valid[i] = 0;
		if (++_deg[i][b] == 3) _valid[i] = 0;
		int p = find(a,_par[i]), q = find(b,_par[i]);
		if (p == q) _valid[i] = 0;
		_par[i][q] = p;
	}
}

void reg(int n)
{
	int i,j,k=0;
	_target[k++] = n;
	for (i=0;i<sz(edges);i++){
		if (edges[i].first == n) _target[k++] = edges[i].second;
		if (edges[i].second == n) _target[k++] = edges[i].first;
	}
	for (i=0;i<4;i++){
		_valid[i] = 1;
		for (j=1;j<=N;j++) _par[i][j] = j;
	}
	for (i=0;i<sz(edges);i++) addEdge(edges[i].first,edges[i].second);
}

void Link(int a,int b)
{
	a++; b++;
	deg[a]++; deg[b]++;
	edges.pb(mp(a,b));
	if (!sw && deg[a] == 3) sw = 1, reg(a);
	else if (!sw && deg[b] == 3) sw = 1, reg(b);
	else if (!sw){
		a = find(a); b = find(b);
		if (a == b){
			cycle_cnt++;
			cycle_size = size[a];
		}else{
			par[b] = a;
			size[a] += size[b];
		}
	}else{
		addEdge(a,b);
	}
}

int CountCritical()
{
	if (cycle_cnt > 1) return 0;
	if (!sw){
		if (cycle_cnt) return cycle_size;
		return N;
	}
	int ret = 0,i;
	for (i=0;i<4;i++) ret += _valid[i];
	return ret;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 5 ms 916 KB Output is correct
4 Correct 2 ms 916 KB Output is correct
5 Correct 3 ms 916 KB Output is correct
6 Correct 3 ms 916 KB Output is correct
7 Correct 2 ms 916 KB Output is correct
8 Correct 3 ms 916 KB Output is correct
9 Correct 5 ms 964 KB Output is correct
10 Correct 4 ms 976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 243 ms 10948 KB Output is correct
2 Correct 1606 ms 43448 KB Output is correct
3 Correct 2403 ms 52068 KB Output is correct
4 Correct 577 ms 52068 KB Output is correct
5 Correct 565 ms 52068 KB Output is correct
6 Correct 559 ms 52068 KB Output is correct
7 Correct 1946 ms 52392 KB Output is correct
8 Correct 1806 ms 52392 KB Output is correct
9 Correct 2048 ms 52392 KB Output is correct
10 Correct 513 ms 52392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 5 ms 916 KB Output is correct
4 Correct 2 ms 916 KB Output is correct
5 Correct 3 ms 916 KB Output is correct
6 Correct 3 ms 916 KB Output is correct
7 Correct 2 ms 916 KB Output is correct
8 Correct 3 ms 916 KB Output is correct
9 Correct 5 ms 964 KB Output is correct
10 Correct 4 ms 976 KB Output is correct
11 Correct 4 ms 52392 KB Output is correct
12 Correct 6 ms 52392 KB Output is correct
13 Correct 6 ms 52392 KB Output is correct
14 Correct 6 ms 52392 KB Output is correct
15 Correct 6 ms 52392 KB Output is correct
16 Correct 5 ms 52392 KB Output is correct
17 Correct 9 ms 52392 KB Output is correct
18 Correct 6 ms 52392 KB Output is correct
19 Correct 5 ms 52392 KB Output is correct
20 Correct 6 ms 52392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 5 ms 916 KB Output is correct
4 Correct 2 ms 916 KB Output is correct
5 Correct 3 ms 916 KB Output is correct
6 Correct 3 ms 916 KB Output is correct
7 Correct 2 ms 916 KB Output is correct
8 Correct 3 ms 916 KB Output is correct
9 Correct 5 ms 964 KB Output is correct
10 Correct 4 ms 976 KB Output is correct
11 Correct 4 ms 52392 KB Output is correct
12 Correct 6 ms 52392 KB Output is correct
13 Correct 6 ms 52392 KB Output is correct
14 Correct 6 ms 52392 KB Output is correct
15 Correct 6 ms 52392 KB Output is correct
16 Correct 5 ms 52392 KB Output is correct
17 Correct 9 ms 52392 KB Output is correct
18 Correct 6 ms 52392 KB Output is correct
19 Correct 5 ms 52392 KB Output is correct
20 Correct 6 ms 52392 KB Output is correct
21 Correct 17 ms 52392 KB Output is correct
22 Correct 25 ms 52392 KB Output is correct
23 Correct 36 ms 52392 KB Output is correct
24 Correct 46 ms 52392 KB Output is correct
25 Correct 32 ms 52392 KB Output is correct
26 Correct 40 ms 52392 KB Output is correct
27 Correct 38 ms 52392 KB Output is correct
28 Correct 51 ms 52392 KB Output is correct
29 Correct 36 ms 52392 KB Output is correct
30 Correct 43 ms 52392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 5 ms 916 KB Output is correct
4 Correct 2 ms 916 KB Output is correct
5 Correct 3 ms 916 KB Output is correct
6 Correct 3 ms 916 KB Output is correct
7 Correct 2 ms 916 KB Output is correct
8 Correct 3 ms 916 KB Output is correct
9 Correct 5 ms 964 KB Output is correct
10 Correct 4 ms 976 KB Output is correct
11 Correct 243 ms 10948 KB Output is correct
12 Correct 1606 ms 43448 KB Output is correct
13 Correct 2403 ms 52068 KB Output is correct
14 Correct 577 ms 52068 KB Output is correct
15 Correct 565 ms 52068 KB Output is correct
16 Correct 559 ms 52068 KB Output is correct
17 Correct 1946 ms 52392 KB Output is correct
18 Correct 1806 ms 52392 KB Output is correct
19 Correct 2048 ms 52392 KB Output is correct
20 Correct 513 ms 52392 KB Output is correct
21 Correct 4 ms 52392 KB Output is correct
22 Correct 6 ms 52392 KB Output is correct
23 Correct 6 ms 52392 KB Output is correct
24 Correct 6 ms 52392 KB Output is correct
25 Correct 6 ms 52392 KB Output is correct
26 Correct 5 ms 52392 KB Output is correct
27 Correct 9 ms 52392 KB Output is correct
28 Correct 6 ms 52392 KB Output is correct
29 Correct 5 ms 52392 KB Output is correct
30 Correct 6 ms 52392 KB Output is correct
31 Correct 17 ms 52392 KB Output is correct
32 Correct 25 ms 52392 KB Output is correct
33 Correct 36 ms 52392 KB Output is correct
34 Correct 46 ms 52392 KB Output is correct
35 Correct 32 ms 52392 KB Output is correct
36 Correct 40 ms 52392 KB Output is correct
37 Correct 38 ms 52392 KB Output is correct
38 Correct 51 ms 52392 KB Output is correct
39 Correct 36 ms 52392 KB Output is correct
40 Correct 43 ms 52392 KB Output is correct
41 Correct 176 ms 52392 KB Output is correct
42 Correct 805 ms 52392 KB Output is correct
43 Correct 333 ms 52392 KB Output is correct
44 Correct 894 ms 52392 KB Output is correct
45 Correct 1303 ms 52392 KB Output is correct
46 Correct 542 ms 52392 KB Output is correct
47 Correct 536 ms 52392 KB Output is correct
48 Correct 772 ms 52392 KB Output is correct
49 Correct 469 ms 52392 KB Output is correct
50 Correct 503 ms 52392 KB Output is correct
51 Correct 411 ms 52392 KB Output is correct
52 Correct 785 ms 52392 KB Output is correct
53 Correct 761 ms 52392 KB Output is correct
54 Correct 1537 ms 52392 KB Output is correct
55 Correct 1577 ms 52392 KB Output is correct