#include<bits/stdc++.h>
#define fo(i,d,c) for(int i=d;i<=c;i++)
#define fod(i,c,d) for(int i=c;i>=d;i--)
#define maxn 10010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout<<"\n";
#define inf 1000000000
#define pii pair<int,int>
#define vii vector<pii>
#define lb(x) x&-x
#define bit(i,j) ((i>>j)&1)
#define offbit(i,j) (i^(1<<j))
#define onbit(i,j) (i|(1<<j))
#define vi vector<int>
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;
}
using namespace std;
bitset<110> dp[10010][110];
vi ke[maxn];
int v[maxn];
int n;
bitset<110> f[110];
void dfs(int u)
{
for(int v : ke[u]) dfs(v);
fo(i,1,100) f[i].reset();
f[v[u]][v[u]] = 1;
for(int v : ke[u])
{
fo(i,1,100) f[i] |= dp[v][i];
}
fo(i,1,100) fo(j,i,100) if(f[i][j]) f[i] |= f[j];
dp[u][v[u]][v[u]] = 1;
fo(i,1,100) fo(j,i,100)
{
if(f[i + 1][j] and i == v[u]) dp[u][i][j] = 1;
if(f[i][j - 1] and j == v[u]) dp[u][i][j] = 1;
if(f[i][v[u] - 1] and f[v[u] + 1][j]) dp[u][i][j] = 1;
}
}
main()
{
#define name "TASK"
if(fopen(name".inp","r"))
{
freopen(name".inp","r",stdin);
freopen(name".out","w",stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
fo(i,1,n) cin >> v[i];
fo(i,1,n - 1)
{
int u,v;
cin >> u >> v;
ke[u].pb(v);
}
dfs(1);
long long ans = 0;
fo(i,1,100) ans += dp[1][i].count();
cout << ans;
}
Compilation message
uzastopni.cpp:60:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
60 | main()
| ^~~~
uzastopni.cpp: In function 'int main()':
uzastopni.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | freopen(name".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
uzastopni.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | freopen(name".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2648 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
2648 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
2652 KB |
Output isn't correct |
4 |
Correct |
2 ms |
2904 KB |
Output is correct |
5 |
Correct |
2 ms |
2652 KB |
Output is correct |
6 |
Correct |
2 ms |
2656 KB |
Output is correct |
7 |
Correct |
2 ms |
2652 KB |
Output is correct |
8 |
Correct |
2 ms |
2652 KB |
Output is correct |
9 |
Incorrect |
3 ms |
2652 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
2652 KB |
Output isn't correct |
11 |
Incorrect |
148 ms |
17988 KB |
Output isn't correct |
12 |
Incorrect |
152 ms |
18004 KB |
Output isn't correct |
13 |
Correct |
134 ms |
17876 KB |
Output is correct |
14 |
Correct |
147 ms |
19104 KB |
Output is correct |
15 |
Correct |
142 ms |
19028 KB |
Output is correct |
16 |
Correct |
143 ms |
18928 KB |
Output is correct |
17 |
Incorrect |
170 ms |
18004 KB |
Output isn't correct |
18 |
Correct |
148 ms |
18004 KB |
Output is correct |
19 |
Incorrect |
139 ms |
17864 KB |
Output isn't correct |
20 |
Incorrect |
163 ms |
17988 KB |
Output isn't correct |