QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#34690#4251. Gamejli505#30 2055ms9760kbC++202.5kb2022-06-12 04:51:342024-05-26 00:52:24

Judging History

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

  • [2024-05-26 00:52:24]
  • 评测
  • 测评结果:30
  • 用时:2055ms
  • 内存:9760kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-06-12 04:51:34]
  • 提交

answer

#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#include "game.h"
using namespace std;

void fastIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

int N, M, K;


vector<int> adj[100100];
 
stack<int> S;
 
int cnt = 0;
int dfn[100100], low[100100];
bool in_stack[100100];
int time_in = 0;
int kingdom[100100];

int self_e[100100];

int pre_time_in = 0;
void init(int n, int k){
    N = n;
    K = k;
    for (int i = 0; i < k-1; i++){
        adj[i].push_back(i+1);
    }
}

int kcnt[100100];

void dfs(int node){
    dfn[node] = ++time_in;
    low[node] = dfn[node];
    S.push(node);
    in_stack[node] = true;
    for (int nx : adj[node]){
        if (dfn[nx] <= pre_time_in){
            dfs(nx);
            low[node] = min(low[node], low[nx]);
        } else if (in_stack[nx]){
            low[node] = min(low[node], dfn[nx]);
        }
    }
    if (low[node] == dfn[node]){
        ++cnt;
        while (S.top() != node){
            kcnt[cnt]++;
            kingdom[S.top()] = cnt;
            in_stack[S.top()] = false;
            S.pop();
        }
        kcnt[cnt]++;
        kingdom[S.top()] = cnt;
        in_stack[S.top()] = false;
        S.pop();
    }
}


bool good = false;


