제출 #394759

#제출 시각아이디문제언어결과실행 시간메모리
394759SaynaaNetwork (BOI15_net)C++14
100 / 100
496 ms41040 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 5e5 + 10; int n; vector< int > adj[MAXN], ls; void dfs(int u, int p = -1){ if( adj[u].size() == 1) ls.push_back(u); for(int i = 0; i < adj[u].size(); i ++){ int v = adj[u][i]; if( v == p) continue; dfs(v, u); } } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n; for(int i = 1; i < n; i ++){ int u, v; cin >> u >> v, u --, v --; adj[u].push_back(v), adj[v].push_back(u); } dfs(0); cout << (ls.size() + 1)/2 << '\n'; // int pt = 0; for(int i = 0; i + ls.size()/2 < ls.size(); i ++){ cout << ls[i] + 1 << " " << ls[i + ls.size()/2] + 1 << '\n'; //pt = i; } //if( ls.size() % 2) return 0; }

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

net.cpp: In function 'void dfs(int, int)':
net.cpp:10:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  for(int i = 0; i < adj[u].size(); i ++){
      |                 ~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...