이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
struct unionfind{
int sz;
vector<int> tree;
unionfind(int size):sz(size),tree(size,-1){}
int leader(int p){
int pos;
while(tree[p]>=0)p=tree[p];
while(tree[pos]>=0){
int bef=tree[pos];
tree[pos]=p;
pos=tree[pos];
}
return p;
}
int size(int p){
return -tree[leader(p)];
}
bool merge(int x,int y){
x=leader(x);
y=leader(y);
if(x==y)return false;
if(tree[x]>tree[y])swap(x,y);
tree[x]+=tree[y];
tree[y]=x;
return true;
}
};
vector<vector<int>> edge;
unionfind uni(0);
int N;
void initialize(int n) {
N=n;
edge.resize(n,vector<int>(n,0));
uni=unionfind(n);
}
int hasEdge(int u, int v) {
u=uni.leader(u);
v=uni.leader(v);
assert(u!=v);
edge[u][v]++;
edge[v][u]++;
if(uni.size(u)*uni.size(v)==edge[u][v]){
uni.merge(u,v);
if(uni.leader(u)!=u)swap(u,v);
rep(i,N){
if(i==u)continue;
if(i==v)continue;
edge[i][u]+=edge[i][v];
edge[u][i]+=edge[v][i];
}
return 1;
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
game.cpp: In member function 'int unionfind::leader(int)':
game.cpp:13:17: warning: unused variable 'bef' [-Wunused-variable]
13 | int bef=tree[pos];
| ^~~
game.cpp: In function 'int hasEdge(int, int)':
game.cpp:12:23: warning: 'pos' is used uninitialized in this function [-Wuninitialized]
12 | while(tree[pos]>=0){
| ^
game.cpp:10:13: note: 'pos' was declared here
10 | int pos;
| ^~~
game.cpp:12:23: warning: 'pos' is used uninitialized in this function [-Wuninitialized]
12 | while(tree[pos]>=0){
| ^
game.cpp:10:13: note: 'pos' was declared here
10 | int pos;
| ^~~
game.cpp:12:23: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
12 | while(tree[pos]>=0){
| ^
game.cpp:10:13: note: 'pos' was declared here
10 | int pos;
| ^~~
game.cpp:12:23: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
12 | while(tree[pos]>=0){
| ^
game.cpp:10:13: note: 'pos' was declared here
10 | int pos;
| ^~~
game.cpp:12:23: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
12 | while(tree[pos]>=0){
| ^
game.cpp:10:13: note: 'pos' was declared here
10 | int pos;
| ^~~
game.cpp:12:23: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
12 | while(tree[pos]>=0){
| ^
game.cpp:10:13: note: 'pos' was declared here
10 | int pos;
| ^~~
game.cpp:12:23: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
12 | while(tree[pos]>=0){
| ^
game.cpp:10:13: note: 'pos' was declared here
10 | int pos;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |