이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#define LOL
#if !defined(LOL)
#include "game.h"
#endif
using namespace std;
#define pb push_back
#define all(a) a.begin(),a.end()
#define ll long long
const int maxn = 1510;
int p[maxn], sz[maxn], cnt[maxn], edge[maxn][maxn], ind = 0;
int findSet(int i){return p[i]==-1?i:p[i]=findSet(p[i]);}
bool isSameSet(int i, int j){return findSet(i)==findSet(j);}
int unionSet(int i, int j){
int x = findSet(i), y = findSet(j);
if(x==y) return 0;
if(sz[x]<sz[y]) swap(x,y);
p[y] = x; sz[x]+=sz[y]; return 1;
}
void initialize(int n) {
for(int i = 0; i <= n; i++)
p[i]=-1,sz[i]=1,cnt[i]=0;
}
int hasEdge(int u, int v) {
u++, v++;
if(edge[u][v] or edge[v][u]) return 1;
if(isSameSet(u,v)) return 0;
if(!isSameSet(u,0) and !isSameSet(v,0)) return 0;
if(isSameSet(u,0)) swap(u,v); cnt[u]++;
if(cnt[u]==sz[findSet(0)])
return edge[u][v]=edge[v][u]=unionSet(u,0);
return 0;
}
#if defined(LOL)
int read_int() {
int x; assert(scanf("%d", &x) == 1); return x;
}
int main() {
int n, u, v; n = read_int(); initialize(n);
for (int i = 0; i < n * (n - 1) / 2; i++) {
u = read_int(); v = read_int();
printf("%d\n", hasEdge(u, v));
}
return 0;
}
#endif
컴파일 시 표준 에러 (stderr) 메시지
game.cpp: In function 'int hasEdge(int, int)':
game.cpp:32:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
32 | if(isSameSet(u,0)) swap(u,v); cnt[u]++;
| ^~
game.cpp:32:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
32 | if(isSameSet(u,0)) swap(u,v); cnt[u]++;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |