Submission #00010
ソースコード
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 41 42 43 44 45 46 47 48 | #include<bits/stdc++.h> using namespace std; #define int long long main(){ int n;cin>>n; vector<vector< int >>s(n+1,vector< int >(0)); for ( int i=0;i<n-1;i++){ int u,v;cin>>u>>v; s[u].push_back(v); s[v].push_back(u); } int num=1; queue< int >q; q.push(1); vector< int >t(n+1,LONG_LONG_MAX); t[1]=0; while (!q.empty()){ int now=q.front(); q.pop(); for ( int i=0;i<s[now].size();i++){ if (t[s[now][i]] > t[now] + 1){ t[s[now][i]] = t[now]+1; q.push(s[now][i]); num=s[now][i]; } } } for ( int i=1;i<=n;i++){ t[i]=LONG_LONG_MAX; } q.push(num); t[num]=0; while (!q.empty()){ int now=q.front(); q.pop(); for ( int i=0;i<s[now].size();i++){ if (t[s[now][i]] > t[now] + 1){ t[s[now][i]] = t[now]+1; q.push(s[now][i]); } } } int ans=0; for ( int i=1;i<=n;i++){ ans=max(ans,t[i]*10); } cout<<ans<< "\n" ; } |
ステータス
項目 | データ |
---|---|
問題 | 0005 - Company Location |
ユーザー名 | ei2326 |
投稿日時 | 2024-08-09 10:15:19 |
言語 | C++17 |
状態 | Accepted |
得点 | 20 |
ソースコード長 | 1136 Byte |
最大実行時間 | 66 ms |
最大メモリ使用量 | 6764 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 20 / 20 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
in1.txt | AC | 26 ms | 476 KB |
1
|
in2.txt | AC | 16 ms | 444 KB |
1
|
in3.txt | AC | 23 ms | 284 KB |
1
|
in4.txt | AC | 19 ms | 380 KB |
1
|
in5.txt | AC | 19 ms | 472 KB |
1
|
in6.txt | AC | 21 ms | 560 KB |
1
|
in7.txt | AC | 26 ms | 1032 KB |
1
|
in8.txt | AC | 29 ms | 1688 KB |
1
|
in9.txt | AC | 66 ms | 6764 KB |
1
|