답안 #36806

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
36806 2017-12-14T19:18:17 Z mohammad_kilani 낙하산 고리들 (IOI12_rings) C++14
100 / 100
2319 ms 113072 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
int n , comp[N], mx , adj[N] , ans = 0 , cycles = 0 , vis[N] , vi = 0 , comp2[4][N] , con1[4][N] , con2[4][N];
vector< int > g[N];
vector< pair<int,bool> > v;
vector< pair<int,int> > v2;

int Find(int u){
	return (u == comp[u] ? u : comp[u] = Find(comp[u]));
}

int Find2(int u,int i){
	if(u == comp2[i][u]) 
		return u;
	return comp2[i][u] = Find2(comp2[i][u],i);
}

void Init(int N_) {
  n = N_;
  ans = n ;
  for(int i=0;i<n;i++) 
  	comp[i] = i;
  mx = 0 ;
  cycles = 0 ;
}


void DFS(int node,int prnt,int last){
	ans++;
	if(node == last) return;
	for(int i=0;i<(int)g[node].size();i++){
		if(g[node][i] != prnt) DFS(g[node][i],node,last);
	}
}

void DFS2(int node,int cant){
	vis[node] = vi;
	int num = 0 ;
	for(int i=0;i<(int)g[node].size();i++){
		int newnode = g[node][i];
		num += (newnode != cant);
		if(vis[newnode] == vi || newnode == cant) continue;
		DFS2(newnode,cant);
	}
	v2.push_back(make_pair(node,num));
}

void make(int u){
	v.push_back(make_pair(u,true));
	for(int i=0;i<(int)g[u].size();i++){
		v.push_back(make_pair(g[u][i],true));
	}
	ans = 0 ;
	for(int i=0;i<(int)v.size();i++){
		vi++;
		int cnt = 0 ;
		for(int j=0;j<n;j++){
			if(j == v[i].first || vis[j] == vi) continue;
			v2.clear();
			cnt = j;
			DFS2(j,v[i].first);
			if(v2.size() == 1){
				con1[i][cnt] = con2[i][cnt] = v2[0].first;
				comp2[i][v2[0].first] = cnt;
			}
			else if(v2.size() == 2){
				con1[i][cnt] = v2[0].first;
				con2[i][cnt] = v2[1].first;
				comp2[i][v2[0].first] = comp2[i][v2[1].first] = cnt;
			}
			else{
				con1[i][cnt] = con2[i][cnt] = -1;
				for(int k=0;k<(int)v2.size();k++){
					if(v2[k].second == 1) if(con1[i][cnt] == -1) con1[i][cnt] = v2[k].first; else con2[i][cnt] = v2[k].first;
					comp2[i][v2[k].first] = cnt;
				}
				if(con1[i][cnt] == -1){
					v[i].second = false;
					break;
				}
			}
		}
		ans += v[i].second;
	}
}

void Link(int a, int b) {
	if(ans == 0) return;
	if(mx < 3){
		int u = Find(a);
		int v = Find(b);
		adj[a]++;
		adj[b]++;
		g[a].push_back(b);
		g[b].push_back(a);
		if(adj[a] == 3){
			mx = 3;
			make(a);
			return ;
		}
		if(adj[b] == 3){
			mx = 3;
			make(b);
			return;
		}
		if(u == v){
			if(cycles > 0){
				ans = 0;
				return ;
			}
			cycles++;
			ans = 0 ;
			DFS(a,b,b);
		}
		else{
			comp[u] = v;
		}
		return ;
	}
	for(int i=0;i<(int)v.size();i++){
		if(v[i].second == false || v[i].first == a || v[i].first == b) continue;
		int u = Find2(comp2[i][a],i);
		int vv = Find2(comp2[i][b],i);
		if(u == vv){
			v[i].second = false;
			ans--;
			continue;
		}
		if(a != con1[i][u] && a != con2[i][u]){
			v[i].second = false;
			ans--;
			continue;
		}
		if(b != con1[i][vv] && b != con2[i][vv]){
			v[i].second = false;
			ans--;
			continue;
		}
		comp2[i][u] = vv;
		if(a == con1[i][u] && b == con1[i][vv]){
			con1[i][vv] = con2[i][u];
		}
		else if(a == con2[i][u] && b == con1[i][vv]){
			con1[i][vv] = con1[i][u];
		}
		else if(a == con1[i][u] && b == con2[i][vv]){
			con2[i][vv] = con2[i][u];
		}
		else if(a == con2[i][u] && b == con2[i][vv]){
			con2[i][vv] = con1[i][u];
		}
	}
}

int CountCritical() {
  return ans;
}

Compilation message

rings.cpp: In function 'void make(int)':
rings.cpp:75:8: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
      if(v2[k].second == 1) if(con1[i][cnt] == -1) con1[i][cnt] = v2[k].first; else con2[i][cnt] = v2[k].first;
        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 25 ms 24444 KB Output is correct
