답안 #18671

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
18671 2016-02-14T02:10:16 Z suhgyuho_william 낙하산 고리들 (IOI12_rings) C++
0 / 100
2037 ms 63264 KB
#include <vector>
#include <stdio.h>
#include <queue>

using namespace std;

int N;
vector<int> edge[1000010];
bool check[1000010],flag;
int q[1000010],top,rear;

int jj;
void dfs2(int x,int par){
    int i,v,cnt = 0;

    check[x] = true;
    for(i=0; i<edge[x].size(); i++){
        v = edge[x][i];
        if(v == par || v == jj) continue;
        if(check[v]){ flag = false; continue; }
        dfs2(v,x);
        cnt++;
    }
    if(cnt >= 2) flag = false;
}

int checking(int x){
	int i,t,v;

	jj = x;
	for(i=1; i<=N; i++) check[i] = false;
	flag = true; check[jj] = true;
	for(i=1; i<=N; i++){
		if(!check[i]){
			t = 0;
			for(int k=0; k<edge[i].size(); k++){
				v = edge[i][k];
				if(v == jj) continue;
				t++;
				if(t == 3){
					flag = false;
					break;
				}
				dfs2(v,i);
			}
		}
		if(!flag) break;
	}
	if(flag) return 1;
	else return 0;
}

void Init(int N_) {
	N = N_;
}

void Link(int A, int B) {
	A++; B++;
	edge[A].push_back(B);
	edge[B].push_back(A);
}

int problem;
void dfs(int x,int par){
    int i,v,cnt = 0;

    check[x] = true;
    for(i=0; i<edge[x].size(); i++){
        v = edge[x][i];
        if(v == par) continue;
        if(check[v]){
			flag = false;
			problem = x;
			continue;
		}
        dfs(v,x);
        cnt++;
    }
    if(cnt >= 2){
		flag = false;
		problem = x;
    }
}
int ischain(int x){
	int i,t;

	check[x] = true; t = 0; flag = true;
	for(i=0; i<edge[x].size(); i++){
		t++;
        if(!check[edge[x][i]]) dfs(edge[x][i],x);
	}
	if(t >= 3){
		flag = false;
	}
	if(flag) return 0; // chain
	else return 1;
}

int CountCritical() {
	int i,j,cnt,s,v;
	int ans = 0;

	cnt = 0;
	for(i=1; i<=N; i++) check[i] = false;
	for(i=1; i<=N; i++){
		if(!check[i]){
			if(ischain(i) == 1){
				cnt++;
				s = i;
			}
		}
	}
	if(cnt >= 2) return 0;
	if(cnt == 0) return N;
	for(i=1; i<=N; i++) check[i] = false;
	cnt = edge[s].size();
	if(cnt > 3){
		ans += checking(s);
		return ans;
	}else if(cnt == 3){
        ans += checking(s);
        for(i=0; i<edge[s].size(); i++){
			v = edge[s][i];
			ans += checking(v);
        }
        return ans;
	}else{
		i = ischain(s); s = problem;
		rear = 1; q[1] = s;
		for(i=0; i<edge[s].size(); i++) q[++rear] = edge[s][i];
		for(i=1; i<=rear; i++) check[q[i]] = true;
		for(i=2; i<=rear; i++){
			v = q[i];
			for(j=0; j<edge[v].size(); j++){
				if(!check[edge[v][j]]){
					q[++rear] = edge[v][j];
					check[q[rear]] = true;
				}
			}
		}
		for(i=1; i<=rear; i++) ans += checking(q[i]);
		/*ans += checking(s);
		if(edge[s].size() > 3) return ans;
		for(i=0; i<edge[s].size(); i++){
			v = edge[s][i];
			ans += checking(v);
		}*/
	}
	return ans;
}

Compilation message

rings.cpp: In function 'void dfs2(int, int)':
rings.cpp:17:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0; i<edge[x].size(); i++){
              ~^~~~~~~~~~~~~~~
rings.cpp: In function 'int checking(int)':
rings.cpp:36:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int k=0; k<edge[i].size(); k++){
                 ~^~~~~~~~~~~~~~~
rings.cpp: In function 'void dfs(int, int)':
rings.cpp:68:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0; i<edge[x].size(); i++){
              ~^~~~~~~~~~~~~~~
rings.cpp: In function 'int ischain(int)':
rings.cpp:88:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0; i<edge[x].size(); i++){
           ~^~~~~~~~~~~~~~~
rings.cpp: In function 'int CountCritical()':
rings.cpp:122:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(i=0; i<edge[s].size(); i++){
                  ~^~~~~~~~~~~~~~~
rings.cpp:130:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(i=0; i<edge[s].size(); i++) q[++rear] = edge[s][i];
            ~^~~~~~~~~~~~~~~
rings.cpp:134:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(j=0; j<edge[v].size(); j++){
             ~^~~~~~~~~~~~~~~
rings.cpp:128:5: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
   i = ischain(s); s = problem;
   ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 26 ms 24056 KB Output is correct
3 Correct 25 ms 24128 KB Output is correct
4 Incorrect 21 ms 24128 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 527 ms 41104 KB Output is correct
2 Correct 1890 ms 50132 KB Output is correct
3 Correct 1129 ms 63264 KB Output is correct
4 Incorrect 2037 ms 63264 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 26 ms 24056 KB Output is correct
3 Correct 25 ms 24128 KB Output is correct
4 Incorrect 21 ms 24128 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 26 ms 24056 KB Output is correct
3 Correct 25 ms 24128 KB Output is correct
4 Incorrect 21 ms 24128 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 26 ms 24056 KB Output is correct
3 Correct 25 ms 24128 KB Output is correct
4 Incorrect 21 ms 24128 KB Output isn't correct
5 Halted 0 ms 0 KB -