Submission #1084613

#TimeUsernameProblemLanguageResultExecution timeMemory
1084613_rain_Network (BOI15_net)C++14
100 / 100
201 ms47824 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define fixbug true const int maxn = 5e5; vector<int> g[maxn+2]; vector<int> leaf; int n; void dfs(int u , int p){ if (g[u].size()==1) leaf.push_back(u); for (auto& v : g[u]){ if (v != p) dfs(v,u); } return; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define name "main" if (fopen(name".inp","r")){ freopen(name".inp","r",stdin); } cin >> n; for (int i = 1; i < n; ++i){ int u , v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } for (int i = 1; i <= n; ++i){ if (g[i].size() > 1){ dfs(i,i); break; } } if (leaf.size()%2==1) leaf.push_back(leaf.front()); cout << leaf.size() / 2 << '\n'; for (int i = 0; i < leaf.size() / 2; i++){ cout << leaf[i] << ' ' << leaf[leaf.size()/2 + i] << '\n'; } exit(0); }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:41:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for (int i = 0; i < leaf.size() / 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(name".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...