UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213585#2769. 覆盖1811260623110027317ms299104kbC++112.2kb2024-11-12 21:18:492024-11-12 23:47:23

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        x = (x << 1) + (x << 3) + (ch ^ 48);
        ch = getchar();
    }
    return x * f;
}
int n, m, u, v, pos, head[4000001];
bool vis[2000001];
struct edge
{
    int u, v, next;
} e[4000001];
void add(int u, int v)
{
    e[++pos] = {u, v, head[u]};
    head[u] = pos;
}
vector<int> ans;
set<int> s[2000001];
void dfs(int u, int fa = -1)
{
    for (int i = head[u]; i; i = e[i].next)
    {
        int v = e[i].v;
        if (v == fa)
            continue;
        dfs(v, u);
        if (s[u].size() > s[v].size())
        {
            for (auto x : s[v])
            {
                auto pos = s[u].find(x);
                if (pos != s[u].end())
                {
                    vis[u] = true;
                }
                else
                {
                    s[u].insert(x);
                }
            }
        }
        else
        {
            for (auto x : s[u])
            {
                auto pos = s[v].find(x);
                if (pos != s[v].end())
                {
                    vis[u] = 1;
                }
                else
                {
                    s[v].insert(x);
                }
            }
            swap(s[u], s[v]);
        }
    }
    if (vis[u])
    {
        ans.push_back(u);
        s[u].clear();
    }
}
signed main()
{
    n = read();
    for (int i = 1; i < n; i++)
    {
        u = read();
        v = read();
        add(u, v);
        add(v, u);
    }
    m = read();
    for (int i = 1; i <= m; i++)
    {
        u = read();
        v = read();
        if (u > v)
            swap(u, v);
        if (u == v)
        {
            vis[u] = true;
        }
        s[u].insert(i);
        s[v].insert(i);
    }
    dfs(1);
    printf("%lld\n", ans.size());
    sort(ans.begin(), ans.end());
    for (auto x : ans)
    {
        printf("%lld ", x);
    }
    return 0;
}

详细

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 30
Accepted

Test #1:

score: 30
Accepted
time: 16ms
memory: 94964kb

input:

20
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 13
17 15
18 16
19 17
20 18
...

output:

2
3 10 

result:

ok ok

Test #2:

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

input:

20
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
20 19
...

output:

2
6 13 

result:

ok ok

Test #3:

score: 0
Accepted
time: 24ms
memory: 94968kb

input:

20
2 1
3 1
4 3
5 1
6 5
7 4
8 7
9 8
10 9
11 10
12 6
13 2
14 7
15 14
16 11
17 12
18 17
19 7
20 15
5
4 ...

output:

3
1 4 11 

result:

ok ok

Test #4:

score: 0
Accepted
time: 24ms
memory: 94968kb

input:

20
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
20 19
...

output:

2
5 11 

result:

ok ok

Test #5:

score: 0
Accepted
time: 20ms
memory: 94968kb

input:

20
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 6
10 8
11 10
12 11
13 11
14 12
15 13
16 9
17 15
18 16
19 16
20 17
1...

output:

6
1 3 7 10 17 19 

result:

ok ok

Test #6:

score: 0
Accepted
time: 15ms
memory: 94968kb

input:

20
2 1
3 2
4 3
5 3
6 5
7 4
8 6
9 8
10 7
11 7
12 10
13 12
14 13
15 9
16 14
17 16
18 16
19 17
20 15
12...

output:

3
4 9 13 

result:

ok ok

Test #7:

score: 0
Accepted
time: 15ms
memory: 94968kb

input:

20
2 1
3 1
4 2
5 3
6 4
7 5
8 6
9 7
10 8
11 9
12 10
13 11
14 10
15 14
16 10
17 13
18 4
19 18
20 4
2
1...

output:

2
5 8 

result:

ok ok

Test #8:

score: 0
Accepted
time: 16ms
memory: 94968kb

input:

20
2 1
3 2
4 3
5 4
6 5
7 4
8 7
9 6
10 9
11 8
12 11
13 10
14 10
15 12
16 14
17 13
18 17
19 14
20 18
4...

output:

2
4 10 

result:

ok ok

Test #9:

score: 0
Accepted
time: 28ms
memory: 94968kb

input:

20
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 8
12 10
13 12
14 8
15 13
16 8
17 8
18 16
19 15
20 11
12
8...

output:

3
3 8 10 

result:

ok ok

Test #10:

score: 0
Accepted
time: 23ms
memory: 94968kb

input:

