제출 #95927

#제출 시각아이디문제언어결과실행 시간메모리
95927luciocfNetwork (BOI15_net)C++14
0 / 100
10 ms12152 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5+10; vector<int> grafo[maxn]; int main(void) { int n; cin >> n; for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; grafo[u].push_back(v); grafo[v].push_back(u); } int ans = 0, first; deque<int> leaf; for (int i = 1; i <= n; i++) if (grafo[i].size() == 1) leaf.push_back(i), ans++, first = i; cout << (ans+1)/2 << "\n"; while (leaf.size() > 0) { if (leaf.size() > 1) { cout << leaf.back() << " " << leaf.front() << "\n"; leaf.pop_back(), leaf.pop_front(); } else { cout << leaf.back() << " " << first << "\n"; leaf.pop_back(); } } }

컴파일 시 표준 에러 (stderr) 메시지

net.cpp: In function 'int main()':
net.cpp:40:43: warning: 'first' may be used uninitialized in this function [-Wmaybe-uninitialized]
    cout << leaf.back() << " " << first << "\n";
                                           ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...