Submission #932596

#TimeUsernameProblemLanguageResultExecution timeMemory
932596vjudge1Network (BOI15_net)C++17
0 / 100
1 ms512 KiB
// in the name of God #include<bits/stdc++.h> using namespace std; #define int long long #define fast() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ff first #define ss second #define pb(x) push_back(x) #define all(x) x.begin(), x.end() #define mk make_pair #define ppb pop_back #define endl '\n' #define pii pair<int, int> #define sz(x) (int)x.size() #define file() freopen("input.txt", "r", stdin); #pragma GCC optimize("Ofast") #pragma GCC optimize("O4") #pragma GCC optimize("unroll-loops") //#pragma GCC target("avx2") mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int mod = 1e9 + 7, maxn = 2e3 + 10, sq = 3163, inf = 1e18 + 10, lg = 25, pp = 4447, modd = 1e9 + 9; int n; vector<vector<int>> g(maxn); int h[maxn]; void dfs(int u = 0, int parr = -1){ for(int v : g[u]){ if(v != parr){ h[v] = h[u] + 1; dfs(v, u); } } } bool cmp(int a, int b){ if(h[a] > h[b]) return a > b; return a < b; } signed main(){ fast();//file(); cin >> n; for(int i = 1; i < n; ++i){ int u, v; cin >> u >> v; u--; v--; g[u].pb(v); g[v].pb(u); } dfs(); vector<int> b; for(int i = 0; i < n; ++i) if(g[i].size() == 1) b.pb(i); cout << ceil((double) b.size() / 2) << endl; sort(all(b), cmp); int p1 = 0, p2 = b.size() - 1; while(p1 < p2){ cout << b[p1] + 1 << " " << b[p2] + 1 << endl; p1++; p2--; } if(b.size() % 2){ cout << b[b.size() / 2] + 1 << " " << b.back() + 1; } } // Running from the daylight...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...