// 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];
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) {
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;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23780 KB |
Output is correct |
2 |
Correct |
12 ms |
23708 KB |
Output is correct |
3 |
Correct |
12 ms |
23764 KB |
Output is correct |
4 |
Correct |
16 ms |
23792 KB |
Output is correct |
5 |
Correct |
14 ms |
23752 KB |
Output is correct |
6 |
Correct |
15 ms |
23740 KB |
Output is correct |
7 |
Correct |
13 ms |
23764 KB |
Output is correct |
8 |
Correct |
29 ms |
23828 KB |
Output is correct |
9 |
Correct |
29 ms |
23764 KB |
Output is correct |
10 |
Correct |
29 ms |
23812 KB |
Output is correct |
11 |
Correct |
19 ms |
23828 KB |
Output is correct |
12 |
Correct |
19 ms |
23764 KB |
Output is correct |
13 |
Correct |
18 ms |
23800 KB |
Output is correct |
14 |
Correct |
18 ms |
23764 KB |
Output is correct |
15 |
Correct |
13 ms |
23740 KB |
Output is correct |
16 |
Correct |
14 ms |
23776 KB |
Output is correct |
17 |
Correct |
13 ms |
23764 KB |
Output is correct |
18 |
Correct |
16 ms |
23892 KB |
Output is correct |
19 |
Correct |
20 ms |
23764 KB |
Output is correct |
20 |
Correct |
21 ms |
23764 KB |
Output is correct |
21 |
Correct |
17 ms |
23764 KB |
Output is correct |
22 |
Correct |
13 ms |
23816 KB |
Output is correct |
23 |
Correct |
13 ms |
23764 KB |
Output is correct |
24 |
Correct |
13 ms |
23892 KB |
Output is correct |
25 |
Correct |
13 ms |
23760 KB |
Output is correct |
26 |
Correct |
29 ms |
23816 KB |
Output is correct |
27 |
Correct |
19 ms |
23828 KB |
Output is correct |
28 |
Correct |
18 ms |
23820 KB |
Output is correct |
29 |
Correct |
20 ms |
23764 KB |
Output is correct |
30 |
Correct |
13 ms |
23820 KB |
Output is correct |
31 |
Correct |
15 ms |
23764 KB |
Output is correct |
32 |
Correct |
20 ms |
23764 KB |
Output is correct |
33 |
Correct |
14 ms |
23764 KB |
Output is correct |
34 |
Correct |
14 ms |
23764 KB |
Output is correct |
35 |
Correct |
14 ms |
23764 KB |
Output is correct |
36 |
Correct |
14 ms |
23764 KB |
Output is correct |
37 |
Correct |
14 ms |
23764 KB |
Output is correct |
38 |
Correct |
14 ms |
23772 KB |
Output is correct |
39 |
Correct |
14 ms |
23764 KB |
Output is correct |
40 |
Correct |
18 ms |
23736 KB |
Output is correct |
41 |
Correct |
14 ms |
23804 KB |
Output is correct |
42 |
Correct |
14 ms |
23808 KB |
Output is correct |
43 |
Correct |
17 ms |
23744 KB |
Output is correct |
44 |
Correct |
15 ms |
23764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23780 KB |
Output is correct |
2 |
Correct |
12 ms |
23708 KB |
Output is correct |
3 |
Correct |
12 ms |
23764 KB |
Output is correct |
4 |
Correct |
16 ms |
23792 KB |
Output is correct |
5 |
Correct |
14 ms |
23752 KB |
Output is correct |
6 |
Correct |
15 ms |
23740 KB |
Output is correct |
7 |
Correct |
13 ms |
23764 KB |
Output is correct |
8 |
Correct |
29 ms |
23828 KB |
Output is correct |
9 |
Correct |
29 ms |
23764 KB |
Output is correct |
10 |
Correct |
29 ms |
23812 KB |
Output is correct |
11 |
Correct |
19 ms |
23828 KB |
Output is correct |
12 |
Correct |
19 ms |
23764 KB |
Output is correct |
13 |
Correct |
18 ms |
23800 KB |
Output is correct |
14 |
Correct |
18 ms |
23764 KB |
Output is correct |
15 |
Correct |
13 ms |
23740 KB |
Output is correct |
16 |
Correct |
14 ms |
23776 KB |
Output is correct |
17 |
Correct |
13 ms |
23764 KB |
Output is correct |
18 |
Correct |
16 ms |
23892 KB |
Output is correct |
19 |
Correct |
20 ms |
23764 KB |
Output is correct |
20 |
Correct |
21 ms |
23764 KB |
Output is correct |
21 |
Correct |
17 ms |
23764 KB |
Output is correct |
22 |
Correct |
13 ms |
23816 KB |
Output is correct |
23 |
Correct |
13 ms |
23764 KB |
Output is correct |
24 |
Correct |
13 ms |
23892 KB |
Output is correct |
25 |
Correct |
13 ms |
23760 KB |
Output is correct |
26 |
Correct |
29 ms |
23816 KB |
Output is correct |
27 |
Correct |
19 ms |
23828 KB |
Output is correct |
28 |
Correct |
18 ms |
23820 KB |
Output is correct |
29 |
Correct |
20 ms |
23764 KB |
Output is correct |
30 |
Correct |
13 ms |
23820 KB |
Output is correct |
31 |
Correct |
15 ms |
23764 KB |
Output is correct |
32 |
Correct |
20 ms |
23764 KB |
Output is correct |
33 |
Correct |
14 ms |
23764 KB |
Output is correct |
34 |
Correct |
14 ms |
23764 KB |
Output is correct |
35 |
Correct |
14 ms |
23764 KB |
Output is correct |
36 |
Correct |
14 ms |
23764 KB |
Output is correct |
37 |
Correct |
14 ms |
23764 KB |
Output is correct |
38 |
Correct |
14 ms |
23772 KB |
Output is correct |
39 |
Correct |
14 ms |
23764 KB |
Output is correct |
40 |
Correct |
18 ms |
23736 KB |
Output is correct |
41 |
Correct |
14 ms |
23804 KB |
Output is correct |
42 |
Correct |
14 ms |
23808 KB |
Output is correct |
43 |
Correct |
17 ms |
23744 KB |
Output is correct |
44 |
Correct |
15 ms |
23764 KB |
Output is correct |
45 |
Correct |
15 ms |
23812 KB |
Output is correct |
46 |
Correct |
20 ms |
23972 KB |
Output is correct |
47 |
Correct |
21 ms |
24008 KB |
Output is correct |
48 |
Correct |
19 ms |
23892 KB |
Output is correct |
49 |
Execution timed out |
2086 ms |
23980 KB |
Time limit exceeded |
50 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23780 KB |
Output is correct |
2 |
Correct |
12 ms |
23708 KB |
Output is correct |
3 |
Correct |
12 ms |
23764 KB |
Output is correct |
4 |
Correct |
16 ms |
23792 KB |
Output is correct |
5 |
Correct |
14 ms |
23752 KB |
Output is correct |
6 |
Correct |
15 ms |
23740 KB |
Output is correct |
7 |
Correct |
13 ms |
23764 KB |
Output is correct |
8 |
Correct |
29 ms |
23828 KB |
Output is correct |
9 |
Correct |
29 ms |
23764 KB |
Output is correct |
10 |
Correct |
29 ms |
23812 KB |
Output is correct |
11 |
Correct |
19 ms |
23828 KB |
Output is correct |
12 |
Correct |
19 ms |
23764 KB |
Output is correct |
13 |
Correct |
18 ms |
23800 KB |
Output is correct |
14 |
Correct |
18 ms |
23764 KB |
Output is correct |
15 |
Correct |
13 ms |
23740 KB |
Output is correct |
16 |
Correct |
14 ms |
23776 KB |
Output is correct |
17 |
Correct |
13 ms |
23764 KB |
Output is correct |
18 |
Correct |
16 ms |
23892 KB |
Output is correct |
19 |
Correct |
20 ms |
23764 KB |
Output is correct |
20 |
Correct |
21 ms |
23764 KB |
Output is correct |
21 |
Correct |
17 ms |
23764 KB |
Output is correct |
22 |
Correct |
13 ms |
23816 KB |
Output is correct |
23 |
Correct |
13 ms |
23764 KB |
Output is correct |
24 |
Correct |
13 ms |
23892 KB |
Output is correct |
25 |
Correct |
13 ms |
23760 KB |
Output is correct |
26 |
Correct |
29 ms |
23816 KB |
Output is correct |
27 |
Correct |
19 ms |
23828 KB |
Output is correct |
28 |
Correct |
18 ms |
23820 KB |
Output is correct |
29 |
Correct |
20 ms |
23764 KB |
Output is correct |
30 |
Correct |
13 ms |
23820 KB |
Output is correct |
31 |
Correct |
15 ms |
23764 KB |
Output is correct |
32 |
Correct |
20 ms |
23764 KB |
Output is correct |
33 |
Correct |
14 ms |
23764 KB |
Output is correct |
34 |
Correct |
14 ms |
23764 KB |
Output is correct |
35 |
Correct |
14 ms |
23764 KB |
Output is correct |
36 |
Correct |
14 ms |
23764 KB |
Output is correct |
37 |
Correct |
14 ms |
23764 KB |
Output is correct |
38 |
Correct |
14 ms |
23772 KB |
Output is correct |
39 |
Correct |
14 ms |
23764 KB |
Output is correct |
40 |
Correct |
18 ms |
23736 KB |
Output is correct |
41 |
Correct |
14 ms |
23804 KB |
Output is correct |
42 |
Correct |
14 ms |
23808 KB |
Output is correct |
43 |
Correct |
17 ms |
23744 KB |
Output is correct |
44 |
Correct |
15 ms |
23764 KB |
Output is correct |
45 |
Correct |
15 ms |
23812 KB |
Output is correct |
46 |
Correct |
20 ms |
23972 KB |
Output is correct |
47 |
Correct |
21 ms |
24008 KB |
Output is correct |
48 |
Correct |
19 ms |
23892 KB |
Output is correct |
49 |
Execution timed out |
2086 ms |
23980 KB |
Time limit exceeded |
50 |
Halted |
0 ms |
0 KB |
- |