Submission #356237

#TimeUsernameProblemLanguageResultExecution timeMemory
356237nikita4109Network (BOI15_net)C++17
0 / 100
10 ms12140 KiB
#include <bits/stdc++.h> using namespace std; random_device rd; mt19937 rnd(rd()); #define pt pair<int, int> #define x first #define y second #define what_is(x) cerr << #x << " is " << x << endl; #define ok cerr << "ok" << endl; #define endl '\n' #define int long long #define ld long double const int N = 5e5 + 5; vector<int> g[N]; signed main() { cin.tie(0), cout.tie(0), ios::sync_with_stdio(0); int n; cin >> n; for (int i = 0, x, y; i < n - 1; ++i) { cin >> x >> y; --x, --y; g[x].push_back(y); g[y].push_back(x); } vector<int> a; for (int i = 0; i < n; ++i) { assert((int)g[i].size() > 0); if (g[i].size() == 1) a.push_back(i + 1); } int len = a.size(); if (len % 2) { cout << len / 2 + 1 << endl; cout << a[0] << " " << a.back(); for (int i = 0; i < a.size() / 2; ++i) cout << a[i] << " " << a[i + a.size() / 2] << endl; } else { cout << len / 2 << endl; for (int i = 0; i < a.size() / 2; ++i) cout << a[i] << " " << a[i + a.size() / 2] << endl; } return 0; }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:47:21: 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]
   47 |   for (int i = 0; i < a.size() / 2; ++i)
      |                   ~~^~~~~~~~~~~~~~
net.cpp:53:21: 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]
   53 |   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...