제출 #546669

#제출 시각아이디문제언어결과실행 시간메모리
546669JomnoiNetwork (BOI15_net)C++17
100 / 100
401 ms47676 KiB
#include <bits/stdc++.h> #define DEBUG 0 using namespace std; const int N = 5e5 + 10; vector <int> adj[N]; vector <int> leaf; void dfs(int u, int p) { if(adj[u].size() == 1) { leaf.push_back(u); } for(auto v : adj[u]) { if(v != p) { dfs(v, u); } } } int main() { cin.tie(0)->sync_with_stdio(0); int n; cin >> n; for(int i = 1; i <= n - 1; i++) { int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } for(int i = 1; i <= n; i++) { if(adj[i].size() > 1) { dfs(1, -1); break; } } cout << (leaf.size() + 1) / 2 << '\n'; for(int i = 0; i < (leaf.size() + 1) / 2; i++) { cout << leaf[i] << ' ' << leaf[leaf.size() / 2 + i] << '\n'; } return 0; }

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

net.cpp: In function 'int main()':
net.cpp:40:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i = 0; i < (leaf.size() + 1) / 2; i++) {
      |                    ~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...