20
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 7
10 9
11 10
12 8
13 11
14 12
15 13
16 14
17 15
18 16
19 18
20 19
1...

output:

2
7 12 

result:

ok ok

Subtask #2:

score: 30
Accepted

Test #11:

score: 30
Accepted
time: 19ms
memory: 95060kb

input:

1000
2 1
3 2
4 3
5 4
6 3
7 6
8 7
9 8
10 9
11 10
12 5
13 11
14 13
15 14
16 15
17 12
18 16
19 18
20 19...

output:

11
53 131 186 235 258 280 289 317 397 471 585 

result:

ok ok

Test #12:

score: 0
Accepted
time: 12ms
memory: 95068kb

input:

1000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 12
16 14
17 16
18 17
19 18
20 1...

output:

16
96 109 110 114 152 154 179 285 315 418 463 469 526 561 610 822 

result:

ok ok

Test #13:

score: 0
Accepted
time: 12ms
memory: 95036kb

input:

1000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
20 1...

output:

2
40 305 

result:

ok ok

Test #14:

score: 0
Accepted
time: 20ms
memory: 95064kb

input:

1000
2 1
3 2
4 3
5 4
6 4
7 5
8 6
9 7
10 8
11 9
12 11
13 10
14 12
15 14
16 13
17 15
18 16
19 17
20 18...

output:

15
36 77 111 161 164 218 236 277 281 391 408 410 460 577 738 

result:

ok ok

Test #15:

score: 0
Accepted
time: 16ms
memory: 95100kb

input:

1000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
20 1...

output:

17
46 104 126 230 293 313 324 439 460 462 469 504 513 526 546 646 694 

result:

ok ok

Test #16:

score: 0
Accepted
time: 23ms
memory: 95032kb

input:

1000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
20 1...

output:

6
18 114 168 201 311 651 

result:

ok ok

Test #17:

score: 0
Accepted
time: 12ms
memory: 95076kb

input:

1000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 13
16 14
17 16
18 17
19 15
20 1...

output:

16
11 42 68 113 171 249 311 341 361 373 423 450 497 567 586 649 

result:

ok ok

Test #18:

score: 0
Accepted
time: 24ms
memory: 95032kb

input:

1000
2 1
3 2
4 3
5 4
6 5
7 6
8 6
9 8
10 9
11 7
12 11
13 10
14 12
15 13
16 15
17 14
18 15
19 18
20 16...

output:

4
15 167 387 437 

result:

ok ok

Test #19:

score: 0
Accepted
time: 15ms
memory: 95048kb

input:

1000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
20 1...

output:

10
33 158 210 236 363 364 367 372 873 978 

result:

ok ok

Test #20:

score: 0
Accepted
time: 23ms
memory: 95032kb

input:

1000
2 1
3 2
4 3
5 4
6 5
7 6
8 3
9 8
10 9
11 10
12 11
13 7
14 12
15 13
16 7
17 14
18 17
19 15
20 16
...

output:

5
7 85 118 241 307 

result:

ok ok

Subtask #3:

score: 40
Accepted

Test #21:

score: 40
Accepted
time: 685ms
memory: 205336kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 11
15 14
16 13
17 15
18 16
19 17
2...

output:

5
260 10715 16698 23494 49620 

result:

ok ok

Test #22:

score: 0
Accepted
time: 931ms
memory: 205692kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

45
2404 7524 11229 11999 14383 16080 18852 24573 25801 31547 35420 37754 42334 58888 69242 72415 820...

result:

ok ok

Test #23:

score: 0
Accepted
time: 898ms
memory: 218260kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

288
553 5636 9673 9795 15417 22482 28415 29113 30841 31695 36154 36370 41110 45282 46034 47993 48884...

result:

ok ok

Test #24:

score: 0
Accepted
time: 914ms
memory: 211200kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

172
4997 8750 17928 18489 27327 30718 32013 33965 34115 42664 44246 55789 56336 56495 57194 69263 74...

result:

ok ok

Test #25:

score: 0
Accepted
time: 1249ms
memory: 255360kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

635
969 1796 5534 7302 8367 9149 10058 10082 10729 13481 14831 15038 17852 18658 20221 22753 25477 2...

result:

ok ok

Test #26:

score: 0
Accepted
time: 878ms
memory: 205680kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

27
5198 7509 8142 27608 34761 38220 48041 50127 56909 61117 71286 81891 86675 104143 114045 119648 1...

result:

ok ok

Test #27:

score: 0
Accepted
time: 754ms
memory: 205256kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

