Submission #639380

#TimeUsernameProblemLanguageResultExecution timeMemory
6393803omar_ahmedNetwork (BOI15_net)C++17
100 / 100
418 ms48496 KiB
/** * author: 3omar_ahmed * date: 09-09-2022 * Expert When :) */ #include <bits/stdc++.h> using namespace std ; #define int long long #define endl '\n' #define all(a) a.begin() , a.end() #define alr(a) a.rbegin() , a.rend() int n ; vector < vector < int >> adj(500001); vector < int > a; void dfs(int node , int par){ if(adj[node].size() == 1){ a.push_back(node); } for(auto i : adj[node]){ if(i == par) continue ; dfs(i , node); } } signed 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; adj[u].push_back(v); adj[v].push_back(u); } dfs(1 , 0); // for(auto i : a) cout << i << ' '; // cout << endl; cout << ((int)(a.size()) + 1) / 2 << endl; for(int i = 0 ; i < a.size() / 2 ; i ++){ cout << a[i] << ' ' << a[((int)(a.size()) + 1) / 2 + i] << endl; } if((int)(a.size()) % 2 == 0) return 0; int val = a[a.size() / 2]; set < int > s ; for(int i = 1 ; i <= n ; i++){ if(count(all(adj[val]),i)) continue ; val = i ; break ; } cout << a[a.size() / 2] << ' ' << val << endl; return 0 ; }

Compilation message (stderr)

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