# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1085799 | I_am_Polish_Girl | Cat Exercise (JOI23_ho_t4) | C++14 | 2074 ms | 24008 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
int mx = -1;
void dfs(int ind , int last , int d)
{
mx = max(mx, dp[ind]+d);
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);
vector <int> a(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;
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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |