이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for (int i=0; i<n; ++i)
vector<multiset<int>> A;
struct DSU {
vector<int> p;
vector<int> r;
vector<int> q;
vector<int> o;
DSU(int n) {
p.assign(n,0);
r.assign(n,0);
forn(i,n) p[i]=i;
q.assign(n,n-1);
o.assign(n,0);
}
int get(int i) {
return p[i]==i ? i : get(p[i]);
}
void uni(int a, int b) {
a=get(a);
b=get(b);
if (a==b) return;
if (r[a]==r[b]) r[a]++;
if (r[a]>r[b]) {
swap(a,b);
}
p[a]=b;
q[b]+=q[a]-2;
o[b]+=o[a]-1;
forn(i,A.size()) {
while (A[i].find(a)!=A[i].end()) {
A[i].erase(A[i].find(a));
A[i].insert(b);
}
}
while (A[a].size()) {
A[b].insert(*A[a].begin());
A[a].erase(A[a].begin());
}
}
void substract(int a, int b) {
a=get(a);
b=get(b);
--q[a];
--q[b];
}
int getq(int a) {
a=get(a);
return q[a];
}
int geto(int a) {
a=get(a);
return o[a];
}
void inco(int a) {
a=get(a);
o[a]++;
}
};
DSU dsu(0);
int q;
int n;
void initialize(int N) {
n=N;
DSU paiu(n);
dsu=paiu;
q=n*(n-1)/2;
A.resize(n);
forn(i,n) forn(j,n) if (i!=j) A[i].insert(j);
//cout<<"!"<<dsu.p.size()<<'\n';
}
int hasEdge(int u, int v) {
u=dsu.get(u), v=dsu.get(v);
if (u==v) {
return 1;
} else {
dsu.substract(u,v);
A[u].erase(A[u].find(v));
A[v].erase(A[v].find(u));
if (A[u].size()==1) {
int V=*A[u].begin();
A[u].clear();
A[V].erase(u);
dsu.uni(u,V);
u=V;
}
if (A[v].size()==1) {
int V=*A[v].begin();
A[v].clear();
A[V].erase(v);
dsu.uni(v,V);
v=V;
}
return 0;
}
}
컴파일 시 표준 에러 (stderr) 메시지
game.cpp: In member function 'void DSU::uni(int, int)':
game.cpp:5:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::multiset<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
5 | #define forn(i,n) for (int i=0; i<n; ++i)
......
46 | forn(i,A.size()) {
| ~~~~~~~~~~
game.cpp:46:9: note: in expansion of macro 'forn'
46 | forn(i,A.size()) {
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |