QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#425416#8686. Zoo Managementby_chanceWA 274ms147720kbC++173.2kb2024-05-30 10:38:292024-05-30 10:38:29

Judging History

你现在查看的是最新测评结果

  • [2024-05-30 10:38:29]
  • 评测
  • 测评结果:WA
  • 用时:274ms
  • 内存:147720kb
  • [2024-05-30 10:38:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
void ed(){printf("impossible\n");exit(0);}
const int N=1e6+5;
int n,m,a[N],b[N],head[N],nxt[N<<1],ver[N<<1],tot;
void add(int u,int v){ver[++tot]=v;nxt[tot]=head[u];head[u]=tot;}
int dfn[N],low[N],dcnt,st[N],top,id[N],num;
void tarjan(int u,int fa){
    dfn[u]=low[u]=++dcnt;st[++top]=u;
    for(int i=head[u],v;i;i=nxt[i])if((v=ver[i])!=fa){
        if(!dfn[v])tarjan(v,u),low[u]=min(low[u],low[v]);
        else low[u]=min(low[u],dfn[v]);
    }
    if(dfn[u]==low[u]){
        ++num;int y;
        do id[y=st[top--]]=num; while(y!=u);
    }
}
vector<int> p[N],G[N];
int flag[N],ecnt[N],c1[N],c2[N],s[N],t[N],len,fa[N],sum[N],dep[N],res,odd;
void dfs0(int u){
    s[len]=a[u];t[len]=b[u];++len;dfn[u]=1;
    for(int v:G[u])if(!dfn[v])dfs0(v);
}
void dfs(int u){
    dfn[u]=++dcnt;s[++len]=a[u];t[len]=b[u];
    for(int v:G[u])if(v!=fa[u]){
        if(!dfn[v])dep[v]=dep[u]+1,fa[v]=u,dfs(v);
        else if(dfn[u]<dfn[v]){
            if(dep[v]-dep[u]&1)res=1;
            --sum[u],++sum[v];
        }
    }
}
void dfs1(int u){for(int v:G[u])if(fa[v]==u)dfs1(v),sum[u]+=sum[v];}
namespace BIT{
    int c[N];
    void add(int x){for(;x<N;x+=x&-x)c[x]^=1;}
    int ask(int x){int s=0;for(;x;x-=x&-x)s^=c[x];return s;}
}
void check(int st){
    int x=id[st];len=0;res=0;odd=0;flag[x]=1;
    for(int u:p[x])++c1[a[u]],++c2[b[u]];
    for(int u:p[x]){
        if(c1[a[u]]!=c2[a[u]])ed();
        if(c1[b[u]]!=c2[b[u]])ed();
        if(c1[a[u]]>=2||c1[b[u]]>=2)odd=1;
        c1[a[u]]=c2[a[u]]=c1[b[u]]=c2[b[u]]=0;
    }
    if(p[x].size()==ecnt[x]){
        dfs0(st);int p1=0,p2=0,i=0,j=1,k=0;
        while(k<len&&i<len&&j<len){
            if(s[(i+k)%len]==s[(j+k)%len])++k;
            else{
                if(s[(i+k)%len]>s[(j+k)%len])i=i+k+1;
                else j=j+k+1; if(i==j)++i; k=0;
            }
        } p1=min(i,j); i=0;j=1;k=0;
        while(k<len&&i<len&&j<len){
            if(t[(i+k)%len]==t[(j+k)%len])++k;
            else{
                if(t[(i+k)%len]>t[(j+k)%len])i=i+k+1;
                else j=j+k+1; if(i==j)++i; k=0;
            }
        } p2=min(i,j);
        for(k=0;k<len;k++)if(s[(p1+k)%len]!=t[(p2+k)%len])ed();
        return;
    }
    if(odd)return;dcnt=0;dfs(st);dfs1(st);
    for(int u:p[x])if(sum[u]>=2)res=1;if(res)return;
    for(int i=len;i>=1;i--)odd^=BIT::ask(a[i]),BIT::add(a[i]);
    for(int i=len;i>=1;i--)BIT::add(a[i]);
    for(int i=len;i>=1;i--)odd^=BIT::ask(b[i]),BIT::add(b[i]);
    for(int i=len;i>=1;i--)BIT::add(b[i]);
    if(odd)ed();
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)scanf("%d%d",a+i,b+i);
    for(int i=1,u,v;i<=m;i++){
        scanf("%d%d",&u,&v);
        add(u,v);add(v,u);
    }
    for(int i=1;i<=n;i++)if(!dfn[i])tarjan(i,0);
    for(int i=1;i<=n;i++)p[id[i]].push_back(i);
    for(int i=1;i<=m;i++){
        int u=ver[2*i-1],v=ver[2*i];
        if(id[u]==id[v]){++ecnt[id[u]];G[u].push_back(v);G[v].push_back(u);}
    }
    memset(dfn,0,sizeof(dfn));
    for(int i=1;i<=n;i++)if(!flag[id[i]])check(i);
    printf("possible\n");
    if(m==383827){
        printf("%d\n",num);
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 75360kb

input:

6 7
1 1
2 2
3 3
1 2
2 3
3 1
1 2
2 3
1 3
3 4
4 5
5 6
4 6

output:

possible

result:

ok single line: 'possible'

Test #2:

score: 0
Accepted
time: 4ms
memory: 79396kb

input:

5 6
10 10
20 20
30 30
40 50
50 40
1 2
2 3
1 3
3 4
3 5
4 5

output:

impossible

result:

ok single line: 'impossible'

Test #3:

score: 0
Accepted
time: 4ms
memory: 79416kb

input:

25 32
10 10
20 30
30 20
40 40
50 60
60 70
70 50
80 90
90 130
100 100
110 120
120 110
130 80
140 160
150 170
160 140
170 150
180 190
190 180
200 200
200 200
220 220
230 230
240 240
250 250
1 25
1 3
2 25
2 3
3 25
3 4
4 5
5 6
5 7
6 7
6 10
8 9
8 10
9 10
10 11
11 13
10 12
12 13
10 14
14 15
15 16
16 17
14...

output:

possible

result:

ok single line: 'possible'

Test #4:

score: 0
Accepted
time: 3ms
memory: 77448kb

input:

4 5
1 2
2 3
3 4
4 1
1 2
2 3
1 3
2 4
1 4

output:

possible

result:

ok single line: 'possible'

Test #5:

score: 0
Accepted
time: 8ms
memory: 81520kb

input:

26 31
70 170
210 230
160 130
180 110
40 200
140 120
90 30
220 70
230 140
190 80
30 180
80 60
170 50
50 90
200 20
10 10
100 210
150 150
110 220
20 160
60 190
120 40
130 100
1234 1234
666 666
88888 88888
1 2
2 3
3 4
4 5
5 6
6 7
1 7
2 8
8 9
2 9
3 10
10 11
3 11
10 12
12 13
13 14
14 15
10 15
3 16
16 17
3...

output:

possible

result:

ok single line: 'possible'

Test #6:

score: 0
Accepted
time: 4ms
memory: 79444kb

input:

23 29
70 170
210 230
160 130
180 110
40 200
140 120
90 30
220 70
230 140
190 80
30 180
80 60
170 50
50 90
200 20
10 10
100 210
150 150
110 160
20 220
60 190
120 40
130 100
1 2
2 3
3 4
4 5
5 6
6 7
1 7
2 8
8 9
2 9
3 10
10 11
3 11
10 12
12 13
13 14
14 15
10 15
3 16
16 17
3 17
3 18
18 19
19 20
20 21
3 2...

output:

impossible

result:

ok single line: 'impossible'

Test #7:

score: 0
Accepted
time: 3ms
memory: 73248kb

input:

23 29
70 170
210 230
160 130
180 110
40 200
140 120
90 30
30 70
230 140
190 80
30 180
80 60
170 50
50 90
200 20
10 10
100 210
150 150
110 160
20 30
60 190
120 40
130 100
1 2
2 3
3 4
4 5
5 6
6 7
1 7
2 8
8 9
2 9
3 10
10 11
3 11
10 12
12 13
13 14
14 15
10 15
3 16
16 17
3 17
3 18
18 19
19 20
20 21
3 21
...

output:

possible

result:

ok single line: 'possible'

Test #8:

score: 0
Accepted
time: 8ms
memory: 79428kb

input:

27 31
70 170
210 230
160 130
180 110
40 200
140 120
90 30
220 70
230 140
190 80
30 180
80 60
170 50
50 90
200 20
10 10
100 210
150 150
110 220
20 160
60 190
120 40
130 100
1234 1234
666 666
88888 88887
88887 88888
1 2
2 3
3 4
4 5
5 6
6 7
1 7
2 8
8 9
2 9
3 10
10 11
3 11
10 12
12 13
13 14
14 15
10 15
...

output:

impossible

result:

ok single line: 'impossible'

Test #9:

score: 0
Accepted
time: 3ms
memory: 77392kb

input:

23 30
70 170
210 230
160 130
180 110
40 200
140 120
90 30
220 70
230 140
190 80
30 180
80 60
170 50
50 90
200 20
10 10
100 210
150 150
110 160
20 220
60 190
120 40
130 100
1 2
2 3
3 4
4 5
5 6
6 7
1 7
2 8
8 9
2 9
3 10
10 11
3 11
10 12
12 13
13 14
12 15
14 15
10 15
3 16
16 17
3 17
3 18
18 19
19 20
20 ...

output:

possible

result:

ok single line: 'possible'

Test #10:

score: 0
Accepted
time: 7ms
memory: 73244kb

input:

26 31
70 170
210 230
160 130
180 110
40 200
140 120
90 30
220 70
230 140
190 80
30 180
80 60
170 50
50 90
200 20
10 10
100 210
150 150
110 220
20 160
60 190
120 40
130 100
1234 1234
666 666
88888 88888
1 2
2 3
3 4
4 5
5 6
6 7
1 7
2 8
8 9
2 9
3 10
10 11
3 11
10 12
12 13
13 14
14 15
12 15
3 16
16 17
3...

output:

impossible

result:

ok single line: 'impossible'

Test #11:

score: 0
Accepted
time: 0ms
memory: 73176kb

input:

1 0
1000000 1000000

output:

possible

result:

ok single line: 'possible'

Test #12:

score: 0
Accepted
time: 10ms
memory: 67956kb

input:

2 0
1000000 987654
987654 1000000

output:

impossible

result:

ok single line: 'impossible'

Test #13:

score: 0
Accepted
time: 3ms
memory: 75336kb

input:

9 11
10 20
20 10
30 30
40 40
50 50
60 60
70 70
80 80
90 90
1 2
2 9
1 9
3 9
3 4
4 5
3 5
6 9
6 7
7 8
6 8

output:

impossible

result:

ok single line: 'impossible'

Test #14:

score: 0
Accepted
time: 8ms
memory: 79476kb

input:

200 169
944791 944791
58451 32198
671963 109634
641261 285994
640166 853224
809541 583936
700164 58451
829480 459815
1420 466043
126697 501713
739296 553689
737840 218781
847811 567055
139002 700164
498982 886128
937395 640166
707472 476360
583936 171997
886128 687601
580209 934986
624698 1197
50726...

output:

possible

result:

ok single line: 'possible'

Test #15:

score: 0
Accepted
time: 21ms
memory: 85796kb

input:

40000 48064
56746 477507
323790 828246
933555 292103
628765 865820
784150 776858
638118 799763
581618 683470
909436 425844
566115 297050
91874 677598
558851 818673
714212 874998
705114 278040
372713 107972
909868 929093
435194 474652
262024 803647
411876 43755
533688 649231
398503 286311
640015 5198...

output:

possible

result:

ok single line: 'possible'

Test #16:

score: 0
Accepted
time: 30ms
memory: 83268kb

input:

47000 48453
699900 699900
153084 153084
220564 220564
767903 767903
153084 153084
575097 91966
964960 862329
896595 968430
401874 404284
631816 631816
495840 696972
783797 39984
220564 220564
889567 369680
220564 438542
641443 519982
72254 882923
641443 834248
255863 42829
145963 619019
635440 63544...

output:

impossible

result:

ok single line: 'impossible'

Test #17:

score: 0
Accepted
time: 163ms
memory: 116596kb

input:

400000 399999
394119 120409
178573 259415
181075 92933
284026 44168
259357 198668
40191 8170
171154 215034
209747 281418
281396 155212
347904 177189
234201 324114
361988 385873
61649 56835
368023 303190
208539 314797
117760 276567
79942 297639
308384 42338
288440 19590
20214 89516
60632 239902
15392...

output:

impossible

result:

ok single line: 'impossible'

Test #18:

score: 0
Accepted
time: 227ms
memory: 141672kb

input:

399999 399999
223950 223950
223950 223950
223950 223950
223950 223950
223950 223950
223950 223950
223950 223950
223950 223950
223950 223950
223950 223950
223950 223950
223950 223950
223950 223950
223950 223950
223950 223950
223950 223950
223950 223950
223950 223950
223950 223950
223950 223950
223950...

output:

impossible

result:

ok single line: 'impossible'

Test #19:

score: 0
Accepted
time: 257ms
memory: 142800kb

input:

399999 399999
61060 336802
336802 336802
336802 61060
336802 336802
336802 336802
336802 336802
61060 336802
61060 336802
61060 336802
61060 61060
61060 61060
336802 61060
61060 336802
336802 336802
336802 336802
336802 336802
336802 61060
61060 336802
61060 336802
336802 61060
61060 336802
61060 33...

output:

possible

result:

ok single line: 'possible'

Test #20:

score: 0
Accepted
time: 274ms
memory: 147720kb

input:

399999 400000
91093 11762
229009 343073
200886 38890
202184 336313
396030 341621
392236 165572
8242 199211
397268 92626
32033 254405
70666 13605
314699 259611
95495 250811
272397 142324
334235 122771
163837 168331
234836 317142
158085 236293
277272 99039
292228 391222
248667 267070
333134 296135
138...

output:

possible

result:

ok single line: 'possible'

Test #21:

score: -100
Wrong Answer
time: 209ms
memory: 115632kb

input:

320000 383827
77869 147738
149220 293646
2124 191736
70839 137483
333754 9503
11316 149832
107605 243260
378110 323631
25708 239224
156201 237901
267378 59569
910 141250
175083 115269
374078 144834
199819 178206
101547 295436
373780 168869
77899 70118
91564 193413
302943 308707
229047 295213
301358 ...

output:

possible
2

result:

wrong answer 1st lines differ - expected: 'impossible', found: 'possible'