답안 #60556

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
60556 2018-07-24T10:47:48 Z aome 낙하산 고리들 (IOI12_rings) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1000005;

int n;
int szCircle;
int sz[N], par[N];
vector<int> G[N];
vector< pair<int, int> > E;

struct DSU {
	int root;
	int valid;
	int par[N];
	int deg[N];

	int find(int u) { return u == par[u] ? u : par[u] = find(par[u]); }

	void join(int u, int v) { par[find(u)] = find(v); }

	void add(int u, int v) {
		if (!valid || u == root || v == root) return;
		int ru = find(u), rv = find(v);
		if (deg[u] == 2 || deg[v] == 2 || ru == rv) {
			valid = 0; return;
		}
		deg[u]++, deg[v]++;
		join(u, v);
	}

	DSU(int _root) {
		valid = 1, root = _root;
		for (int i = 0; i < n; ++i) {
			cnt[0][i] = 1, par[i] = i, deg[i] = 0;
		}
		for (auto i : E) add(i.first, i.second);
	}
};

vector<DSU> vec;

int find(int u) { return u == par[u] ? u : par[u] = find(par[u]); }

bool join(int u, int v) {
	u = find(u), v = find(v);
	if (u == v) return 0;
	sz[u] += sz[v], par[v] = u; return 1;
}

void Init(int _n) {
	n = _n;
	for (int i = 0; i < n; ++i) sz[i] = 1, par[i] = i;
}

void Link(int A, int B) {
	if (vec.size()) {
		for (int i = 0; i < vec.size(); ++i) vec[i].add(A, B);
		return;
	}
	E.push_back({A, B});
	G[A].push_back(B), G[B].push_back(A);
	if (G[A].size() < G[B].size()) swap(A, B);
	if (G[A].size() == 3) {
		vec.push_back(DSU(A));
		for (auto i : G[A]) {
			vec.push_back(DSU(i));
		}
		return;
	}
	if (!join(A, B)) {
		szCircle = sz[find(A)];
	}
}

int CountCritical() {
	int res = 0;
	if (vec.size()) {
		for (int i = 0; i < vec.size(); ++i) res += vec[i].valid;
	}
	else if (szCircle) res = szCircle;
	else res = n;
	return res;
}

Compilation message

rings.cpp: In constructor 'DSU::DSU(int)':
rings.cpp:36:4: error: 'cnt' was not declared in this scope
    cnt[0][i] = 1, par[i] = i, deg[i] = 0;
    ^~~
rings.cpp:36:4: note: suggested alternative: 'int'
    cnt[0][i] = 1, par[i] = i, deg[i] = 0;
    ^~~
    int
rings.cpp: In function 'void Link(int, int)':
rings.cpp:59:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < vec.size(); ++i) vec[i].add(A, B);
                   ~~^~~~~~~~~~~~
rings.cpp: In function 'int CountCritical()':
rings.cpp:80:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < vec.size(); ++i) res += vec[i].valid;
                   ~~^~~~~~~~~~~~