# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
675209 | 2022-12-27T02:58:40 Z | vjudge1 | Uzastopni (COCI15_uzastopni) | C++17 | 61 ms | 18304 KB |
//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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 596 KB | Output is correct |
2 | Correct | 1 ms | 596 KB | Output is correct |
3 | Correct | 1 ms | 596 KB | Output is correct |
4 | Correct | 1 ms | 596 KB | Output is correct |
5 | Correct | 1 ms | 724 KB | Output is correct |
6 | Correct | 1 ms | 724 KB | Output is correct |
7 | Correct | 1 ms | 724 KB | Output is correct |
8 | Correct | 1 ms | 724 KB | Output is correct |
9 | Correct | 1 ms | 724 KB | Output is correct |
10 | Correct | 1 ms | 596 KB | Output is correct |
11 | Correct | 43 ms | 15172 KB | Output is correct |
12 | Correct | 17 ms | 7924 KB | Output is correct |
13 | Correct | 22 ms | 9692 KB | Output is correct |
14 | Correct | 59 ms | 18252 KB | Output is correct |
15 | Correct | 59 ms | 18296 KB | Output is correct |
16 | Correct | 61 ms | 18304 KB | Output is correct |
17 | Correct | 9 ms | 4052 KB | Output is correct |
18 | Correct | 28 ms | 10884 KB | Output is correct |
19 | Correct | 3 ms | 724 KB | Output is correct |
20 | Correct | 3 ms | 724 KB | Output is correct |