3 Correct 26 ms 24444 KB Output is correct
4 Correct 30 ms 24444 KB Output is correct
5 Correct 24 ms 24444 KB Output is correct
6 Correct 29 ms 24444 KB Output is correct
7 Correct 24 ms 24444 KB Output is correct
8 Correct 25 ms 24444 KB Output is correct
9 Correct 25 ms 24444 KB Output is correct
10 Correct 24 ms 24648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 495 ms 44488 KB Output is correct
2 Correct 1316 ms 85136 KB Output is correct
3 Correct 452 ms 85136 KB Output is correct
4 Correct 1343 ms 85136 KB Output is correct
5 Correct 1215 ms 85136 KB Output is correct
6 Correct 1312 ms 85244 KB Output is correct
7 Correct 451 ms 85244 KB Output is correct
8 Correct 2023 ms 105464 KB Output is correct
9 Correct 2319 ms 113072 KB Output is correct
10 Correct 810 ms 113072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 25 ms 24444 KB Output is correct
3 Correct 26 ms 24444 KB Output is correct
4 Correct 30 ms 24444 KB Output is correct
5 Correct 24 ms 24444 KB Output is correct
6 Correct 29 ms 24444 KB Output is correct
7 Correct 24 ms 24444 KB Output is correct
8 Correct 25 ms 24444 KB Output is correct
9 Correct 25 ms 24444 KB Output is correct
10 Correct 24 ms 24648 KB Output is correct
11 Correct 25 ms 113072 KB Output is correct
12 Correct 29 ms 113072 KB Output is correct
13 Correct 28 ms 113072 KB Output is correct
14 Correct 33 ms 113072 KB Output is correct
15 Correct 28 ms 113072 KB Output is correct
16 Correct 29 ms 113072 KB Output is correct
17 Correct 26 ms 113072 KB Output is correct
18 Correct 28 ms 113072 KB Output is correct
19 Correct 29 ms 113072 KB Output is correct
20 Correct 31 ms 113072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 25 ms 24444 KB Output is correct
3 Correct 26 ms 24444 KB Output is correct
4 Correct 30 ms 24444 KB Output is correct
5 Correct 24 ms 24444 KB Output is correct
6 Correct 29 ms 24444 KB Output is correct
7 Correct 24 ms 24444 KB Output is correct
8 Correct 25 ms 24444 KB Output is correct
9 Correct 25 ms 24444 KB Output is correct
10 Correct 24 ms 24648 KB Output is correct
11 Correct 25 ms 113072 KB Output is correct
12 Correct 29 ms 113072 KB Output is correct
13 Correct 28 ms 113072 KB Output is correct
14 Correct 33 ms 113072 KB Output is correct
15 Correct 28 ms 113072 KB Output is correct
16 Correct 29 ms 113072 KB Output is correct
17 Correct 26 ms 113072 KB Output is correct
18 Correct 28 ms 113072 KB Output is correct
19 Correct 29 ms 113072 KB Output is correct
20 Correct 31 ms 113072 KB Output is correct
21 Correct 63 ms 113072 KB Output is correct
22 Correct 56 ms 113072 KB Output is correct
23 Correct 68 ms 113072 KB Output is correct
24 Correct 68 ms 113072 KB Output is correct
25 Correct 47 ms 113072 KB Output is correct
26 Correct 64 ms 113072 KB Output is correct
27 Correct 80 ms 113072 KB Output is correct
28 Correct 58 ms 113072 KB Output is correct
29 Correct 59 ms 113072 KB Output is correct
30 Correct 90 ms 113072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 25 ms 24444 KB Output is correct
3 Correct 26 ms 24444 KB Output is correct
4 Correct 30 ms 24444 KB Output is correct
5 Correct 24 ms 24444 KB Output is correct
6 Correct 29 ms 24444 KB Output is correct
7 Correct 24 ms 24444 KB Output is correct
8 Correct 25 ms 24444 KB Output is correct
9 Correct 25 ms 24444 KB Output is correct
10 Correct 24 ms 24648 KB Output is correct
11 Correct 495 ms 44488 KB Output is correct
12 Correct 1316 ms 85136 KB Output is correct
13 Correct 452 ms 85136 KB Output is correct
14 Correct 1343 ms 85136 KB Output is correct
15 Correct 1215 ms 85136 KB Output is correct
16 Correct 1312 ms 85244 KB Output is correct
17 Correct 451 ms 85244 KB Output is correct
18 Correct 2023 ms 105464 KB Output is correct
19 Correct 2319 ms 113072 KB Output is correct
20 Correct 810 ms 113072 KB Output is correct
21 Correct 25 ms 113072 KB Output is correct
22 Correct 29 ms 113072 KB Output is correct
23 Correct 28 ms 113072 KB Output is correct
24 Correct 33 ms 113072 KB Output is correct
25 Correct 28 ms 113072 KB Output is correct
26 Correct 29 ms 113072 KB Output is correct
27 Correct 26 ms 113072 KB Output is correct
28 Correct 28 ms 113072 KB Output is correct
29 Correct 29 ms 113072 KB Output is correct
30 Correct 31 ms 113072 KB Output is correct
31 Correct 63 ms 113072 KB Output is correct
32 Correct 56 ms 113072 KB Output is correct
33 Correct 68 ms 113072 KB Output is correct
34 Correct 68 ms 113072 KB Output is correct
35 Correct 47 ms 113072 KB Output is correct
36 Correct 64 ms 113072 KB Output is correct
37 Correct 80 ms 113072 KB Output is correct
38 Correct 58 ms 113072 KB Output is correct
39 Correct 59 ms 113072 KB Output is correct
40 Correct 90 ms 113072 KB Output is correct
41 Correct 244 ms 113072 KB Output is correct
42 Correct 1076 ms 113072 KB Output is correct
43 Correct 410 ms 113072 KB Output is correct
44 Correct 442 ms 113072 KB Output is correct
45 Correct 686 ms 113072 KB Output is correct
46 Correct 844 ms 113072 KB Output is correct
47 Correct 1224 ms 113072 KB Output is correct
48 Correct 431 ms 113072 KB Output is correct
49 Correct 761 ms 113072 KB Output is correct
50 Correct 812 ms 113072 KB Output is correct
51 Correct 342 ms 113072 KB Output is correct
52 Correct 369 ms 113072 KB Output is correct
53 Correct 386 ms 113072 KB Output is correct
54 Correct 1532 ms 113072 KB Output is correct
55 Correct 648 ms 113072 KB Output is correct