Submission #443499

#TimeUsernameProblemLanguageResultExecution timeMemory
443499BeanZNetwork (BOI15_net)C++14
100 / 100
538 ms64448 KiB
// I_Love_LPL 1y0m2d #include <bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' const int N = 1e6 + 5; long long mod = 1000007; const int lim = 4e5 + 5; const int lg = 20; const int base = 311; const long double eps = 1e-6; vector<ll> node[N]; vector<ll> one; void dfs(ll u, ll p){ for (auto j : node[u]){ if (j == p) continue; dfs(j, u); } if (node[u].size() == 1) one.push_back(u); } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("tests.inp", "r")){ freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } ll n; cin >> n; for (int i = 1; i < n; i++){ ll u, v; cin >> u >> v; node[u].push_back(v); node[v].push_back(u); } for (int i = 1; i <= n; i++){ if (node[i].size() != 1){ dfs(i, i); break; } } cout << (one.size() + 1) / 2 << endl; for (int i = 0; i < (one.size() + 1) / 2; i++){ cout << one[i] << " " << one[i + one.size() / 2] << endl; } } /* Ans: Out: */

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for (int i = 0; i < (one.size() + 1) / 2; i++){
      |                     ~~^~~~~~~~~~~~~~~~~~~~~~
net.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
net.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...