# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
644243 | BackNoob | Uzastopni (COCI15_uzastopni) | C++14 | 28 ms | 5172 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.
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define endl '\n'
#define MASK(i) (1LL << (i))
#define ull unsigned long long
#define ld long double
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define BIT(x , i) ((x >> (i)) & 1)
#define TASK "task"
#define sz(s) (int) (s).size()
using namespace std;
const int mxN = 1e4 + 227;
const int inf = 1e9 + 277;
const int mod = 1e9 + 7;
const ll infll = 1e18 + 7;
const int base = 307;
const int LOG = 20;
const int block_sz = 550;
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
int n;
int v[mxN];
ll dp[107][107][107];
ll f[107][107];
vector<int> adj[mxN];
void dfs(int u, int p)
{
for(int v : adj[u]) {
if(v == p) continue;
dfs(v, u);
}
memset(f, 0, sizeof(f));
for(int i = 0; i <= 101; i++)
for(int j = 0; j <= 101; j++) if(i > j) f[i][j] = 1;
for(int v : adj[u]) {
if(v == p) continue;
for(int le = 100; le >= 1; le--) {
for(int i = 1; i + le - 1 <= 100; i++) {
int j = i + le - 1;
for(int k = i; k <= j; k++) {
f[i][j] += 1LL * f[i][k] * dp[v][k + 1][j];
f[i][j] += 1LL * dp[v][i][k] * f[k + 1][j];
}
}
}
}
for(int i = 1; i <= 100; i++) {
for(int j = i; j <= 100; j++) {
if(i <= v[u] && v[u] <= j) {
dp[u][i][j] += 1LL * f[i][v[u] - 1] * f[v[u] + 1][j];
}
}
}
}
void solve()
{
cin >> n;
for(int i = 1; i <= n; i++) cin >> v[i];
for(int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
dfs(1, -1);
ll res = 0;
for(int l = 1; l <= 100; l++)
for(int r = l; r <= 100; r++) {
res += dp[1][l][r];
}
cout << res;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("graph.inp", "r", stdin);
//freopen("graph.out", "w", stdout);
int tc = 1;
//cin >> tc;
while(tc--) {
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |