Submission #849123

#TimeUsernameProblemLanguageResultExecution timeMemory
849123sandry24Network (BOI15_net)C++17
0 / 100
1 ms548 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pi; #define pb push_back #define mp make_pair #define f first #define s second void solve(){ int n; cin >> n; vector<vi> adj(n+5); for(int i = 0; i < n-1; i++){ int a, b; cin >> a >> b; adj[a].pb(b); adj[b].pb(a); } vi leaves; for(int i = 1; i <= n; i++) if(adj[i].size() == 1) leaves.pb(i); cout << ceil((double)leaves.size()/2) << '\n'; for(int i = 1; i < leaves.size(); i += 2) cout << leaves[i-1] << ' ' << leaves[i] << '\n'; if(leaves.size() & 1) cout << leaves[leaves.size()-2] << ' ' << leaves.back() << '\n'; } int main(){ //freopen("flota.in", "r", stdin); //freopen("flota.out", "w", stdout); ios::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; while(t--){ solve(); } }

Compilation message (stderr)

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