제출 #278415

#제출 시각아이디문제언어결과실행 시간메모리
278415test2Network (BOI15_net)C++14
0 / 100
92 ms95708 KiB
#include<bits/stdc++.h> #define I inline void using namespace std ; using ll = long long ; using ld = long double ; const int N = 2e6 + 7 ; // How interesting! int n; vector<int> adj[N] ; vector<pair<int , int> > ans ; vector<int> leafs ; int dfs(int x, int p){ for(auto u : adj[x]){ if(u == p) continue ; dfs(u , x) ; } if(adj[x].size() == 1) leafs.push_back(x) ; } int main(){ ios_base::sync_with_stdio(0) ; cin.tie(0) ; //freopen("in.in", "r" , stdin) ; cin >> n ; for(int i = 0 ;i < n -1 ;i ++){ int u , v; cin >> u >> v ; adj[u].push_back(v) ; adj[v].push_back(u) ; } dfs(1 , 1) ; if(leafs.size() & 1){ cout<< (int) leafs.size() / 2 + 1<<"\n" ; for(int i = 0 ;i < leafs.size() / 2 ; i++){ cout<< leafs[i] <<" " << leafs[i + leafs.size() / 2 + 1] <<"\n" ; } cout<< leafs[leafs.size() / 2] <<" " << 1 <<"\n" ; } else{ cout<< (int) leafs.size() / 2 <<"\n" ; for(int i = 0 ;i < leafs.size() / 2 ; i++){ cout<< leafs[i] <<" " << leafs[i + leafs.size() / 2] <<"\n" ; } } return 0 ; }

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

net.cpp: In function 'int dfs(int, int)':
net.cpp:28:1: warning: no return statement in function returning non-void [-Wreturn-type]
   28 | }
      | ^
net.cpp: In function 'int main()':
net.cpp:48:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |   for(int i = 0 ;i < leafs.size() / 2 ; i++){
      |                  ~~^~~~~~~~~~~~~~~~~~
net.cpp:55:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |   for(int i = 0 ;i < leafs.size() / 2 ; i++){
      |                  ~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...