int add_teleporter(int u, int v){
    if (good) return true;
    if (u == v){
        self_e[u]++;
    }
    pre_time_in = time_in;
    adj[u].push_back(v);
    cnt = 0;
    for (int i = 0; i < K; i++){
        kingdom[i] = 0;
    }
    while (!S.empty()){
        in_stack[S.top()] = false;
        S.pop();
    }
    /*if (u == 2){
        cout << pre_time_in << "\n";
        for (int i = 0; i < N; i++){
            cout << dfn[i] << " ";
        }
        cout << "\n";
        for (int i = 0; i < N; i++){
            cout << low[i] << " ";
        }
        cout << "\n";
        for (int i = 0; i < N; i++){
            cout << in_stack[i] << " ";
        }
        cout << "\n";
    }*/
    for (int i = 0; i < K; i++){
        if (dfn[i] <= pre_time_in){
            dfs(i);
        }
    }
    /*if (u == 2){
        for (int i = 0; i < N; i++){
            cout << kingdom[i] << " ";
        }
        cout << "\n";
    }*/
    bool work = false;
    for (int i = 0; i < K; i++){
        if (kcnt[kingdom[i]] > 1 || self_e[i]){
            work = true;
            good = true;
        }
    }
    for (int i = 1; i <= cnt; i++) kcnt[i] = 0;
    return work;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 2
Accepted

Test #1:

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

input:

1 1
1
893123 893123
-1

output:

0

result:

ok interaction finished.

Test #2:

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

input:

9 9
29
893122 893124
893121 893127
893120 893124
893123 893121
893122 893131
893125 893131
893121 893126
893123 893126
893126 893131
893123 893131
893123 893125
893123 893124
893127 893125
893120 893126
893123 893120
893121 893131
893123 893127
893122 893126
893122 893127
893127 893131
893122 893125...

output:

28

result:

ok interaction finished.

Test #3:

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

input:

100 100
80
893180 893071
893134 893063
893150 893091
893127 893178
893142 893177
893153 893156
893127 893137
893174 893065
893127 893070
893126 893061
893171 893089
893173 893072
893153 893058
893156 893074
893151 893068
893136 893060
893120 893083
893073 893091
893148 893163
893073 893088
893156 89...

output:

80
80
80
59

result:

ok interaction finished.

Test #4:

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

input:

45 45
80
893143 893167
893122 893132
893123 893140
893120 893139
893158 893167
893154 893163
893133 893137
893133 893142
893135 893137
893121 893135
893137 893149
893141 893152
893122 893167
893128 893145
893140 893167
893122 893127
893134 893142
893122 893129
893141 893156
893146 893149
893123 8931...

output:

80
49

result:

ok interaction finished.

Test #5:

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

input:

100 100
80
893169 893058
893132 893065
893143 893068
893153 893167
893152 893182
893138 893162
893129 893163
893146 893164
893134 893180
893142 893167
893144 893059
893132 893064
893135 893091
893164 893068
893123 893179
893126 893060
893136 893140
893179 893081
893139 893181
893120 893057
893172 89...

output:

80
80
80
42

result:

ok interaction finished.

Test #6:

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

input:

100 100
80
893135 893081
893170 893076
893148 893075
893134 893159
893159 893073
893170 893088
893131 893138
893121 893166
893171 893168
893127 893137
893147 893145
893062 893076
893160 893059
893063 893088
893137 893073
893123 893182
893152 893170
893141 893172
893137 893087
893167 893085
893147 89...

output:

80
80
80
37

result:

ok interaction finished.

Test #7:

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

input:

100 100
80
893062 893075
893139 893156
893137 893083
893071 893075
893072 893080
893141 893060
893126 893179
893064 893081
893167 893077
893139 893165
893056 893085
893169 893182
893062 893087
893141 893078
893062 893078
893129 893176
893065 893077
893141 893181
893152 893158
893151 893078
893157 89...

output:

80
80
80
59

result:

ok interaction finished.

Subtask #2:

score: 10
Accepted

Dependency #1:

100%
Accepted

Test #8:

score: 10
Accepted
time: 1ms
memory: 5804kb

input:

100 10
80
893135 893150
893174 893168
893159 893149
893162 893082
893158 893129
893072 893150
893088 893079
893155 893154
893086 893126
893078 893153
893177 893138
893057 893066
893151 893089
893076 893162
893165 893164
893085 893170
893084 893128
893074 893083
893138 893148
893147 893167
893071 893...

output:

80
31

result:

ok interaction finished.

Test #9:

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

input:

100 10
80
893087 893068
893090 893073
893077 893169
893159 893156
893170 893062
893081 893145
893076 893083
893128 893078
893132 893139
893181 893165
893155 893167
893167 893089
893065 893081
893068 893180
893150 893175
893066 893183
893060 893133
893086 893060
893072 893142
893084 893132
893151 893...

output:

80
10

result:

ok interaction finished.

Test #10:

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

input:

100 10
80
893136 893078
893085 893075
893173 893143
893132 893066
893066 893074
893149 893080
893152 893148
893179 893146
893174 893137
893082 893077
893140 893082
893080 893134
893171 893149
893070 893161
893087 893132
893168 893059
893086 893085
893159 893153
893143 893173
893167 893140
893062 893...

output:

80
25

result:

ok interaction finished.

Test #11:

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

input:

100 50
80
893180 893088
893174 893057
893168 893177
893080 893064
893061 893060
893086 893065
893169 893168
893182 893069
893079 893068
893177 893089
893064 893176
893175 893084
893068 893072
893076 893063
893071 893087
893074 893078
893070 893082
893090 893179
893179 893182
893063 893071
893173 893...

output:

80
19

result:

ok interaction finished.

Test #12:

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

input:

100 25
80
893065 893138
893153 893124
893163 893132
893121 893173
893170 893183
893128 893162
893063 893084
893174 893128
893163 893124
893148 893127
893127 893167
893146 893153
893157 893152
893077 893154
893067 893135
893174 893146
893156 893058
893120 893066
893151 893128
893087 893139
893144 893...

output:

80
80
80
14

result:

ok interaction finished.

Test #13:

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

input:

100 10
80
893171 893168
893173 893067
893132 893173
893060 893178
893062 893064
893077 893171
893135 893081
893089 893134
893091 893064
893086 893156
893173 893181
893133 893071
893070 893076
893154 893069
893172 893182
893138 893091
893151 893149
893162 893085
893132 893136
893125 893083
893173 893...

output:

80
80
80
13

result:

ok interaction finished.

Test #14:

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

input:

100 50
80
893171 893179
893169 893074
893139 893091
893159 893168
893078 893171
893162 893064
893080 893174
893125 893067
893156 893087
893152 893061
893063 893183
893069 893170
893086 893170
893154 893181
893069 893090
893131 893069
893075 893164
893088 893171
893131 893066
893154 893083
893153 893...

output:

80
80
80
9

result:

ok interaction finished.

Test #15:

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

input:

100 48
80
893089 893176
893085 893129
893129 893176
893083 893129
893141 893061
893083 893064
893166 893176
893064 893073
893141 893176
893085 893141
893085 893083
893061 893089
893073 893061
893129 893089
893129 893061
893141 893089
893073 893166
893083 893141
893166 893061
893083 893166
893129 893...

output:

80
68

result:

ok interaction finished.

Test #16:

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

input:

100 48
80
893168 893085
893072 893083
893072 893148
893145 893168
893083 893087
893145 893080
893085 893080
893182 893165
893182 893072
893182 893145
893087 893168
893145 893083
893148 893168
893165 893168
893072 893145
893072 893165
893182 893148
893165 893085
893148 893085
893145 893085
893165 893...

output:

80
80
13

result:

ok interaction finished.

Subtask #3:

score: 18
Accepted

Dependency #2:

100%
Accepted

Test #17:

score: 18
Accepted
time: 2ms
memory: 5852kb

input:

1000 10
80
893932 893218
893380 893370
893280 893263
893162 893561
893846 893370
893391 893342
893351 893619
893565 893342
893487 893723
893463 893114
893799 893840
893116 893441
893210 893715
893586 893630
893612 893924
893414 893035
893390 893253
893141 893115
893485 893520
893924 893878
893292 89...

output:

80
80
80
80
80
80
80
80
80
80
80
80
1

result:

ok interaction finished.

Test #18:

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

input:

1000 100
80
893512 892972
893438 893564
893648 893457
893558 893935
893376 893054
893861 893423
893145 893474
893644 893946
893336 893172
893850 893616
893261 893785
893760 893528
893373 893292
893465 893705
893048 893365
893330 893083
893594 893296
893279 893125
893188 893313
893536 893453
893668 8...

output:

80
56

result:

ok interaction finished.

Test #19:

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

input:

1000 100
80
893640 893021
893621 893584
892987 893336
893472 892977
893543 893228
893314 893623
893549 893545
893618 892972
893241 893381
893339 893277
893423 893676
893787 893947
893412 893867
893526 893881
892954 893865
893779 893945
893204 893474
893229 893295
893397 893600
893284 893829
893890 8...

output:

80
80
80
80
80
80
80
80
80
80
80
20

result:

ok interaction finished.

Test #20:

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

input:

1000 10
80
893630 893661
893243 893498
893009 893765
893016 893444
893442 893486
893037 893282
893800 893364
893482 893573
893083 893631
893680 893845
892952 893465
893061 893075
893838 893376
893452 893546
892990 893508
893114 892973
892991 893401
893404 893301
893086 893936
893257 892992
893820 89...

output:

80
80
80
80
80
80
80
80
80
80
80
80
80
15

result:

ok interaction finished.

Test #21:

score: 0
Accepted
time: 14ms
memory: 5996kb

input:

1000 500
80
893666 893929
893585 893608
893889 893683
893864 893568
893874 893523
893903 893487
893618 893794
893829 893804
893594 893482
893673 893497
893523 893878
893447 893527
893590 893853
893777 893514
893550 893237
893897 893540
893775 893778
893799 893622
893627 893621
893598 893530
893558 8...

output:

80
80
80
80
80
80
80
80
80
80
80
80
39

result:

ok interaction finished.

Test #22:

score: 0
Accepted
time: 38ms
memory: 5976kb

input:

1000 250
80
893027 893523
893258 893080
893847 893524
893720 893942
893660 893559
893031 893609
893219 892986
893616 893689
893286 893014
893184 893029
893833 893857
892978 893795
893434 893676
893789 892942
892952 893880
893705 893611
893075 893267
892948 893313
893150 893708
893030 893778
892929 8...

output:

80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
60

result:

ok interaction finished.

Test #23:

score: 0
Accepted
time: 36ms
memory: 6132kb

input:

1000 100
80
893395 892948
893103 893673
893689 893615
892957 893475
893685 893445
892965 892951
892954 893469
893566 893605
893591 893865
893712 893584
893072 893453
893681 893490
893594 893206
893724 893481
892962 893647
893581 893832
893825 893010
893326 892940
893205 893665
893230 893462
893949 8...

output:

80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
3

result:

ok interaction finished.

Test #24:

score: 0
Accepted
time: 54ms
memory: 5860kb

input:

1000 500
80
893592 893233
893222 893809
893786 893543
893661 893233
893362 893896
893432 893822
893603 893232
893830 893816
893894 893233
893782 893232
893935 893232
893445 893232
893875 893234
893331 893790
893716 893574
892964 893646
893677 893234
893460 893593
893037 893494
893500 893233
893012 8...

output:

80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
32

result:

ok interaction finished.

Test #25:

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

input:

1000 480
80
893401 893764
893787 893211
893240 893127
893880 892971
893522 892984
893522 893015
893449 893401
893149 893224
893331 893784
893534 893063
893880 893120
893050 893928
893652 893023
893354 893594
893120 893870
893127 893790
893570 893182
892984 893629
893652 893182
893345 893447
893354 8...

output:

80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
69

result:

ok interaction finished.

Test #26:

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

input:

1000 480
80
893907 893272
893478 893293
893886 892998
893490 893573
893038 893623
893781 892951
892940 893891
893834 893070
892964 893629
892940 893867
893437 893685
892950 893925
893572 892990
892950 893490
893454 893538
893907 893293
893489 893293
893591 893712
893908 893679
893336 893588
893781 8...

output:

80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
8

result:

ok interaction finished.

Subtask #4:

score: 0
Time Limit Exceeded

Dependency #3:

100%
Accepted

Test #27:

score: 30
Accepted
time: 126ms
memory: 6472kb

input:

30000 100
80
899506 888816
888591 894413
902184 906369
904197 896104
889550 895990
916079 915763
885883 899331
887259 885983
898484 887782
891896 904753
910535 893719
910133 891961
899807 898437
916401 895311
891348 887333
887544 916670
899351 905356
893259 915304
893328 903480
894439 897409
911242 ...

output:

80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
...

result:

ok interaction finished.

Test #28:

score: 0
Accepted
time: 140ms
memory: 6416kb

input:

30000 1000
80
888463 913925
892100 897945
913578 901104
890521 899049
895263 894452
913292 909544
905183 917349
885960 885393
889726 899618
910824 913325
901155 896320
885429 898265
900308 910523
904946 887937
886762 892781
888918 916215
886099 889793
885317 917406
892733 917151
893037 898842
896378...

output:

80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
26

result:

ok interaction finished.

Test #29:

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

input:

30000 100
80
894521 909917
901995 912849
884977 917008
903366 905126
898211 902083
902834 896589
892563 903508
912525 897850
911679 901575
905919 897511
911480 909868
903623 897534
917191 888463
891138 891245
899943 897287
910082 891188
909593 890450
889548 885321
910460 905329
893972 889385
886431 ...

output:

80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
...

result:

ok interaction finished.

Test #30:

score: 0
Accepted
time: 19ms
memory: 7304kb

input:

30000 10
80
903385 897892
901499 897416
901684 888817
896553 889043
911436 891926
900347 888717
900444 913858
892209 906168
913793 911944
896231 905276
897882 911886
914209 916881
896877 889975
901214 912595
897884 896669
903532 885001
911544 916543
914413 888441
893885 915363
894985 913964
892328 9...

output:

80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
...

result:

ok interaction finished.

Test #31:

score: 0
Accepted
time: 2055ms
memory: 9760kb

input:

30000 1000
80
890517 916773
914690 905354
886694 897246
898826 904179
911030 917195
887996 898617
898053 909920
917009 895972
903355 910504
915250 886913
895885 910418
902854 904356
910687 909634
887159 904371
915737 891190
895082 888447
916943 906351
916836 885068
888219 915392
910073 888168
900294...

output:

80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
...

result:

ok interaction finished.

Test #32:

score: -30
Time Limit Exceeded

input:

30000 1000
80
897191 890469
906065 892509
885193 894316
885157 889260
912943 904052
916930 909659
914728 884742
896488 895555
902178 906152
911233 893445
914592 903728
892220 893410
902970 916889
893575 913577
888565 913378
909744 886927
890859 906250
890485 892591
903043 888565
898326 910029
889181...

output:

80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
...

result:


Subtask #5:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

0%