이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define int long long
#define all(a) a.begin(),a.end()
#define rank rank_
const int mxN = (int)2e6+2;
const int MOD = (int)1e9+7;
int n, a[mxN], SZ, cnt[mxN], rank[mxN], bipartite[mxN];
pair<int,int> parent[mxN];
void make_set(int v) {
parent[v] = make_pair(v, 0);
rank[v] = 0;
bipartite[v] = true;
}
pair<int, int> find_set(int v) {
if (v != parent[v].first) {
int parity = parent[v].second;
parent[v] = find_set(parent[v].first);
parent[v].second ^= parity;
}
return parent[v];
}
void unionSet(int a, int b) {
pair<int, int> pa = find_set(a);
a = pa.first;
int x = pa.second;
pair<int, int> pb = find_set(b);
b = pb.first;
int y = pb.second;
if (a == b) {
if (x == y)
bipartite[a] = false;
} else {
if (rank[a] < rank[b])
swap (a, b); SZ--;
parent[b] = make_pair(a, x^y^1);
bipartite[a] &= bipartite[b];
if (rank[a] == rank[b])
++rank[a];
}
}
bool is_bipartite(int v) {
return bipartite[find_set(v).first];
}
int poww(int a, int b){
if(!b) return 1;
int x = poww(a,b/2);
x*=x,x%=MOD;
if(b&1)x*=a,x%=MOD;
return x;
}
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n; SZ=n;
for(int i = 0; i < n; i++) make_set(i);
for(int i = 0; i < n; i++){
int x, y; cin >> x >> y;
a[x]=a[y]=i;
}
set<pair<int,int>> S;
for(int i = 1; i <= 2*n; i++){
if(cnt[a[i]]){
S.erase({cnt[a[i]],a[i]});
auto itr = S.lower_bound(make_pair(cnt[a[i]],-1));
while(itr!=S.end()){
if(find_set(itr->se)==find_set(a[i])) break;
unionSet(itr->se,a[i]);
if(!is_bipartite(itr->se) or !is_bipartite(a[i])) { cout << 0; return 0; }
itr++;
}
}
else S.insert({i,a[i]}),cnt[a[i]]=i;
}
cout << poww(2,SZ);
}
컴파일 시 표준 에러 (stderr) 메시지
port_facility.cpp: In function 'void unionSet(long long int, long long int)':
port_facility.cpp:43:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
43 | if (rank[a] < rank[b])
| ^~
port_facility.cpp:44:26: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
44 | swap (a, b); SZ--;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |