結果
問題 | No.806 木を道に |
ユーザー | face4 |
提出日時 | 2019-03-22 21:32:46 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 989 bytes |
コンパイル時間 | 1,071 ms |
コンパイル使用メモリ | 86,780 KB |
実行使用メモリ | 9,020 KB |
最終ジャッジ日時 | 2024-09-19 02:52:58 |
合計ジャッジ時間 | 3,005 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:44:19: warning: 'cost' may be used uninitialized [-Wmaybe-uninitialized] 44 | cout << n-1 + cost << endl; | ^~~~ main.cpp:33:9: note: 'cost' was declared here 33 | int cost; | ^~~~ In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:64, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/string:50, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/locale_classes.h:40, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/ios_base.h:41, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ios:42, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/iostream:39, from main.cpp:1: In constructor 'constexpr std::pair<_T1, _T2>::pair(_U1&&, _U2&&) [with _U1 = int&; _U2 = int; typename std::enable_if<(std::_PCC<true, _T1, _T2>::_MoveConstructiblePair<_U1, _U2>() && std::_PCC<true, _T1, _T2>::_ImplicitlyMoveConvertiblePair<_U1, _U2>()), bool>::type <anonymous> = true; _T1 = int; _T2 = int]', inlined from 'int main()' at main.cpp:32:12: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_pair.h:535:11: warning: 't' may be used uninitialized [-Wmaybe-uninitialized] 535 | : first(std::forward<_U1>(__x)), second(std::forward<_U2>(__y)) { } | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ main.cpp: In function 'int main()': main.cpp:19:9: note: 't' was declared here 19 | int t; | ^
ソースコード
#include<iostream> #include<vector> #include<queue> using namespace std; int main(){ int n; cin >> n; vector<int> v[n]; int a, b; for(int i = 0; i < n-1; i++){ cin >> a >> b; a--, b--; v[a].push_back(b); v[b].push_back(a); } vector<bool> visit(n, 0); queue<int> q; int t; q.push(0); while(!q.empty()){ int x = q.front(); q.pop(); if(visit[x]) continue; t = x; visit[x] = true; for(int next : v[x]){ if(!visit[next]) q.push(x); } } visit.resize(n, 0); queue<pair<int,int>> pq; pq.push({t, 0}); int cost; while(!pq.empty()){ auto x = pq.front(); pq.pop(); int i = x.first; if(visit[i]) continue; cost = x.second; visit[i] = true; for(int next : v[i]){ if(!visit[next]) pq.push({next, cost+1}); } } cout << n-1 + cost << endl; return 0; }