# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
693252 | Tien_Noob | Uzastopni (COCI15_uzastopni) | C++17 | 63 ms | 18448 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.
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
using namespace std;
const int N = 1e4, M = 1e2;
int a[N + 1], n;
vector<int> adj[N + 1];
bitset<M + 1> dp[N + 1][M + 1];
void read()
{
cin >> n;
for (int i = 1; i <= n; ++ i)
{
cin >> a[i];
}
for (int i = 1; i < n; ++ i)
{
int u, v;
cin >> u >> v;
adj[u].push_back(v);
}
}
void DFS(int u)
{
dp[u][a[u]][a[u]] = true;
for (int v : adj[u])
{
if (a[v] > a[u])
{
DFS(v);
for (int i = 1; i <= M; ++ i)
{
vector<int> avail;
for (int j = i; j < M; ++ j)
{
if (dp[u][i][j])
{
avail.push_back(j + 1);
}
}
for (int j : avail)
{
dp[u][i] |= dp[v][j];
}
}
}
}
reverse(adj[u].begin(), adj[u].end());
for (int v : adj[u])
{
if (a[v] < a[u])
{
DFS(v);
for (int i = 1; i <= M; ++ i)
{
vector<int> avail;
for (int j = i; j < M; ++ j)
{
if (dp[v][i][j])
{
avail.push_back(j + 1);
}
}
for (int j : avail)
{
dp[u][i] |= dp[u][j];
}
}
}
}
}
void solve()
{
for (int u = 1; u <= n; ++ u)
{
sort(adj[u].begin(), adj[u].end(), [&](const int &x, const int &y)
{
return a[x] < a[y];
});
}
DFS(1);
int res = 0;
for (int i = 1; i <= M; ++ i)
{
res += dp[1][i].count();
}
cout << res;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
//freopen(TASK".OUT", "w", stdout);
}
int t = 1;
bool typetest = false;
if (typetest)
{
cin >> t;
}
for (int __ = 1; __ <= t; ++ __)
{
//cout << "Case " << __ << ": ";
read();
solve();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |