// oooo
/*
har chi delet mikhad bebar ~
gitar o ba khodet nabar! ~
;Amoo_Hasan;
*/
#include<bits/stdc++.h>
//#pragma GCC optimize("O3,no-stack-protector,unroll-loops")
//#pragma GCC target("avx2,fma")
using namespace std;
typedef long long ll;
typedef long double ld;
#define Sz(x) int((x).size())
#define All(x) (x).begin(), (x).end()
#define wtf(x) cout<<#x <<" : " <<x <<endl
#define mak make_pair
//constexpr int PRI = 1000696969;
constexpr ll INF = 1e18, N = 1e6 + 10, MOD = 1e9 + 7;
int a[N];
bool mark[N];
int par[N];
int cnt[N];
vector<int> adj[N];
int main() {
ios :: sync_with_stdio(0), cin.tie(0); cout.tie(0);
int n; cin >>n;
for(int i = 1; i <= n; i++) cin >>a[i];
mark[1] = 1;
cnt[1] = a[1];
int cur = 0;
for(int i = 0; i < n - 1; i++) {
int u, v; cin >>u >>v;
if(mark[v]) swap(u, v);
mark[v] = 1;
cnt[v] = a[v];
par[v] = u;
vector<int> vc;
int x = u;
while(x) {
if(x > 1) {
if(cnt[x] != cnt[par[x]]) cur++;
}
vc.push_back(cnt[x]);
cnt[x] = cnt[v];
x = par[x];
}
ll ans = 0;
for(int j = 0; j < Sz(vc); j++)
for(int k = j + 1; k < Sz(vc); k++)
if(vc[j] < vc[k]) ans++;
cout<<ans <<endl;
}
if(cur >= 10000000) assert(0);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
15 ms |
23764 KB |
Output is correct |
3 |
Correct |
15 ms |
23776 KB |
Output is correct |
4 |
Correct |
13 ms |
23764 KB |
Output is correct |
5 |
Correct |
13 ms |
23808 KB |
Output is correct |
6 |
Correct |
12 ms |
23764 KB |
Output is correct |
7 |
Correct |
13 ms |
23816 KB |
Output is correct |
8 |
Correct |
29 ms |
23812 KB |
Output is correct |
9 |
Correct |
32 ms |
23892 KB |
Output is correct |
10 |
Correct |
29 ms |
23764 KB |
Output is correct |
11 |
Correct |
18 ms |
23812 KB |
Output is correct |
12 |
Correct |
18 ms |
23752 KB |
Output is correct |
13 |
Correct |
19 ms |
23792 KB |
Output is correct |
14 |
Correct |
19 ms |
23836 KB |
Output is correct |
15 |
Correct |
13 ms |
23828 KB |
Output is correct |
16 |
Correct |
13 ms |
23764 KB |
Output is correct |
17 |
Correct |
16 ms |
23812 KB |
Output is correct |
18 |
Correct |
12 ms |
23816 KB |
Output is correct |
19 |
Correct |
17 ms |
23764 KB |
Output is correct |
20 |
Correct |
17 ms |
23764 KB |
Output is correct |
21 |
Correct |
18 ms |
23844 KB |
Output is correct |
22 |
Correct |
14 ms |
23752 KB |
Output is correct |
23 |
Correct |
13 ms |
23744 KB |
Output is correct |
24 |
Correct |
13 ms |
23764 KB |
Output is correct |
25 |
Correct |
13 ms |
23764 KB |
Output is correct |
26 |
Correct |
30 ms |
23844 KB |
Output is correct |
27 |
Correct |
17 ms |
23764 KB |
Output is correct |
28 |
Correct |
21 ms |
23764 KB |
Output is correct |
29 |
Correct |
18 ms |
23764 KB |
Output is correct |
30 |
Correct |
14 ms |
23828 KB |
Output is correct |
31 |
Correct |
13 ms |
23764 KB |
Output is correct |
32 |
Correct |
17 ms |
23848 KB |
Output is correct |
33 |
Correct |
14 ms |
23764 KB |
Output is correct |
34 |
Correct |
13 ms |
23764 KB |
Output is correct |
35 |
Correct |
13 ms |
23736 KB |
Output is correct |
36 |
Correct |
15 ms |
23764 KB |
Output is correct |
37 |
Correct |
14 ms |
23764 KB |
Output is correct |
38 |
Correct |
13 ms |
23764 KB |
Output is correct |
39 |
Correct |
15 ms |
23764 KB |
Output is correct |
40 |
Correct |
14 ms |
23764 KB |
Output is correct |
41 |
Correct |
13 ms |
23764 KB |
Output is correct |
42 |
Correct |
14 ms |
23764 KB |
Output is correct |
43 |
Correct |
13 ms |
23764 KB |
Output is correct |
44 |
Correct |
13 ms |
23828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
15 ms |
23764 KB |
Output is correct |
3 |
Correct |
15 ms |
23776 KB |
Output is correct |
4 |
Correct |
13 ms |
23764 KB |
Output is correct |
5 |
Correct |
13 ms |
23808 KB |
Output is correct |
6 |
Correct |
12 ms |
23764 KB |
Output is correct |
7 |
Correct |
13 ms |
23816 KB |
Output is correct |
8 |
Correct |
29 ms |
23812 KB |
Output is correct |
9 |
Correct |
32 ms |
23892 KB |
Output is correct |
10 |
Correct |
29 ms |
23764 KB |
Output is correct |
11 |
Correct |
18 ms |
23812 KB |
Output is correct |
12 |
Correct |
18 ms |
23752 KB |
Output is correct |
13 |
Correct |
19 ms |
23792 KB |
Output is correct |
14 |
Correct |
19 ms |
23836 KB |
Output is correct |
15 |
Correct |
13 ms |
23828 KB |
Output is correct |
16 |
Correct |
13 ms |
23764 KB |
Output is correct |
17 |
Correct |
16 ms |
23812 KB |
Output is correct |
18 |
Correct |
12 ms |
23816 KB |
Output is correct |
19 |
Correct |
17 ms |
23764 KB |
Output is correct |
20 |
Correct |
17 ms |
23764 KB |
Output is correct |
21 |
Correct |
18 ms |
23844 KB |
Output is correct |
22 |
Correct |
14 ms |
23752 KB |
Output is correct |
23 |
Correct |
13 ms |
23744 KB |
Output is correct |
24 |
Correct |
13 ms |
23764 KB |
Output is correct |
25 |
Correct |
13 ms |
23764 KB |
Output is correct |
26 |
Correct |
30 ms |
23844 KB |
Output is correct |
27 |
Correct |
17 ms |
23764 KB |
Output is correct |
28 |
Correct |
21 ms |
23764 KB |
Output is correct |
29 |
Correct |
18 ms |
23764 KB |
Output is correct |
30 |
Correct |
14 ms |
23828 KB |
Output is correct |
31 |
Correct |
13 ms |
23764 KB |
Output is correct |
32 |
Correct |
17 ms |
23848 KB |
Output is correct |
33 |
Correct |
14 ms |
23764 KB |
Output is correct |
34 |
Correct |
13 ms |
23764 KB |
Output is correct |
35 |
Correct |
13 ms |
23736 KB |
Output is correct |
36 |
Correct |
15 ms |
23764 KB |
Output is correct |
37 |
Correct |
14 ms |
23764 KB |
Output is correct |
38 |
Correct |
13 ms |
23764 KB |
Output is correct |
39 |
Correct |
15 ms |
23764 KB |
Output is correct |
40 |
Correct |
14 ms |
23764 KB |
Output is correct |
41 |
Correct |
13 ms |
23764 KB |
Output is correct |
42 |
Correct |
14 ms |
23764 KB |
Output is correct |
43 |
Correct |
13 ms |
23764 KB |
Output is correct |
44 |
Correct |
13 ms |
23828 KB |
Output is correct |
45 |
Correct |
13 ms |
23764 KB |
Output is correct |
46 |
Correct |
19 ms |
23892 KB |
Output is correct |
47 |
Correct |
19 ms |
23892 KB |
Output is correct |
48 |
Correct |
19 ms |
23892 KB |
Output is correct |
49 |
Execution timed out |
2083 ms |
23904 KB |
Time limit exceeded |
50 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
15 ms |
23764 KB |
Output is correct |
3 |
Correct |
15 ms |
23776 KB |
Output is correct |
4 |
Correct |
13 ms |
23764 KB |
Output is correct |
5 |
Correct |
13 ms |
23808 KB |
Output is correct |
6 |
Correct |
12 ms |
23764 KB |
Output is correct |
7 |
Correct |
13 ms |
23816 KB |
Output is correct |
8 |
Correct |
29 ms |
23812 KB |
Output is correct |
9 |
Correct |
32 ms |
23892 KB |
Output is correct |
10 |
Correct |
29 ms |
23764 KB |
Output is correct |
11 |
Correct |
18 ms |
23812 KB |
Output is correct |
12 |
Correct |
18 ms |
23752 KB |
Output is correct |
13 |
Correct |
19 ms |
23792 KB |
Output is correct |
14 |
Correct |
19 ms |
23836 KB |
Output is correct |
15 |
Correct |
13 ms |
23828 KB |
Output is correct |
16 |
Correct |
13 ms |
23764 KB |
Output is correct |
17 |
Correct |
16 ms |
23812 KB |
Output is correct |
18 |
Correct |
12 ms |
23816 KB |
Output is correct |
19 |
Correct |
17 ms |
23764 KB |
Output is correct |
20 |
Correct |
17 ms |
23764 KB |
Output is correct |
21 |
Correct |
18 ms |
23844 KB |
Output is correct |
22 |
Correct |
14 ms |
23752 KB |
Output is correct |
23 |
Correct |
13 ms |
23744 KB |
Output is correct |
24 |
Correct |
13 ms |
23764 KB |
Output is correct |
25 |
Correct |
13 ms |
23764 KB |
Output is correct |
26 |
Correct |
30 ms |
23844 KB |
Output is correct |
27 |
Correct |
17 ms |
23764 KB |
Output is correct |
28 |
Correct |
21 ms |
23764 KB |
Output is correct |
29 |
Correct |
18 ms |
23764 KB |
Output is correct |
30 |
Correct |
14 ms |
23828 KB |
Output is correct |
31 |
Correct |
13 ms |
23764 KB |
Output is correct |
32 |
Correct |
17 ms |
23848 KB |
Output is correct |
33 |
Correct |
14 ms |
23764 KB |
Output is correct |
34 |
Correct |
13 ms |
23764 KB |
Output is correct |
35 |
Correct |
13 ms |
23736 KB |
Output is correct |
36 |
Correct |
15 ms |
23764 KB |
Output is correct |
37 |
Correct |
14 ms |
23764 KB |
Output is correct |
38 |
Correct |
13 ms |
23764 KB |
Output is correct |
39 |
Correct |
15 ms |
23764 KB |
Output is correct |
40 |
Correct |
14 ms |
23764 KB |
Output is correct |
41 |
Correct |
13 ms |
23764 KB |
Output is correct |
42 |
Correct |
14 ms |
23764 KB |
Output is correct |
43 |
Correct |
13 ms |
23764 KB |
Output is correct |
44 |
Correct |
13 ms |
23828 KB |
Output is correct |
45 |
Correct |
13 ms |
23764 KB |
Output is correct |
46 |
Correct |
19 ms |
23892 KB |
Output is correct |
47 |
Correct |
19 ms |
23892 KB |
Output is correct |
48 |
Correct |
19 ms |
23892 KB |
Output is correct |
49 |
Execution timed out |
2083 ms |
23904 KB |
Time limit exceeded |
50 |
Halted |
0 ms |
0 KB |
- |