Submission #1135236

#TimeUsernameProblemLanguageResultExecution timeMemory
1135236alir3za_zar3Village (BOI20_village)C++20
25 / 100
1093 ms17716 KiB
// Alir3za.Zar3 -> Shiraz , Iran #include <bits/stdc++.h> using namespace std; #define int long long #define loop(i , l , r) for (int i=l; i<=r; i+=1) #define arc(i , r , l) for (int i=r; i>=l; i-=1) const int N = 1e5+7; int n,Lo,Hi=0 , lo[N],hi[N],sz[N]; vector<int> e[N],T[N]; void brain_DFS (int v , int p) { sz[v] = 1; for (auto to : e[v]) { if (to == p){ continue; } brain_DFS(to,v); sz[v] += sz[to]; Hi += min(sz[to],n-sz[to]); } if (lo[v] == v) { if (v==p) swap(lo[v],lo[e[v].front()]); else swap(lo[v],lo[p]); Lo += 2; } int combine = min(sz[p],sz[v]); loop(i,0,combine-1) { swap(hi[T[p][i]],hi[T[v][i]]); } while (!T[v].empty() and v!=1) { T[p].push_back(T[v].back()); T[v].pop_back(); } T[v].clear(); T[v].shrink_to_fit(); } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; loop(i,1,n) { lo[i]=hi[i]=i; T[i].push_back(i); } loop(i,1,n-1) { int u,v; cin >> u >> v; e[u].push_back(v); e[v].push_back(u); } brain_DFS(1,1); cout << Lo << " " << Hi << '\n'; loop(i,1,n){ cout << lo[i] << " "; } cout << '\n'; loop(i,1,n){ cout << hi[i] << " "; } cout << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...