QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#120237#4635. Graph OperationmyeeRE 83ms21672kbC++114.3kb2023-07-06 15:20:312023-07-06 15:20:32

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-06 15:20:32]
  • 评测
  • 测评结果:RE
  • 用时:83ms
  • 内存:21672kb
  • [2023-07-06 15:20:31]
  • 提交

answer

// 那就是希望。
// 即便需要取模,也是光明。

#include <algorithm>
#include <stdio.h>
#include <vector>
typedef long long llt;
typedef unsigned uint;typedef unsigned long long ullt;
typedef bool bol;typedef char chr;typedef void voi;
typedef double dbl;
template<typename T>bol _max(T&a,T b){return(a<b)?a=b,true:false;}
template<typename T>bol _min(T&a,T b){return(b<a)?a=b,true:false;}
template<typename T>T lowbit(T n){return n&-n;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T lcm(T a,T b){return(a!=0||b!=0)?a/gcd(a,b)*b:(T)0;}
template<typename T>T exgcd(T a,T b,T&x,T&y){if(b!=0){T ans=exgcd(b,a%b,y,x);y-=a/b*x;return ans;}else return y=0,x=1,a;}
template<typename T>T power(T base,T index,T mod)
{
    T ans=1%mod;
    while(index)
    {
        if(index&1)ans=ans*base%mod;
        base=base*base%mod,index>>=1;
    }
    return ans;
}
// Heaven and Earth... My guiding star...
// Akira Complex R.I.P.
bol B[1005][1005],B2[1005][1005],G[1000005];
uint E[2][1000005],Tp[1000005],Ops[4][1000005],n,m,tp;
voi doit(uint a,uint b,uint c,uint d)
{
    if(a==b||b==c||c==d||d==a||a==c||b==d)puts("qvq"),exit(233);
    if(B[a][c]||B[b][d]||!B[a][b]||!B[c][d])puts("qwq"),exit(233);
    // for(uint i=0;i<n;i++,putchar('\n'))
    //     for(uint j=0;j<n;j++)putchar("01"[B[i][j]]);
    // printf("%u %u %u %u\n",a+1,b+1,c+1,d+1);
    Ops[0][tp]=a,Ops[1][tp]=b,Ops[2][tp]=c,Ops[3][tp]=d,tp++;
    B[a][c]=B[c][a]=B[b][d]=B[d][b]=true,B[a][b]=B[b][a]=B[c][d]=B[d][c]=false;
}
voi upd4(uint a,uint b,uint c,uint d){if(B[a][b])doit(a,b,d,c);else doit(b,c,a,d);}
uint Now[1000005],Pre[1000005],Nxt[1000005];
voi upd(uint p,uint len)
{
    if(len<4)exit(233);
    if(len==4){upd4(p[Now],p[Nxt][Now],p[Nxt][Nxt][Now],p[Pre][Now]);return;}
    while(p[Now]==p[Nxt][Now]||p[Now]==p[Nxt][Nxt][Now]||p[Now]==p[Pre][Now]
        ||p[Nxt][Now]==p[Nxt][Nxt][Now]||p[Nxt][Now]==p[Pre][Now]||p[Nxt][Nxt][Now]==p[Pre][Now])p=p[Nxt];
    uint a=p[Now],b=p[Nxt][Now],c=p[Nxt][Nxt][Now],d=p[Pre][Now];p[Pre][Nxt]=p[Nxt][Nxt],p[Nxt][Nxt][Pre]=p[Pre];
    if(B[a][b]==B[c][d])upd4(a,b,c,d),upd(p[Pre],len-2);else upd(p[Pre],len-2),upd4(a,b,c,d);
}
int main()
{
#ifdef MYEE
    freopen("QAQ.in","r",stdin);
    freopen("QAQ.out","w",stdout);
#else
#endif
    scanf("%u%u",&n,&m);
    for(uint i=0,u,v;i<m;i++)scanf("%u%u",&u,&v),u--,v--,B[u][v]=B[v][u]=true;
    for(uint i=0,u,v;i<m;i++)scanf("%u%u",&u,&v),u--,v--,B2[u][v]=B2[v][u]=true;
    for(uint i=0;i<n;i++)
    {
        std::vector<uint>X,Y;
        for(uint j=0;j<n;j++)if(B[i][j]!=B2[i][j])(B[i][j]?X:Y).push_back(j);
        if(X.size()!=Y.size())return puts("-1"),0;
        for(uint j=0,a,b;j<X.size();j++)
            a=std::min(i,X[j])*n+std::max(i,X[j]),
            b=std::min(i,Y[j])*n+std::max(i,Y[j]),
            E[Tp[a]++][a]=b,E[Tp[b]++][b]=a;
    }
    // for(uint i=0;i<n*n;i++)if(Tp[i]&&(B[i/n][i%n]==B[E[0][i]/n][E[0][i]%n]||B[i/n][i%n]==B[E[1][i]/n][E[1][i]%n]))
    //     exit(233);
    static uint R[2005];for(uint j=0;j<n*2;j++)R[j]=-1;
    for(uint e=n*n-1;~e;e--)if(Tp[e]&&!G[e])
    {
        std::vector<uint>Q{e},T;
        do G[Q.back()]=true,Q.push_back(E[Q.size()==1||Q[Q.size()-2]==E[0][Q.back()]][Q.back()]);while(Q.back()!=e);
        for(uint i=0;i+1<Q.size();i++)Q[i]=Q[i]/n==Q[i+1]/n||Q[i]/n==Q[i+1]%n?Q[i]/n:Q[i]%n;
        Q.back()=Q[0];
        for(auto q:Q)if(~R[q<<1|(T.size()&1)])
        {
            uint f=R[q<<1|(T.size()&1)];
            uint len=T.size()-f;
            for(uint t=0;t<len;t++)Now[t]=T[t+f],Pre[t]=t?t-1:len-1,Nxt[t]=t==len-1?0:t+1;
            upd(0,len);
            for(uint t=f+1;t<T.size();t++)R[T[t]<<1|(t&1)]=-1;
            T.resize(f+1);
        }
        else R[q<<1|(T.size()&1)]=T.size(),T.push_back(q);
        R[T[0]<<1]=-1;
    }
    // for(uint i=0;i<n;i++)for(uint j=0;j<n;j++)
    //     if(B[i][j]!=B2[i][j])exit(233);
    printf("%u\n",tp);
    for(uint i=0;i<tp;i++)
        printf("%u %u %u %u\n",Ops[0][i]+1,Ops[1][i]+1,Ops[2][i]+1,Ops[3][i]+1);
    // for(uint i=0;i<n;i++,putchar('\n'))
    //     for(uint j=0;j<n;j++)putchar("01"[B[i][j]]);
    // for(uint i=0;i<n;i++,putchar('\n'))
    //     for(uint j=0;j<n;j++)putchar("01"[B2[i][j]]);
    return 0;
}

// 那就是希望。
// 即便需要取模,也是光明。

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 21556kb

input:

4 2
1 2
3 4
1 3
2 4

output:

1
2 1 4 3

result:

ok n=4

Test #2:

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

input:

6 12
1 2
3 5
4 6
1 4
1 5
1 6
2 3
2 5
2 6
3 4
3 6
4 5
1 3
2 4
5 6
1 4
1 5
1 6
2 3
2 5
2 6
3 4
3 6
4 5

output:

2
6 4 5 2
2 1 5 3

result:

ok n=6

Test #3:

score: 0
Accepted
time: 1ms
memory: 5112kb

input:

4 0

output:

0

result:

ok n=4

Test #4:

score: 0
Accepted
time: 1ms
memory: 5128kb

input:

10 0

output:

0

result:

ok n=10

Test #5:

score: 0
Accepted
time: 1ms
memory: 5172kb

input:

100 0

output:

0

result:

ok n=100

Test #6:

score: 0
Accepted
time: 1ms
memory: 5048kb

input:

1000 0

output:

0

result:

ok n=1000

Test #7:

score: 0
Accepted
time: 2ms
memory: 7268kb

input:

4 6
4 1
1 2
1 3
4 3
3 2
4 2
4 1
4 2
4 3
3 2
1 3
1 2

output:

0

result:

ok n=4

Test #8:

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

input:

10 45
7 5
6 1
3 8
9 7
8 1
2 1
7 1
10 9
4 5
6 5
8 6
3 1
5 1
3 6
4 9
6 9
9 1
10 6
4 6
10 2
4 7
4 8
2 5
10 5
3 4
3 7
10 8
8 2
3 10
4 1
4 2
2 9
2 7
8 7
10 1
8 5
6 7
2 6
10 7
9 5
3 9
3 5
8 9
3 2
4 10
3 5
4 6
9 5
7 5
2 9
6 5
4 5
4 1
3 10
8 9
8 6
10 7
3 9
8 2
9 7
8 7
10 8
10 1
2 7
3 6
2 6
3 2
4 2
2 5
10 9
...

output:

0

result:

ok n=10

Test #9:

score: 0
Accepted
time: 1ms
memory: 7096kb

input:

100 4950
15 37
36 56
57 64
66 63
35 70
8 65
25 36
1 27
6 74
79 22
35 34
79 70
53 74
41 63
7 40
41 22
99 93
96 70
35 30
20 67
48 65
100 21
8 4
75 87
80 10
82 38
7 10
85 77
42 77
28 64
73 60
20 74
73 86
24 31
73 44
97 93
8 74
48 19
63 42
41 57
25 79
13 19
96 39
59 44
81 20
66 2
8 37
34 23
88 27
12 14
...

output:

0

result:

ok n=100

Test #10:

score: 0
Accepted
time: 83ms
memory: 8556kb

input:

1000 499500
90 844
735 814
874 452
191 64
745 192
489 653
998 227
104 125
296 644
285 190
831 763
70 776
981 126
213 964
306 137
199 965
849 5
717 70
329 305
196 836
909 527
222 367
323 554
384 900
496 797
620 860
18 823
929 135
589 207
947 354
461 271
22 914
456 403
263 362
908 870
30 384
995 996
3...

output:

0

result:

ok n=1000

Test #11:

score: 0
Accepted
time: 81ms
memory: 8060kb

input:

1000 499500
561 780
496 694
698 721
598 412
55 527
799 952
790 473
980 139
375 308
605 850
670 77
77 908
958 436
379 504
293 452
735 666
223 901
944 455
554 123
644 817
723 68
157 867
527 755
380 937
904 851
614 666
299 131
369 83
61 651
820 239
432 583
588 869
500 542
502 996
305 43
601 882
277 337...

output:

0

result:

ok n=1000

Test #12:

score: 0
Accepted
time: 1ms
memory: 7168kb

input:

4 6
4 3
1 3
2 3
4 2
4 1
2 1
2 3
4 1
4 2
4 3
2 1
1 3

output:

0

result:

ok n=4

Test #13:

score: 0
Accepted
time: 1ms
memory: 7224kb

input:

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

output:

0

result:

ok n=4

Test #14:

score: 0
Accepted
time: 1ms
memory: 7108kb

input:

10 21
2 10
8 4
4 9
10 4
6 10
8 9
3 5
7 9
10 5
2 1
2 8
3 10
6 1
10 7
6 7
4 1
3 4
5 1
8 1
2 5
5 7
3 4
3 9
5 8
2 4
2 5
3 1
10 1
3 5
6 1
6 2
3 6
6 8
3 10
2 9
2 8
3 7
6 7
5 7
2 10
5 4
10 5

output:

-1

result:

ok n=10

Test #15:

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

input:

10 3
2 8
2 10
2 9
2 5
2 6
2 7

output:

-1

result:

ok n=10

Test #16:

score: 0
Accepted
time: 2ms
memory: 7048kb

input:

10 33
2 4
2 6
8 1
5 1
7 1
6 1
6 10
3 6
8 2
3 4
5 10
8 9
7 10
2 10
4 1
3 8
4 10
1 9
4 9
8 10
6 4
2 7
1 10
10 9
2 9
2 1
8 4
6 7
4 7
7 9
5 9
6 9
5 6
4 10
1 9
5 2
6 4
2 1
5 7
7 10
2 7
5 10
8 9
6 9
10 9
7 1
3 6
4 1
2 10
7 9
8 2
2 9
3 2
2 4
6 7
1 10
5 8
4 7
3 9
6 10
3 10
8 10
8 4
6 1
8 6
4 9

output:

-1

result:

ok n=10

Test #17:

score: 0
Accepted
time: 1ms
memory: 7092kb

input:

100 149
97 53
14 62
97 60
14 58
85 69
14 63
97 99
14 71
97 88
85 47
14 61
14 43
97 44
97 17
14 39
85 17
20 99
97 73
85 31
85 67
85 12
14 24
14 69
14 96
97 76
97 95
97 11
85 79
85 19
85 70
85 6
14 56
14 12
85 98
85 53
85 76
85 26
20 37
97 35
97 70
20 96
97 82
97 34
85 94
14 46
97 54
97 43
97 4
85 2
8...

output:

-1

result:

ok n=100

Test #18:

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

input:

100 4631
2 12
66 70
81 62
5 66
94 2
92 64
62 96
58 39
34 3
21 96
52 15
23 67
62 29
38 18
72 56
67 50
81 70
38 42
81 68
99 22
61 42
30 71
32 93
46 95
27 72
97 37
27 2
46 73
65 2
94 22
33 11
64 73
44 5
48 13
65 16
24 44
61 15
34 71
40 1
60 87
100 66
84 33
81 7
14 69
57 83
63 79
23 96
34 15
72 41
47 12...

output:

-1

result:

ok n=100

Test #19:

score: 0
Accepted
time: 46ms
memory: 7932kb

input:

1000 261943
229 141
480 681
189 131
575 202
700 642
405 254
845 739
920 506
838 6
366 32
886 326
124 749
375 702
426 316
843 800
736 845
752 171
744 236
169 313
612 804
675 808
230 804
454 695
617 445
606 481
766 254
140 421
483 155
775 115
617 583
710 417
936 649
329 53
526 979
833 382
464 327
475 ...

output:

-1

result:

ok n=1000

Test #20:

score: 0
Accepted
time: 13ms
memory: 8480kb

input:

1000 48821
306 916
554 937
602 467
778 306
291 993
446 28
561 538
566 718
833 139
857 553
738 128
153 811
350 290
458 146
211 897
158 828
925 574
291 91
530 933
833 387
773 926
554 776
900 41
158 186
877 717
975 113
360 451
375 101
980 364
96 203
492 953
29 280
469 540
153 604
44 911
601 229
469 858...

output:

-1

result:

ok n=1000

Test #21:

score: 0
Accepted
time: 2ms
memory: 7212kb

input:

4 1
4 1
4 1

output:

0

result:

ok n=4

Test #22:

score: 0
Accepted
time: 1ms
memory: 7188kb

input:

6 5
6 3
5 6
2 6
2 3
6 4
6 5
6 4
6 2
2 3
6 3

output:

0

result:

ok n=6

Test #23:

score: 0
Accepted
time: 1ms
memory: 8960kb

input:

6 1
3 1
1 2

output:

-1

result:

ok n=6

Test #24:

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

input:

10 34
7 2
8 10
10 9
6 1
6 5
2 4
6 4
2 5
7 4
2 3
9 4
1 5
6 3
2 1
3 4
4 5
3 5
8 4
7 6
8 1
6 9
10 5
10 4
7 9
3 9
2 9
3 1
1 4
10 6
8 2
8 7
6 2
9 5
1 9
6 2
4 9
4 2
7 8
2 10
4 10
4 8
4 1
2 1
4 7
6 9
6 1
5 8
4 6
1 3
9 7
6 3
9 10
2 5
4 5
6 8
9 5
5 7
2 3
1 10
2 9
4 3
2 8
3 10
1 5
9 1
6 7
6 5
9 3

output:

4
3 5 10 8
8 5 6 7
7 2 6 10
1 8 10 5

result:

ok n=10

Test #25:

score: 0
Accepted
time: 1ms
memory: 21568kb

input:

10 27
10 2
6 4
5 2
5 4
2 7
10 5
1 6
1 9
5 7
3 2
6 9
6 2
8 1
3 7
3 6
8 3
7 9
5 9
5 6
2 9
4 7
6 7
2 4
3 9
10 1
4 9
8 7
6 3
9 4
6 1
2 3
1 10
6 4
2 1
1 8
6 9
3 4
7 5
2 5
5 8
9 8
2 7
6 2
2 9
6 5
7 3
7 10
9 3
9 5
7 4
2 4
6 7
7 9
5 10

output:

3
2 10 8 7
9 1 8 2
8 3 5 4

result:

ok n=10

Test #26:

score: 0
Accepted
time: 1ms
memory: 9088kb

input:

10 12
8 9
8 1
9 3
9 1
9 4
9 5
9 2
9 10
8 7
3 7
9 7
8 6
9 3
7 4
9 8
7 8
9 5
7 3
9 4
7 1
9 1
9 6
9 10
9 7

output:

-1

result:

ok n=10

Test #27:

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

input:

50 952
2 38
10 5
32 33
42 32
40 2
31 33
4 41
47 20
42 13
50 20
1 9
32 41
36 5
11 30
15 23
3 27
17 23
11 25
41 7
31 48
2 9
30 48
35 28
44 36
49 32
45 40
18 45
40 39
47 38
11 39
3 22
6 30
39 46
40 27
15 4
19 13
20 4
21 17
47 7
13 12
44 38
35 15
5 9
44 41
31 14
6 40
50 48
21 49
16 1
44 15
30 5
20 16
41...

output:

98
20 41 28 18
35 41 21 20
45 40 21 35
37 12 29 36
45 29 19 26
44 36 24 37
44 40 20 26
26 40 32 34
45 16 20 44
18 4 9 10
10 2 9 26
8 4 6 18
15 28 12 19
19 10 12 16
16 6 12 10
45 27 34 8
8 27 25 15
46 34 18 10
10 34 15 16
12 20 11 18
26 16 22 35
20 3 15 6
6 12 15 26
18 17 35 10
27 21 11 34
10 21 35 2...

result:

ok n=50

Test #28:

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

input:

50 409
50 22
17 47
45 41
30 9
12 29
15 13
6 14
6 34
6 15
45 25
7 11
17 20
17 23
35 2
24 8
30 22
35 18
31 44
39 38
31 23
37 23
21 10
21 14
35 1
30 17
35 46
11 10
17 39
21 32
1 18
12 5
49 14
46 41
37 4
7 9
1 46
12 9
7 8
35 23
17 1
37 35
49 47
37 48
46 13
36 10
24 17
46 23
15 29
7 1
11 16
31 4
43 25
31...

output:

-1

result:

ok n=50

Test #29:

score: 0
Accepted
time: 1ms
memory: 21524kb

input:

50 869
45 28
16 42
1 34
34 23
39 19
17 48
8 50
2 21
50 4
36 22
46 27
3 27
11 7
24 13
19 33
20 12
37 16
14 28
3 35
3 41
25 34
39 34
15 49
45 34
5 16
19 42
27 28
47 49
39 49
24 49
5 48
27 49
13 32
25 27
3 46
19 26
47 46
20 41
45 16
13 46
8 17
7 32
20 1
11 2
43 28
2 33
4 2
34 19
28 7
15 41
50 16
20 35
...

output:

118
44 36 37 42
47 46 37 44
50 29 30 46
28 47 36 19
50 9 38 13
45 18 36 35
13 9 36 45
24 40 16 30
24 11 28 13
13 11 23 10
38 27 19 12
10 27 23 38
9 43 28 24
9 40 42 13
9 49 23 12
12 43 23 30
8 33 31 9
7 34 20 12
17 30 20 7
9 30 31 17
5 29 36 8
20 40 44 21
10 40 48 20
30 19 48 10
6 19 33 30
7 33 40 4...

result:

ok n=50

Test #30:

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

input:

50 232
5 25
4 11
23 33
44 42
29 10
37 35
8 40
5 45
4 1
8 46
23 13
4 18
4 41
44 25
14 42
19 41
8 10
37 31
4 37
14 45
23 29
24 47
24 36
29 16
24 49
2 46
4 31
29 36
23 39
2 7
29 39
14 27
37 27
8 43
29 32
37 9
4 16
2 22
24 32
29 11
37 26
19 31
44 11
3 17
5 47
2 27
37 12
3 20
19 26
24 9
8 30
3 30
8 34
37...

output:

-1

result:

ok n=50

Test #31:

score: 0
Accepted
time: 2ms
memory: 21648kb

input:

100 3627
14 28
100 63
90 38
28 96
64 4
65 85
46 72
41 44
81 87
27 91
66 5
33 22
21 87
58 20
23 95
93 56
46 62
12 94
39 54
54 42
20 85
28 65
77 40
10 26
72 5
36 18
64 68
17 62
32 72
65 13
36 61
50 20
74 61
77 67
26 63
32 28
22 47
11 86
71 92
58 18
93 46
84 36
92 89
56 47
80 96
94 42
33 31
93 97
20 15...

output:

514
90 94 89 73
100 97 89 90
99 94 91 55
76 87 95 84
55 94 95 76
77 93 91 99
100 93 90 77
88 83 98 75
75 83 77 95
95 90 77 67
79 90 98 72
72 41 55 50
50 27 55 65
33 41 78 72
69 36 78 33
34 36 43 69
79 52 34 60
73 55 36 69
69 34 36 77
59 55 43 73
85 78 43 77
77 78 38 82
84 52 42 69
69 33 42 52
82 52 ...

result:

ok n=100

Test #32:

score: 0
Accepted
time: 1ms
memory: 7236kb

input:

100 430
76 11
76 46
72 19
70 83
76 93
28 94
95 6
72 92
72 20
13 61
28 92
15 84
72 70
13 72
89 49
15 79
76 32
90 60
95 97
13 49
76 35
95 66
76 71
90 85
89 48
90 37
90 79
70 10
76 38
95 83
28 17
90 63
70 98
70 29
90 46
95 100
13 84
13 62
15 82
28 30
90 9
70 7
95 30
72 89
70 34
89 80
95 37
89 51
13 5
9...

output:

-1

result:

ok n=100

Test #33:

score: -100
Runtime Error

input:

100 4106
52 90
31 51
7 15
5 96
24 27
1 40
37 27
53 71
3 96
6 10
94 92
33 17
38 42
31 2
29 14
68 63
84 10
45 93
31 94
66 68
61 94
45 83
37 45
36 14
67 15
80 56
82 39
36 75
18 15
75 89
91 15
83 25
43 8
93 10
51 56
35 40
22 74
81 52
78 16
33 94
87 23
88 41
69 2
16 63
91 6
22 89
28 6
38 40
39 92
61 70
3...

output:

qwq

result: