제출 #38898

#제출 시각아이디문제언어결과실행 시간메모리
38898adamczh1게임 (IOI14_game)C++14
컴파일 에러
0 ms0 KiB
#include "game.h"
#include <bits/stdc++.h>
struct UnionFind {
	vector<int> data;
	int compcnt;
	void init(int n) { data.assign(n, -1), compcnt=n; }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
			compcnt--;
		}
		return x != y;
	}
	bool findSet(int x, int y) { return root(x) == root(y); }
	int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
	int size(int x) { return -data[root(x)]; }
} uf;
void initialize(int n) {
	uf.init(n);
}

int hasEdge(int u, int v) {
	if(!uf.findSet(u,v) && uf.compcnt>2){
		uf.unionSet(u,v);
		uf.compcnt--;
	}
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

game.cpp:4:2: error: 'vector' does not name a type
  vector<int> data;
  ^
game.cpp: In member function 'void UnionFind::init(int)':
game.cpp:6:21: error: 'data' was not declared in this scope
  void init(int n) { data.assign(n, -1), compcnt=n; }
                     ^
game.cpp: In member function 'bool UnionFind::unionSet(int, int)':
game.cpp:10:8: error: 'data' was not declared in this scope
    if (data[y] < data[x]) swap(x, y);
        ^
game.cpp:10:36: error: 'swap' was not declared in this scope
    if (data[y] < data[x]) swap(x, y);
                                    ^
game.cpp:10:36: note: suggested alternatives:
In file included from /usr/include/c++/5/complex:45:0,
                 from /usr/include/c++/5/ccomplex:38,
                 from /usr/include/x86_64-linux-gnu/c++/5/bits/stdc++.h:52,
                 from game.cpp:2:
/usr/include/c++/5/sstream:783:5: note:   'std::__cxx11::swap'
     swap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x,
     ^
In file included from /usr/include/c++/5/regex:61:0,
                 from /usr/include/x86_64-linux-gnu/c++/5/bits/stdc++.h:108,
                 from game.cpp:2:
/usr/include/c++/5/bits/regex.h:1952:5: note:   'std::__cxx11::swap'
     swap(match_results<_Bi_iter, _Alloc>& __lhs,
     ^
In file included from /usr/include/c++/5/exception:162:0,
                 from /usr/include/c++/5/ios:39,
                 from /usr/include/c++/5/istream:38,
                 from /usr/include/c++/5/sstream:38,
                 from /usr/include/c++/5/complex:45,
                 from /usr/include/c++/5/ccomplex:38,
                 from /usr/include/x86_64-linux-gnu/c++/5/bits/stdc++.h:52,
                 from game.cpp:2:
/usr/include/c++/5/bits/exception_ptr.h:160:5: note:   'std::__exception_ptr::swap'
     swap(exception_ptr& __lhs, exception_ptr& __rhs)
     ^
game.cpp:11:4: error: 'data' was not declared in this scope
    data[x] += data[y]; data[y] = x;
    ^
game.cpp: In member function 'int UnionFind::root(int)':
game.cpp:17:27: error: 'data' was not declared in this scope
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
                           ^
game.cpp: In member function 'int UnionFind::size(int)':
game.cpp:18:28: error: 'data' was not declared in this scope
  int size(int x) { return -data[root(x)]; }
                            ^