이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <game.h>
using namespace std;
struct dsu {
vector<int> parent;
vector<int> compSize;
int n;
int cc;
void fill(){
cc = n;
parent.resize(n), compSize.resize(n);
for(int i = 0; i < n; i++){
parent[i] = i, compSize[i] = 1;
}
}
int find_head(int x){
if(x == parent[x]){
return x;
}
return find_head(parent[x]);
}
void join(int x, int y){
x = find_head(x);
y = find_head(y);
if(x == y){
return;
}
cc--;
if(compSize[x] > compSize[y]){
swap(x,y);
//ensures that compSize[x1] <= compSize[y1]
}
parent[x] = y;
compSize[y] += compSize[x];
}
bool comp(int x, int y){
return (find_head(x) == find_head(y));
}
};
dsu d;
vector<set<int> > e;
void initialize (int n) {
d.n = n;
e.resize(n);
d.fill();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (j != i) {
e[i].insert(j);
}
}
}
}
int hasEdge (int u, int v) {
e[u].erase(v);
e[v].erase(u);
d.fill();
for (int i = 0; i < e.size(); i++) {
for (int j: e[i]) {
d.join(i, j);
}
}
if (d.cc == 1) {
return false;
}
e[u].insert(v);
e[v].insert(u);
return true;
}
/*
int main() {
initialize(4);
cout << hasEdge(0, 1) << '\n';
cout << hasEdge(1, 3) << '\n';
cout << hasEdge(1, 2) << '\n';
cout << hasEdge(2, 0) << '\n';
cout << hasEdge(2, 3) << '\n';
cout << hasEdge(0, 3) << '\n';
}
*/
컴파일 시 표준 에러 (stderr) 메시지
game.cpp: In function 'int hasEdge(int, int)':
game.cpp:58:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::set<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for (int i = 0; i < e.size(); i++) {
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |