Submission #854478

#TimeUsernameProblemLanguageResultExecution timeMemory
854478vjudge1Svjetlo (COCI20_svjetlo)C++17
0 / 110
125 ms28500 KiB
//author: Ahmet Alp Orakci #include <bits/stdc++.h> using namespace std; using i64 = long long; int get() { char ch; cin >> ch; return int(ch - '0'); } #define ONLINE_JUDGE void solve() { int n; cin >> n; vector <int> vec(n); for(int &i : vec) { i = get(); } vector <int> adj[n +1]; for(int i = 1; i <= n -1; i++) { int u, v; cin >> u >> v; adj[u].emplace_back(v); adj[v].emplace_back(u); } function <int(int, int)> dfs = [&](int node, int par) -> int { if(adj[node].size() >= 2) { return 1; } int res = 1; for(int &child : adj[node]) { if(child != par) { res = max(res, dfs(child, node) +1); } } return res; }; int mn = n +1; for(int i = 1; i <= n; i++) { if(adj[i].size() == 1) { mn = min(mn, dfs(i, 0) +1); } } cout << n * 2 - mn; return; } signed main() { #ifndef ONLINE_JUDGE freopen(".in", "r", stdin); freopen(".out", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; //cin >> t; for(int i = 1; i <= t; i++) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...