659277 386183
1 2
1 3
1 17
1 34
1 311
1 347
1 539
1 1138
1 1472
1 3361
1 7475
1 10600
1 24431
1 3881
<18857310 bytes omitted>
用户输出
626296
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#64299 | #1298. 寻找终点 | Accepted | 100 | 3393 ms | 28988 K | C++ / 1.2 K | JackHanna | 2022-03-23 0:24:24 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n = 0, s = 0;
cin >> n >> s;
s = s - 1;
vector<vector<int> > tree; //邻接表
vector<bool> judge; //走过就是1 没走过就是0
for (int i = 0; i < n; i++) {
vector<int> temp;
tree.push_back(temp);
judge.push_back(false);
}
for (int i = 0; i < n - 1; i++) {
int a = 0, b = 0;
cin >> a >> b;
tree.at(a - 1).push_back(b - 1);
tree.at(b - 1).push_back(a - 1);
}
while (true) {
bool isleaf = true;
vector<int> unvisited;
for (vector<int>::iterator iter = tree.at(s).begin(); iter != tree.at(s).end(); iter++) {
if (judge.at(*iter) == false) {
isleaf = false;
unvisited.push_back(*iter);
}
}
if (isleaf) {
break;
}
judge.at(s) = true;
//应当去到没被探索过的最小元素那里
s = *min_element(unvisited.begin(), unvisited.end());
}
cout << s + 1 << endl;
}
659277 386183
1 2
1 3
1 17
1 34
1 311
1 347
1 539
1 1138
1 1472
1 3361
1 7475
1 10600
1 24431
1 3881
<18857310 bytes omitted>
用户输出
626296
系统信息
Exited with return code 0
256069 235113
1 2
1 3
1 4
1 6
1 10
1 11
1 13
1 34
1 46
1 82
1 115
1 534
1 789
1 1007
2 9
2 456
2 836
<6972062 bytes omitted>
用户输出
186089
系统信息
Exited with return code 0
577392 319668
1 2
1 3
1 7
1 55
1 1360
1 256588
1 323239
1 460008
2 4
2 16
2 24
2 225
2 10553
2 18482
<16431146 bytes omitted>
用户输出
37589
系统信息
Exited with return code 0
881921 4297
1 2
1 5
1 101
1 992
1 2378
1 23833
1 57369
1 62249
1 164836
1 342354
1 634202
2 3
2 4
2
<25472882 bytes omitted>
用户输出
436278
系统信息
Exited with return code 0
690116 401010
1 2
1 3
1 4
1 10
1 14
1 46
1 87
1 159
1 447
1 511
1 523
1 699
1 2025
1 9648
1 12980
1
<19772222 bytes omitted>
用户输出
656490
系统信息
Exited with return code 0
179327 251
1 2
1 3
1 5
1 17
1 70
1 90
1 112
1 1553
1 1775
1 1928
1 2180
1 6766
1 7623
1 67044
1 1279
<4749045 bytes omitted>
用户输出
103582
系统信息
Exited with return code 0
71567 57797
1 2
1 3
1 4
1 24
1 85
1 96
1 106
1 209
1 548
1 11245
1 37632
1 64950
1 67341
2 5
2 6
2 1
<1766792 bytes omitted>
用户输出
5621
系统信息
Exited with return code 0
479057 240031
1 2
1 4
1 14
1 29
1 170
1 326
1 3811
1 6465
1 7184
1 27831
1 36571
1 63687
1 135286
1
<13521216 bytes omitted>
用户输出
313414
系统信息
Exited with return code 0
100481 81388
1 2
1 3
1 6
1 13
1 15
1 29
1 362
1 462
1 1030
1 1454
1 2979
1 5473
1 7570
1 96038
2 4
2
<2512053 bytes omitted>
用户输出
26359
系统信息
Exited with return code 0
438544 368826
1 2
1 21
1 75
1 413
1 993
1 1922
1 31917
1 48275
1 160089
2 3
2 5
2 6
2 19
2 23
2 115
<12326052 bytes omitted>
用户输出
220367
系统信息
Exited with return code 0