Submission #394607

#TimeUsernameProblemLanguageResultExecution timeMemory
394607amirmohammad_nezamiNetwork (BOI15_net)C++14
100 / 100
531 ms58824 KiB
// In the name of God // We are everywhere while we are nowhere(Haj NEZAM...) #include <bits/stdc++.h> using namespace std; #define F first #define S second #define lc 2 * v #define rc 2 * v + 1 #define PB push_back #define MP make_pair #define ll long long #define int long long #define ld long double #define mid (s + e) / 2 #define pii pair <int , int> #define _sz(e) (int)e.size() #define _all(e) e.begin() , e.end() #define pll pair <long long , long long> #define piii pair <int , pair <int , int> > #define FAST ios::sync_with_stdio(0);cin.tie(0) #define UNI(e) e.resize(unique(_all(e)) - e.begin()) #define kill(e) cout << e << '\n' #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") const int maxn = 5e5 + 5 , N = 1e6 + 5 , SQ = 450 , base = 800287 , mod = 1e9 + 7 , INF = 1e9 + 5 , lg = 20; const ld eps = 1e-4; int n , root; vector <int> vec; vector <int> edges[maxn]; void dfs(int v , int p = -1) { if(_sz(edges[v]) == 1) { vec.PB(v); } for (auto u : edges[v]) { if(u != p) { dfs(u , v); } } } int32_t main() { FAST; cin >> n; for (int i = 0; i < n - 1; ++i) { int x , y; cin >> x >> y; x-- , y--; edges[x].PB(y); edges[y].PB(x); } for (int i = 0; i < n; ++i) { if(_sz(edges[i]) > 1) {root = i;} } dfs(root); int ans = (_sz(vec) + 1) / 2; cout << ans << '\n'; for (int i = 0; i < ans; ++i) { int nxt = min(_sz(vec) - 1 , i + ans); cout << vec[i] + 1 << ' ' << vec[nxt] + 1 << '\n'; } } // Mistakes: // * Read the problem carefully. // * Check maxn. // * Overflows.
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...