# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1085801 | 2024-09-08T17:58:48 Z | I_am_Polish_Girl | Cat Exercise (JOI23_ho_t4) | C++14 | 0 ms | 344 KB |
#pragma target("arch=icelake-server") #include <iostream> #include <vector> #include <algorithm> #include <map> #include <set> #include <unordered_map> #include <unordered_set> #include <stack> #include <queue> #include <cmath> #include <random> #include <chrono> #include <iomanip> #include <bitset> using namespace std; #define int long long typedef long long ll; typedef long double ld; int log_ = 21; int inf = 1000000007; long long mod = 998244353; int p = 499; int NADIYA = 39; vector <int> dp; vector <vector <int>> g; vector <int> a; int mx = -1; int mx2 = -1; void dfs(int ind , int last , int d) { if (mx2 < a[ind]) { mx = dp[ind] + d; mx2 = a[ind]; } for (int i = 0; i < g[ind].size(); i++) { int ind_s = g[ind][i]; if (ind_s == last) continue; if (dp[ind_s] == -1) continue; dfs(ind_s, ind , d+1); } } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; dp.resize(n, -1); a.resize(n); for (int i = 0; i < n; i++) cin >> a[i]; g.resize(n); for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; u--; v--; g[u].push_back(v); g[v].push_back(u); } vector <pair <int, int>> vp; for (int i = 0; i < n; i++) { vp.push_back({ a[i] , i }); } sort(vp.begin(), vp.end()); for (int i = 0; i < n; i++) { mx = -1; mx2 = -1; int ind = vp[i].second; dfs(ind, -1 , 0); mx = max(mx, 0ll); dp[ind] = mx; } cout << mx; } /* 5 5 2 2 2 4 4 #.... #.##. ####. ##... ..... */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |