Submission #764945

#TimeUsernameProblemLanguageResultExecution timeMemory
764945vjudge1Network (BOI15_net)C++17
0 / 100
3 ms5028 KiB
/****************** tree-bends-in-youth //22///06///2023/// ******************/ #include <bits/stdc++.h> #define ll long long #define F first #define S second #define pb push_back #define all(x) x.begin(), x.end() using namespace std; const ll N = 2e5 + 1; const ll INF = 1e17; const ll MOD = 1e9 + 7; vector <int> g[N]; map <int,int> used; int d[N]; void solve(){ int n; cin >> n; set <int> s; for(int i = 1;i <= n;i++){ s.insert(i); } for(int i = 1;i < n;i++){ int x,y; cin >> x >> y; g[x].pb(y); g[y].pb(x); if(g[x].size() > 1)s.erase(x); if(g[y].size() > 1)s.erase(y); } vector <int> a; for(auto to : s){ a.pb(to); } cout << ((a.size() + 1) / 2) << '\n'; for(int i = 0;i < a.size();i++){ if(s.count(a[i]) == 0)continue; s.erase(a[i]); cout << a[i] << " "; if(s.empty()){ cout << a[i- 1] << '\n'; continue; } for(int j = 1;j <= n;j++){ d[j] = 0; } queue <int> q; q.push(a[i]); used.clear(); used[a[i]] = 1; while(!q.empty()){ int v= q.front(); q.pop(); for(auto to : g[v]){ if(used[to] == 0){ q.push(to); used[to] = 1; d[to] = d[v] + 1; } } } int mx = 0,w = 0; for(auto to : s){ if(d[to] > mx){ mx = d[to]; w = to; } } cout << w << "\n"; s.erase(w); } } main () { ios_base::sync_with_stdio(0); cin.tie(0); //freopen("censor.in","r",stdin); //freopen("censor.out","w",stdout); ll T = 1; //cin >> T; for(ll i = 1;i <= T;i++){ // cout << "Case " << i << ":\n"; solve(); } }

Compilation message (stderr)

net.cpp: In function 'void solve()':
net.cpp:38:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for(int i = 0;i < a.size();i++){
      |                   ~~^~~~~~~~~~
net.cpp: At global scope:
net.cpp:75:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   75 | main () {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...