QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#127586#6634. Central SubsetshielderWA 104ms23912kbC++201.4kb2023-07-19 20:02:252023-07-19 20:02:43

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-19 20:02:43]
  • 评测
  • 测评结果:WA
  • 用时:104ms
  • 内存:23912kb
  • [2023-07-19 20:02:25]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 5e5+10;
vector<int> e[N];
vector<int> ans;
int dis[N];
int n, m, k;
int x ,y;
bool vis[N];
bool bfs(int x){
     for(int i = 1;i <= n;i++) vis[i] = 0;
     queue<int> q;
     dis[x] = 0;
     vis[x] = 1;
     q.push(x);
     ans.clear();
    while(!q.empty()){
        int u = q.front();
        q.pop();
        for(auto y : e[u]){
            if(vis[y]) continue;
            vis[y] = 1;
            dis[y] = dis[u] + 1;
            q.push(y);
        }
    }
    for(int i = 1;i <= n;i++){
        if(dis[i]%(k+1) == 1){
            ans.push_back(i);
        }
    }
    //if(ans.size() == 0)Q ans.push_back(1);
    if(ans.size()  <= k)
    return 1;
    return 0;
}
int main(){
    int tt;
    cin >> tt;
    while(tt--){
        cin >> n >>m;
        ans.clear();
        for(int i = 0;i <= n;i++){
                e[i].clear();
            vis[i] = 0;
            dis[i] = 0;
        }
        k = ceil(sqrt(n));
        for(int i = 1;i <= m;i++){
            cin >> x >> y;
            e[x].push_back(y);
            e[y].push_back(x);
        }
        for(int i = 1; i<= n;i++){
         bool f = bfs(i);
         if(f){
        cout << ans.size() << "\n";
        for(auto x : ans){
            cout << x << " ";
        }
        cout << "\n";
        break;
        }
        }
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 16368kb

input:

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

output:

1
2 
3
2 3 4 

result:

ok correct (2 test cases)

Test #2:

score: 0
Accepted
time: 11ms
memory: 16856kb

input:

10000
15 14
13 12
5 4
9 8
11 12
15 14
10 9
14 13
2 3
2 1
6 5
10 11
3 4
7 6
8 7
6 5
2 1
2 4
4 6
2 3
3 5
10 9
8 3
9 4
5 6
5 10
3 2
5 4
2 7
1 2
4 3
2 1
2 1
2 1
2 1
9 8
9 8
5 4
1 2
6 5
3 4
3 2
7 8
7 6
2 1
1 2
14 13
3 10
5 6
2 9
11 4
2 3
2 1
8 7
13 6
5 4
5 12
6 7
4 3
7 14
16 15
2 3
2 1
6 10
6 9
6 4
9 11
...

output:

3
2 7 12 
1
2 
1
2 
1
2 
1
2 
2
2 6 
1
2 
3
2 7 13 
3
2 11 12 
1
2 
4
2 8 14 20 
2
2 8 
1
2 
3
2 14 15 
1
2 
3
2 7 12 
1
2 
1
2 
1
2 
1
2 
1
2 
2
2 8 
3
2 7 13 
4
2 15 16 17 
1
2 
3
2 7 12 
1
2 
3
2 7 14 
1
2 
1
2 
4
2 8 14 20 
1
2 
3
2 7 13 
4
2 12 13 14 
1
2 
2
2 6 
1
2 
3
2 7 12 
3
2 11 12 
1
2 
...

result:

ok correct (10000 test cases)

Test #3:

score: 0
Accepted
time: 61ms
memory: 16428kb

input:

100
2000 1999
529 528
885 884
1221 1222
375 374
245 244
758 757
711 710
1521 1522
1875 1874
749 750
823 822
1959 1958
1767 1766
155 154
631 632
825 824
1330 1331
457 456
1344 1343
1817 1818
413 414
582 583
1828 1827
1335 1336
654 655
162 161
1668 1667
1966 1967
1472 1471
1185 1184
518 517
1509 1510
...

output:

44
2 48 94 140 186 232 278 324 370 416 462 508 554 600 646 692 738 784 830 876 922 968 1014 1060 1106 1152 1198 1244 1290 1336 1382 1428 1474 1520 1566 1612 1658 1704 1750 1796 1842 1888 1934 1980 
1
2 
43
2 48 94 140 186 232 278 324 370 416 462 508 554 600 646 692 738 784 830 876 922 968 1047 1093 ...

result:

ok correct (100 test cases)

Test #4:

score: 0
Accepted
time: 52ms
memory: 17684kb

input:

10
14914 14913
13959 13958
3643 3642
4582 4581
13378 13379
981 980
12901 12902
12355 12356
14692 14691
9670 9669
14632 14631
1441 1440
1367 1368
6237 6238
8297 8298
1021 1020
5096 5097
4773 4774
7778 7779
3013 3014
5536 5535
11621 11620
13904 13903
3050 3049
14179 14178
7471 7472
13380 13381
7403 74...

output:

121
2 126 250 374 498 622 746 870 994 1118 1242 1366 1490 1614 1738 1862 1986 2110 2234 2358 2482 2606 2730 2854 2978 3102 3226 3350 3474 3598 3722 3846 3970 4094 4218 4342 4466 4590 4714 4838 4962 5086 5210 5334 5458 5582 5706 5830 5954 6078 6202 6326 6450 6574 6698 6822 6946 7070 7194 7318 7442 75...

result:

ok correct (10 test cases)

Test #5:

score: 0
Accepted
time: 104ms
memory: 18284kb

input:

10
20000 19999
6831 6760
15763 15900
10362 10184
5821 5880
17555 17389
16708 16574
11592 11436
186 209
19380 19313
8867 8718
12100 12237
16245 16110
18464 18568
4713 4665
17412 17578
18666 18750
4360 4322
12350 12502
4054 4103
2874 2849
8097 8202
14489 14639
1056 1016
13500 13581
2435 2391
199 173
8...

output:

138
2 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 18585 18586 18587 18588 18589 18590 18591 18592 18593 18594 18595 185...

result:

ok correct (10 test cases)

Test #6:

score: 0
Accepted
time: 80ms
memory: 23912kb

input:

1
200000 199999
136649 136648
44943 44944
7148 7149
50332 50333
149967 149966
28976 28975
78549 78550
178698 178697
96434 96433
7859 7858
88976 88977
23348 23347
161682 161681
125393 125392
67892 67893
73592 73593
179054 179055
110841 110842
163714 163715
7982 7981
56309 56310
196486 196485
19176 19...

output:

446
2 451 900 1349 1798 2247 2696 3145 3594 4043 4492 4941 5390 5839 6288 6737 7186 7635 8084 8533 8982 9431 9880 10329 10778 11227 11676 12125 12574 13023 13472 13921 14370 14819 15268 15717 16166 16615 17064 17513 17962 18411 18860 19309 19758 20207 20656 21105 21554 22003 22452 22901 23350 23799 ...

result:

ok correct (1 test case)

Test #7:

score: 0
Accepted
time: 99ms
memory: 23588kb

input:

1
200000 199999
58280 58281
132016 32016
45157 45158
35446 35445
158979 58979
185831 85831
74289 174289
195645 95645
31857 131857
168766 68766
95607 95606
39817 39818
58215 158215
74893 74894
18897 118897
63013 163013
58501 58502
94475 194475
77574 77573
152977 52977
3731 103731
20407 20408
186570 8...

output:

445
2 451 900 1349 1798 2247 2696 3145 3594 4043 4492 4941 5390 5839 6288 6737 7186 7635 8084 8533 8982 9431 9880 10329 10778 11227 11676 12125 12574 13023 13472 13921 14370 14819 15268 15717 16166 16615 17064 17513 17962 18411 18860 19309 19758 20207 20656 21105 21554 22003 22452 22901 23350 23799 ...

result:

ok correct (1 test case)

Test #8:

score: 0
Accepted
time: 94ms
memory: 23312kb

input:

1
200000 199999
84088 84001
74829 74679
40726 41179
113019 113238
112813 113025
77336 77177
60908 61208
4521 4639
144249 144094
102763 102692
112856 113070
2428 2356
114005 113754
168454 168270
114538 114311
36802 36341
170182 170306
31641 32012
92503 92395
143570 143702
6871 6715
51503 51997
140883...

output:

416
2 86770 86771 86772 86773 86774 86775 86776 86777 86778 86779 86780 86781 86782 86783 86784 86785 86786 86787 86788 86789 86790 86791 86792 86793 86794 86795 86796 86797 86798 86799 86800 86801 86802 86803 86804 86805 86806 86807 86808 86809 86810 86811 86812 86813 86814 86815 86816 86817 86818 ...

result:

ok correct (1 test case)

Test #9:

score: -100
Wrong Answer
time: 18ms
memory: 16692kb

input:

1000
11 19
8 11
4 11
2 11
2 3
8 3
6 1
6 4
11 5
5 3
10 8
7 10
4 7
3 9
5 1
5 7
3 6
10 1
11 7
2 9
70 109
32 69
26 15
65 46
70 62
50 23
17 16
15 31
2 23
18 11
48 57
19 29
52 42
26 31
7 1
53 66
5 69
58 20
59 38
3 4
9 53
7 56
52 66
66 28
22 51
2 6
22 35
5 28
25 51
27 13
26 56
10 50
53 56
60 48
67 33
61 23...

output:

3
5 6 10 
5
7 16 33 34 36 
3
5 16 25 
3
54 57 90 
4
9 12 13 16 
4
2 8 9 15 
5
9 14 16 18 31 
6
4 8 12 17 31 41 
3
42 50 53 
3
40 66 67 
3
5 12 18 
10
25 34 53 55 57 60 61 85 87 90 
2
15 33 
3
10 12 47 
1
16 
1
12 
2
3 4 
1
41 
5
7 18 43 44 50 
3
11 14 16 
4
11 16 18 24 
4
16 18 19 24 
2
5 84 
7
2 29...

result:

wrong answer Integer 15 violates the range [1, 4] (test case 13)