답안 #16385

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
16385 2015-08-22T04:31:29 Z comet 낙하산 고리들 (IOI12_rings) C++
20 / 100
1754 ms 263168 KB
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#define pb push_back
using namespace std;
typedef vector<int> vec;
typedef vector<vec> mat;
int N,mode;
struct graph{
	vector<int> p,r;
	mat path;
	void init(int n){
		p.resize(n);
		r.resize(n,0);
		path.assign(n,vec());
		for(int i=0;i<n;i++)p[i]=i;
	}
	int find(int x){
		if(p[x]==x)return x;
		return p[x]=find(p[x]);
	}
	bool merge(int x,int y){
		x=find(x),y=find(y);
		if(x==y)return 0;
		if(r[x]>r[y])swap(x,y);
		p[x]=y;
		if(r[x]==r[y])r[y]++;
		return 1;
	}
	void finish(){
		path.clear();
	}
}A,z[4];
bool CircleChk[1000000],chk[4];
int cnt,Ex[4];

void Init(int n){
	N=n;
	A.init(n);
	for(int i=0;i<4;i++)z[i].init(n);
}

int CountCritical(){
	// Base
	if(mode==0){
		return N;
	}

	// Circle
	else if(mode==1){
		return cnt;
	}

	// Divided
	else if(mode==2){
		cnt=0;
		for(int k=0;k<4;k++)if(!chk[k])cnt++;
		if(cnt==0)mode=-1;
		return cnt;
	}

	// End
	else{
		return 0;
	}
}

void CircleBfs(int v){
	queue<int> Q;
	Q.push(v);
	CircleChk[v]=1;
	while(!Q.empty()){
		v=Q.front();
		cnt++;
		Q.pop();
		for(int i=0;i<A.path[v].size();i++){
          	int u=A.path[v][i];
			if(!CircleChk[u]){
				Q.push(u);
				CircleChk[u]=1;
			}
		}
	}
}

void make_graph(int x,int k){
	Ex[k]=x;
	for(int i=0;i<N;i++){
		if(x==i)continue;
		for(int t=0;t<A.path[i].size();t++){
          	int j=A.path[i][t];
			if(j==x)continue;
			z[k].path[i].pb(j);
			z[k].merge(i,j);
		}
		if(z[k].path[i].size()>2){
			chk[k]=1;
			return;
		}
	}
}

void Link(int x,int y){
	//End
	if(mode<0)return;

	// Base
	if(mode==0){
		A.path[x].pb(y);
		A.path[y].pb(x);
		if(A.path[x].size()<A.path[y].size())swap(x,y);
		if(A.path[x].size()>2){
			mode=2;
			for(int i=0;i<A.path[x].size();i++)
				make_graph(A.path[x][i],i);
			make_graph(x,3);
			A.finish();
			return;
		}

		if(!A.merge(x,y)){
			cnt=0;
			mode=1;
			CircleBfs(x);
		}
	}


	// Circle
	else if(mode==1){
		A.path[x].pb(y);
		A.path[y].pb(x);
		if(!A.merge(x,y)){
			mode=-1;
			return;
		}
		if(A.path[x].size()<A.path[y].size())swap(x,y);
		if(A.path[x].size()>2){
			if(CircleChk[x]==0&&CircleChk[y]==0){
				mode=-1;
				return;
			}
			mode=2;
			for(int i=0;i<A.path[x].size();i++){
				if(!CircleChk[A.path[x][i]]){
					chk[i]=1;
					continue;
				}
				make_graph(A.path[x][i],i);
			}
			make_graph(x,3);
			A.finish();
			return;
		}
	}

	// Divided
	else if(mode==2){
		for(int k=0;k<4;k++){
			if(chk[k])continue;
			if(Ex[k]==x||Ex[k]==y)continue;
			z[k].path[x].pb(y);
			z[k].path[y].pb(x);
			if(!z[k].merge(x,y))chk[k]=1;
			if(z[k].path[x].size()<z[k].path[y].size())swap(x,y);
			if(z[k].path[x].size()>2)chk[k]=1;
		}
	}
}

Compilation message

rings.cpp: In function 'void CircleBfs(int)':
rings.cpp:77:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<A.path[v].size();i++){
               ~^~~~~~~~~~~~~~~~~
rings.cpp: In function 'void make_graph(int, int)':
rings.cpp:91:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int t=0;t<A.path[i].size();t++){
               ~^~~~~~~~~~~~~~~~~
rings.cpp: In function 'void Link(int, int)':
rings.cpp:115:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i=0;i<A.path[x].size();i++)
                ~^~~~~~~~~~~~~~~~~
rings.cpp:145:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i=0;i<A.path[x].size();i++){
                ~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 6 ms 1524 KB Output is correct
3 Correct 6 ms 1544 KB Output is correct
4 Correct 2 ms 1544 KB Output is correct
5 Correct 4 ms 1544 KB Output is correct
6 Correct 5 ms 1544 KB Output is correct
7 Correct 3 ms 1544 KB Output is correct
8 Correct 5 ms 1544 KB Output is correct
9 Correct 8 ms 1808 KB Output is correct
10 Correct 9 ms 1940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 540 ms 98368 KB Output is correct
2 Correct 1692 ms 196204 KB Output is correct
3 Correct 488 ms 196204 KB Output is correct
4 Correct 1438 ms 196204 KB Output is correct
5 Correct 1441 ms 196204 KB Output is correct
6 Correct 1601 ms 196204 KB Output is correct
7 Correct 500 ms 196204 KB Output is correct
8 Runtime error 1754 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 6 ms 1524 KB Output is correct
3 Correct 6 ms 1544 KB Output is correct
4 Correct 2 ms 1544 KB Output is correct
5 Correct 4 ms 1544 KB Output is correct
6 Correct 5 ms 1544 KB Output is correct
7 Correct 3 ms 1544 KB Output is correct
8 Correct 5 ms 1544 KB Output is correct
9 Correct 8 ms 1808 KB Output is correct
10 Correct 9 ms 1940 KB Output is correct
11 Runtime error 9 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 6 ms 1524 KB Output is correct
3 Correct 6 ms 1544 KB Output is correct
4 Correct 2 ms 1544 KB Output is correct
5 Correct 4 ms 1544 KB Output is correct
6 Correct 5 ms 1544 KB Output is correct
7 Correct 3 ms 1544 KB Output is correct
8 Correct 5 ms 1544 KB Output is correct
9 Correct 8 ms 1808 KB Output is correct
10 Correct 9 ms 1940 KB Output is correct
11 Runtime error 9 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 6 ms 1524 KB Output is correct
3 Correct 6 ms 1544 KB Output is correct
4 Correct 2 ms 1544 KB Output is correct
5 Correct 4 ms 1544 KB Output is correct
6 Correct 5 ms 1544 KB Output is correct
7 Correct 3 ms 1544 KB Output is correct
8 Correct 5 ms 1544 KB Output is correct
9 Correct 8 ms 1808 KB Output is correct
10 Correct 9 ms 1940 KB Output is correct
11 Correct 540 ms 98368 KB Output is correct
12 Correct 1692 ms 196204 KB Output is correct
13 Correct 488 ms 196204 KB Output is correct
14 Correct 1438 ms 196204 KB Output is correct
15 Correct 1441 ms 196204 KB Output is correct
16 Correct 1601 ms 196204 KB Output is correct
17 Correct 500 ms 196204 KB Output is correct
18 Runtime error 1754 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
19 Halted 0 ms 0 KB -