Submission #42247

#TimeUsernameProblemLanguageResultExecution timeMemory
42247wasylMag (COCI16_mag)C++11
120 / 120
540 ms252828 KiB
#include <bits/stdc++.h> #ifndef dbg #define dbg(...) #endif #define all(x) begin(x), end(x) #define rsz(...) resize(__VA_ARGS__) #define psh(...) push_back(__VA_ARGS__) #define emp(...) emplace_back(__VA_ARGS__) #define prt(...) print(cout, __VA_ARGS__) #define dprt(...) dbg(print(cerr,__VA_ARGS__)) #define dmp(...) dprt(#__VA_ARGS__, '=', __VA_ARGS__) using namespace std;using ll=long long; template<typename t>using V=vector<t>; template<typename t>void print(ostream& os, const t& a){os<<a<<'\n';} template<typename t, typename... A>void print (ostream& os, const t& a, A&&... b){os<<a<<' ';print(os, b...);} struct Node : V< int > { int val; }; int n, res1, res2; V< Node > gr; V< V< int > > dp; inline void dfs (int v, int oj = 1) { dmp(v, oj); for (int s : gr[v]) if (s != oj) dfs(s, v); if (gr[v].val > 2) return; int tres1 = 0, tres2 = 0; int naj = 0, tmp = 0; for (int s : gr[v]) if (s != oj) { tres1 = max(tres1, naj + dp[0][s] + 1); tres2 = max(tres2, naj + dp[1][s] + 1); tres2 = max(tres2, tmp + dp[0][s] + 1); naj = max(naj, dp[0][s]); tmp = max(tmp, dp[1][s]); } if (gr[v].val == 2) { dp[1][v] = naj + 1; res2 = max(res2, tres1); } else { res1 = max(res1, tres1); res2 = max(res2, tres2); dp[0][v] = naj + 1; dp[1][v] = tmp + 1; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; gr.rsz(n + 1); dp.rsz(2, V< int >(n + 1)); for (int i = 0, p, q; i < n - 1; ++i) { cin >> p >> q; gr[p].psh(q); gr[q].psh(p); } for (int i = 1; i <= n; ++i) cin >> gr[i].val; dfs(1); if (res1) { dmp(res1, res2); if (2 * res1 > res2) cout << 1 << '/' << res1 << '\n'; else { if (res2 & 1) cout << 2 << '/' << res2 << '\n'; else cout << 1 << '/' << res2 / 2 << '\n'; } } else { int mini = INT_MAX; for (int i = 1; i <= n; ++i) mini = min(mini, gr[i].val); cout << mini << '/' << 1 << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...