이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
*/
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
///#define ll long long
typedef pair<int,int> pii;
const int maxn=1e6+10;
int mod=1e9+7;
int n,kolko,rez,sz[maxn],cc,levi[maxn];
pii niz[2*maxn],p[maxn];
void reset(){
for(int i=1;i<=n;i++){
p[i]={i,0};
sz[i]=1;
}
cc=n;
}
pii root(int x){
if(p[x].ff==x)return p[x];
else{
pii pom=root(p[x].ff);
p[x]={pom.ff,(p[x].ss^pom.ss)};
return p[x];
}
}
int join(int x,int y){
pii rx=root(x);
pii ry=root(y);
if(rx.ff==ry.ff){
if(rx.ss==ry.ss)return 1;
else return 0;
}
if(sz[rx.ff]<sz[ry.ff])swap(rx,ry),swap(x,y);
cc--;
p[ry.ff]={rx.ff,(rx.ss^ry.ss^1)};
sz[rx.ff]+=sz[ry.ff];
return 0;
}
int main(){
///freopen("test.txt","r",stdin);
clock_t start=clock();
scanf("%d",&n);
reset();
for(int i=1;i<=n;i++){
int a,b;
scanf("%d %d",&a,&b);
niz[a]={i,1};
niz[b]={i,-1};
levi[i]=a;
}
set<pii>st;
rez=1;
for(int i=1;i<=2*n;i++){
if(niz[i].ss>0)st.insert({i,niz[i].ff});
else{
int id=niz[i].ff;
int lb=levi[id];
set<pii>::iterator it=st.find({levi[id],id});
it++;
///printf("%d AAAAA\n",id);
for(;it!=st.end();it++){
int id2=(*it).ss;
///printf("%d AFSAFSAFSAFAS\n",id2);
if(join(id,id2)==1){
printf("0\n");
return 0;
}
}
st.erase(st.find({lb,id}));
clock_t sad=clock();
if((double)(sad-start)/CLOCKS_PER_SEC>5){
printf("0\n");
return 0;
}
}
}
for(int i=1;i<=cc;i++){
rez+=rez;
if(rez>=mod)rez-=mod;
}
printf("%d\n",rez);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
port_facility.cpp: In function 'int main()':
port_facility.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
port_facility.cpp:61:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&a,&b);
~~~~~^~~~~~~~~~~~~~~
# | 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... |