编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#12391 #51. 「2021 新生杯」成大环 Accepted 100 77 ms 1860 K C++ 17 / 503 B woruo 2023-12-06 23:52:23
显示原始代码
#include <iostream>

using namespace std;

int n;
int adj[100005][2];
int to[100005][2];

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x, y;
        cin >> x >> y;
        adj[x][adj[x][0] != 0] = to[x][to[x][0] != 0] = y;
        adj[y][adj[y][0] != 0] = x;
    }
    int x = 1, y = adj[1][0], ans = to[1][0] == y || to[1][1] == y;
    for (; y != 1; ans += to[x][0] == y || to[x][1] == y) {
        swap(x, y);
        y ^= adj[x][0] ^ adj[x][1];
    }
    cout << min(ans, n - ans) << '\n';
    return 0;
}
子任务 #1
Accepted
得分:100
测试点 #1
Accepted
得分:100
用时:3 ms
内存:248 KiB

输入文件(1.in

5
1 5
3 4
2 1
5 4
2 3

答案文件(1.ans

2

用户输出

2

系统信息

Exited with return code 0
测试点 #2
Accepted
得分:100
用时:3 ms
内存:364 KiB

输入文件(2.in

3
1 2
3 1
2 3

答案文件(2.ans

0

用户输出

0

系统信息

Exited with return code 0
测试点 #3
Accepted
得分:100
用时:3 ms
内存:324 KiB

输入文件(3.in

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

答案文件(3.ans

5

用户输出

5

系统信息

Exited with return code 0
测试点 #4
Accepted
得分:100
用时:3 ms
内存:364 KiB

输入文件(4.in

100
98 52
63 52
63 2
2 18
96 18
96 31
31 58
58 84
40 84
40 41
41 45
66 45
66 100
46 100
71 46
26 71

<488 bytes omitted>

答案文件(4.ans

40

用户输出

40

系统信息

Exited with return code 0
测试点 #5
Accepted
得分:100
用时:3 ms
内存:304 KiB

输入文件(5.in

1000
123 288
721 288
19 721
19 450
669 450
669 251
321 251
321 897
897 417
417 403
455 403
455 746
7
<7691 bytes omitted>

答案文件(5.ans

488

用户输出

488

系统信息

Exited with return code 0
测试点 #6
Accepted
得分:100
用时:7 ms
内存:464 KiB

输入文件(6.in

10000
5537 3905
5537 2138
2138 6193
6193 1368
1368 6237
6237 7641
7641 2323
6717 2323
6717 4239
4239
<97694 bytes omitted>

答案文件(6.ans

4971

用户输出

4971

系统信息

Exited with return code 0
测试点 #7
Accepted
得分:100
用时:55 ms
内存:1860 KiB

输入文件(7.in

100000
56449 21738
21738 74917
44834 74917
36187 44834
36187 96576
37204 96576
28451 37204
28451 344
<1177697 bytes omitted>

答案文件(7.ans

49892

用户输出

49892

系统信息

Exited with return code 0