Submission #80340


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include<bits/stdc++.h>
using namespace std;
vector<int>score;
vector<vector<int>>w;
stack<int>dfsST;
void bfs(int x){
queue<int>q;
q.push(x);
while(!q.empty()){
int y = q.front();
q.pop();
for(int i = 0;i < w[y].size();i++){
if(score[w[y][i]] == -1){
score[w[y][i]] = score[y]+1;
q.push(w[y][i]);
}
}
}
}
int main(){
// ifstream ifs("input/in9.txt");
// #define cin ifs
int n;
cin >>n;
score.resize(n,-1);
w.resize(n);
for(int i = 0;i < n-1;i++){
int a,b;
cin >>a>>b;
w[a-1].push_back(b-1);
w[b-1].push_back(a-1);
}
score[0] = 0;
bfs(0);
int x = max_element(score.begin(),score.end())-score.begin();
for(auto&i:score)i = -1;
score[x] = 0;
bfs(x);
cout <<*max_element(score.begin(),score.end())*10<<"\n";
}

ステータス

項目 データ
問題 1826 - Company Location
ユーザー名 ei2332
投稿日時 2024-08-09 05:25:48
言語 C++17
状態 Accepted
得点 20
ソースコード長 795 Byte
最大実行時間 69 ms
最大メモリ使用量 6356 KB

セット

セット 得点 Cases
1 ALL 20 / 20 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
in1.txt AC 32 ms 604 KB
1
in2.txt AC 24 ms 572 KB
1
in3.txt AC 19 ms 416 KB
1
in4.txt AC 15 ms 508 KB
1
in5.txt AC 24 ms 472 KB
1
in6.txt AC 19 ms 564 KB
1
in7.txt AC 26 ms 908 KB
1
in8.txt AC 37 ms 1500 KB
1
in9.txt AC 69 ms 6356 KB
1