Submission #823021

#TimeUsernameProblemLanguageResultExecution timeMemory
823021serifefedartarNetwork (BOI15_net)C++17
100 / 100
371 ms47664 KiB
#include <bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(0);cin.tie(0); typedef long long ll; #define f first #define s second #define MOD 1000000009 #define LOGN 20 #define MAXN 2000100 vector<vector<int>> graph; vector<int> leaves; void dfs(int node, int parent) { if (graph[node].size() == 1) leaves.push_back(node); for (auto u : graph[node]) { if (u == parent) continue; dfs(u, node); } } int main() { fast int n, u, v; cin >> n; graph = vector<vector<int>>(n+1, vector<int>()); for (int i = 1; i < n; i++) { cin >> u >> v; graph[u].push_back(v); graph[v].push_back(u); } dfs(1, 1); cout << (leaves.size()+1) / 2 << "\n"; for (int i = 0; i < (leaves.size()+1)/2; i++) { cout << leaves[i] << " " << leaves[i + leaves.size()/2] << "\n"; } }

Compilation message (stderr)

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