답안 #400863

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
400863 2021-05-08T18:41:48 Z Jasiekstrz 낙하산 고리들 (IOI12_rings) C++17
100 / 100
1553 ms 141124 KB
#include<bits/stdc++.h>
using namespace std;
const int N=1e6;
int n;
bool was_cycle;
set<int> ok;
vector<int> e[N+10];
int fau[N+10];
bool on_cycle[N+10];
bool vis[N+10];
bool vis2[N+10];
int pp[N+10];
int f(int x)
{
	if(fau[x]!=x)
		fau[x]=f(fau[x]);
	return fau[x];
}
void u(int x,int y)
{
	fau[f(y)]=f(x);
	return;
}
void set_all(bool c)
{
	ok.clear();
	if(c)
	{
		for(int i=0;i<n;i++)
			ok.insert(i);
	}
	return;
}
bool dfs(int x,int y)
{
	if(x==y)
	{
		on_cycle[x]=true;
		return true;
	}
	vis[x]=true;
	for(auto v:e[x])
	{
		if(!vis[v] && dfs(v,y))
		{
			on_cycle[x]=true;
			return true;
		}
	}
	return false;
}
void dfs2(int x,int id)
{
	vis2[x]=true;
	pp[x]=id;
	for(auto v:e[x])
	{
		if(vis2[v] || on_cycle[v])
			continue;
		dfs2(v,id);
	}
	return;
}
void check_deg(int x)
{
	if(ok.empty())
		return;
	if(e[x].size()>3)
	{
		if(ok.find(x)!=ok.end())
		{
			ok.clear();
			ok.insert(x);
		}
		else
			ok.clear();
	}
	else if(e[x].size()==3)
	{
		vector<int> trash;
		set<int> ee={x,e[x][0],e[x][1],e[x][2]};
		for(auto v:ok)
		{
			if(ee.find(v)==ee.end())
				trash.push_back(v);
		}
		for(auto v:trash)
			ok.erase(v);
	}
	return;
}
bool are_ngh(int x,int y)
{
	for(auto v:e[x])
	{
		if(v==y)
			return true;
	}
	return false;
}
void Init(int _N)
{
	n=_N;
	set_all(true);
	for(int i=0;i<n;i++)
		fau[i]=i;
	was_cycle=false;
	return;
}
void Link(int A,int B)
{
	if(ok.empty())
		return;
	if(f(A)==f(B))
	{
		if(was_cycle)
		{
			if(on_cycle[A] && on_cycle[B])
			{
				set<int> st;
				for(int v:{A,B})
				{
					if(ok.find(v)!=ok.end())
						st.insert(v);
				}
				ok=st;
			}
			else if(vis2[A] && vis2[B])
			{
				if(pp[A]==pp[B])
				{
					if(ok.find(pp[A])!=ok.end())
					{
						ok.clear();
						ok.insert(pp[A]);
					}
					else
						ok.clear();
				}
				else if(are_ngh(pp[A],pp[B]))
				{
					set<int> st;
					for(int v:{pp[A],pp[B]})
					{
						if(ok.find(v)!=ok.end())
							st.insert(v);
					}
					ok=st;
				}
				else
					ok.clear();
			}
			else
				ok.clear();
		}
		else
		{
			was_cycle=true;
			dfs(A,B);
			for(int i=0;i<n;i++)
			{
				if(ok.find(i)!=ok.end() && !on_cycle[i])
					ok.erase(i);
			}
			for(int i=0;i<n;i++)
			{
				if(on_cycle[i])
					dfs2(i,i);
			}
		}
	}
	u(A,B);
	e[A].push_back(B);
	e[B].push_back(A);
	if(vis2[A] && !vis2[B])
		dfs2(B,pp[A]);
	if(vis2[B] && !vis2[A])
		dfs2(A,pp[B]);
	check_deg(A);
	check_deg(B);
	return;
}
int CountCritical()
{
	return ok.size();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23756 KB Output is correct
2 Correct 19 ms 24196 KB Output is correct
3 Correct 18 ms 24152 KB Output is correct
4 Correct 14 ms 23888 KB Output is correct
5 Correct 16 ms 24140 KB Output is correct
6 Correct 17 ms 24396 KB Output is correct
7 Correct 15 ms 24068 KB Output is correct
8 Correct 15 ms 24236 KB Output is correct
9 Correct 16 ms 24212 KB Output is correct
10 Correct 16 ms 24268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 490 ms 73492 KB Output is correct
2 Correct 1058 ms 85860 KB Output is correct
3 Correct 626 ms 82136 KB Output is correct
4 Correct 1403 ms 117040 KB Output is correct
5 Correct 1407 ms 120836 KB Output is correct
6 Correct 1553 ms 141124 KB Output is correct
7 Correct 612 ms 82448 KB Output is correct
8 Correct 1267 ms 108804 KB Output is correct
9 Correct 1387 ms 116044 KB Output is correct
10 Correct 1069 ms 115912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23756 KB Output is correct
2 Correct 19 ms 24196 KB Output is correct
3 Correct 18 ms 24152 KB Output is correct
4 Correct 14 ms 23888 KB Output is correct
5 Correct 16 ms 24140 KB Output is correct
6 Correct 17 ms 24396 KB Output is correct
7 Correct 15 ms 24068 KB Output is correct
8 Correct 15 ms 24236 KB Output is correct
9 Correct 16 ms 24212 KB Output is correct
10 Correct 16 ms 24268 KB Output is correct
11 Correct 19 ms 24268 KB Output is correct
12 Correct 22 ms 24760 KB Output is correct
13 Correct 24 ms 24748 KB Output is correct
14 Correct 21 ms 24524 KB Output is correct
15 Correct 25 ms 25220 KB Output is correct
16 Correct 22 ms 24764 KB Output is correct
17 Correct 21 ms 24556 KB Output is correct
18 Correct 23 ms 25164 KB Output is correct
19 Correct 22 ms 24768 KB Output is correct
20 Correct 22 ms 24780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23756 KB Output is correct
2 Correct 19 ms 24196 KB Output is correct
3 Correct 18 ms 24152 KB Output is correct
4 Correct 14 ms 23888 KB Output is correct
5 Correct 16 ms 24140 KB Output is correct
6 Correct 17 ms 24396 KB Output is correct
7 Correct 15 ms 24068 KB Output is correct
8 Correct 15 ms 24236 KB Output is correct
9 Correct 16 ms 24212 KB Output is correct
10 Correct 16 ms 24268 KB Output is correct
11 Correct 19 ms 24268 KB Output is correct
12 Correct 22 ms 24760 KB Output is correct
13 Correct 24 ms 24748 KB Output is correct
14 Correct 21 ms 24524 KB Output is correct
15 Correct 25 ms 25220 KB Output is correct
16 Correct 22 ms 24764 KB Output is correct
17 Correct 21 ms 24556 KB Output is correct
18 Correct 23 ms 25164 KB Output is correct
19 Correct 22 ms 24768 KB Output is correct
20 Correct 22 ms 24780 KB Output is correct
21 Correct 43 ms 27764 KB Output is correct
22 Correct 61 ms 30020 KB Output is correct
23 Correct 73 ms 31716 KB Output is correct
24 Correct 90 ms 30072 KB Output is correct
25 Correct 60 ms 29884 KB Output is correct
26 Correct 82 ms 30396 KB Output is correct
27 Correct 83 ms 31428 KB Output is correct
28 Correct 64 ms 29792 KB Output is correct
29 Correct 71 ms 29856 KB Output is correct
30 Correct 104 ms 34240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23756 KB Output is correct
2 Correct 19 ms 24196 KB Output is correct
3 Correct 18 ms 24152 KB Output is correct
4 Correct 14 ms 23888 KB Output is correct
5 Correct 16 ms 24140 KB Output is correct
6 Correct 17 ms 24396 KB Output is correct
7 Correct 15 ms 24068 KB Output is correct
8 Correct 15 ms 24236 KB Output is correct
9 Correct 16 ms 24212 KB Output is correct
10 Correct 16 ms 24268 KB Output is correct
11 Correct 490 ms 73492 KB Output is correct
12 Correct 1058 ms 85860 KB Output is correct
13 Correct 626 ms 82136 KB Output is correct
14 Correct 1403 ms 117040 KB Output is correct
15 Correct 1407 ms 120836 KB Output is correct
16 Correct 1553 ms 141124 KB Output is correct
17 Correct 612 ms 82448 KB Output is correct
18 Correct 1267 ms 108804 KB Output is correct
19 Correct 1387 ms 116044 KB Output is correct
20 Correct 1069 ms 115912 KB Output is correct
21 Correct 19 ms 24268 KB Output is correct
22 Correct 22 ms 24760 KB Output is correct
23 Correct 24 ms 24748 KB Output is correct
24 Correct 21 ms 24524 KB Output is correct
25 Correct 25 ms 25220 KB Output is correct
26 Correct 22 ms 24764 KB Output is correct
27 Correct 21 ms 24556 KB Output is correct
28 Correct 23 ms 25164 KB Output is correct
29 Correct 22 ms 24768 KB Output is correct
30 Correct 22 ms 24780 KB Output is correct
31 Correct 43 ms 27764 KB Output is correct
32 Correct 61 ms 30020 KB Output is correct
33 Correct 73 ms 31716 KB Output is correct
34 Correct 90 ms 30072 KB Output is correct
35 Correct 60 ms 29884 KB Output is correct
36 Correct 82 ms 30396 KB Output is correct
37 Correct 83 ms 31428 KB Output is correct
38 Correct 64 ms 29792 KB Output is correct
39 Correct 71 ms 29856 KB Output is correct
40 Correct 104 ms 34240 KB Output is correct
41 Correct 335 ms 61296 KB Output is correct
42 Correct 735 ms 88332 KB Output is correct
43 Correct 629 ms 80640 KB Output is correct
44 Correct 595 ms 87484 KB Output is correct
45 Correct 727 ms 95568 KB Output is correct
46 Correct 970 ms 104156 KB Output is correct
47 Correct 1291 ms 124184 KB Output is correct
48 Correct 605 ms 83304 KB Output is correct
49 Correct 861 ms 110688 KB Output is correct
50 Correct 902 ms 109532 KB Output is correct
51 Correct 590 ms 73228 KB Output is correct
52 Correct 538 ms 74664 KB Output is correct
53 Correct 599 ms 82260 KB Output is correct
54 Correct 1089 ms 95440 KB Output is correct
55 Correct 1183 ms 81328 KB Output is correct