6
490 3177 5695 8562 34548 83430 

result:

ok ok

Test #28:

score: 0
Accepted
time: 885ms
memory: 213000kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

220
1404 2780 5137 10384 13852 18479 22969 35367 37404 38380 41605 44793 46628 49267 50316 54862 579...

result:

ok ok

Test #29:

score: 0
Accepted
time: 797ms
memory: 205364kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

18
2171 9580 14974 16009 28264 35966 39104 40324 45067 52501 56381 68915 76116 77646 77795 181356 21...

result:

ok ok

Test #30:

score: 0
Accepted
time: 889ms
memory: 205864kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

45
2737 4251 12786 13429 14598 22080 22736 22786 25916 26716 30601 38898 40197 45646 47158 61559 631...

result:

ok ok

Test #31:

score: 0
Accepted
time: 847ms
memory: 205868kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

32
1116 16424 21197 23111 23813 27073 27779 32582 47061 49460 49619 54106 60014 60225 61690 63492 67...

result:

ok ok

Test #32:

score: 0
Accepted
time: 738ms
memory: 205468kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

5
5384 6708 15117 19941 80900 

result:

ok ok

Test #33:

score: 0
Accepted
time: 770ms
memory: 205548kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

11
4421 6325 8344 16347 35897 44930 46860 57419 78545 299866 326571 

result:

ok ok

Test #34:

score: 0
Accepted
time: 729ms
memory: 205268kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

2
5187 7452 

result:

ok ok

Test #35:

score: 0
Accepted
time: 862ms
memory: 211732kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

192
800 3704 4872 12578 14477 19995 22579 25124 29417 31207 32243 34402 42016 44099 44679 45783 4791...

result:

ok ok

Test #36:

score: 0
Accepted
time: 1158ms
memory: 236920kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

489
39 5656 7050 7487 10829 12376 13186 13483 24437 27366 29300 31447 37089 37325 41271 41767 45145 ...

result:

ok ok

Test #37:

score: 0
Accepted
time: 732ms
memory: 205380kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

2
1572 10047 

result:

ok ok

Test #38:

score: 0
Accepted
time: 737ms
memory: 205632kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

6
5177 16799 17244 21899 124227 342086 

result:

ok ok

Test #39:

score: 0
Accepted
time: 764ms
memory: 205612kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

3
9574 37101 114239 

result:

ok ok

Test #40:

score: 0
Accepted
time: 1046ms
memory: 232216kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

434
2752 3375 3689 4991 6053 9618 12539 12689 13788 16278 19244 20277 22749 25323 28033 30314 36310 ...

result:

ok ok

Test #41:

score: 0
Accepted
time: 750ms
memory: 205396kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

3
4025 12701 18588 

result:

ok ok

Test #42:

score: 0
Accepted
time: 941ms
memory: 205932kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

46
1396 4100 10862 12634 18427 21454 23016 23231 23273 30104 38220 53924 55565 63057 75176 78809 795...

result:

ok ok

Test #43:

score: 0
Accepted
time: 905ms
memory: 205708kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

9
7458 12356 16676 19276 29074 30431 45809 48149 71934 

result:

ok ok

Test #44:

score: 0
Accepted
time: 818ms
memory: 205480kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

21
3775 7530 8870 10517 18085 30025 34965 42583 58317 58508 59568 71429 100130 147513 149176 154795 ...

result:

ok ok

Test #45:

score: 0
Accepted
time: 1925ms
memory: 299104kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

902
1097 2377 2384 2850 4587 8343 10511 12075 12386 12906 14030 14419 14466 16460 17707 21340 21375 ...

result:

ok ok

Test #46:

score: 0
Accepted
time: 712ms
memory: 205380kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

1
8442 

result:

ok ok

Test #47:

score: 0
Accepted
time: 895ms
memory: 205424kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

9
5252 6422 19409 22535 24115 36225 56798 215617 409005 

result:

ok ok

Test #48:

score: 0
Accepted
time: 777ms
memory: 205424kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

5
428 7180 7718 16350 48522 

result:

ok ok

Test #49:

score: 0
Accepted
time: 813ms
memory: 205440kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

2
1290 14389 

result:

ok ok

Test #50:

score: 0
Accepted
time: 1150ms
memory: 245344kb

input:

2000000
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
2...

output:

559
945 1241 5644 8082 9005 9959 10848 12448 12793 14252 20587 20906 23833 27004 27886 28406 29166 3...

result:

ok ok

Extra Test:

score: 0
Extra Test Passed