#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 1e5+7;
int n, a[N], par[N];
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#else
#define endl '\n'
ios_base::sync_with_stdio(0); cin.tie(0);
#endif
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int t = 0; t < n - 1; ++t) {
int u, v;
cin >> u >> v;
par[v] = u;
vector <int> path;
while (u) {
path.app(a[u]);
a[u] = a[v];
u = par[u];
}
int ans = 0;
for (int i = 0; i < path.size(); ++i)
for (int j = i + 1; j < path.size(); ++j)
ans += path[i] < path[j];
cout << ans << endl;
}
}
Compilation message
construction.cpp: In function 'int main()':
construction.cpp:39:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < path.size(); ++i)
~~^~~~~~~~~~~~~
construction.cpp:40:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = i + 1; j < path.size(); ++j)
~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
416 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
23 ms |
384 KB |
Output is correct |
9 |
Correct |
23 ms |
384 KB |
Output is correct |
10 |
Correct |
22 ms |
384 KB |
Output is correct |
11 |
Correct |
10 ms |
384 KB |
Output is correct |
12 |
Correct |
10 ms |
384 KB |
Output is correct |
13 |
Correct |
11 ms |
512 KB |
Output is correct |
14 |
Correct |
10 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
10 ms |
384 KB |
Output is correct |
20 |
Correct |
10 ms |
384 KB |
Output is correct |
21 |
Correct |
10 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
22 ms |
384 KB |
Output is correct |
27 |
Correct |
10 ms |
384 KB |
Output is correct |
28 |
Correct |
10 ms |
384 KB |
Output is correct |
29 |
Correct |
10 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
10 ms |
384 KB |
Output is correct |
33 |
Correct |
6 ms |
384 KB |
Output is correct |
34 |
Correct |
6 ms |
384 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
7 ms |
384 KB |
Output is correct |
37 |
Correct |
6 ms |
384 KB |
Output is correct |
38 |
Correct |
6 ms |
384 KB |
Output is correct |
39 |
Correct |
7 ms |
384 KB |
Output is correct |
40 |
Correct |
6 ms |
384 KB |
Output is correct |
41 |
Correct |
6 ms |
384 KB |
Output is correct |
42 |
Correct |
6 ms |
384 KB |
Output is correct |
43 |
Correct |
6 ms |
384 KB |
Output is correct |
44 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
416 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
23 ms |
384 KB |
Output is correct |
9 |
Correct |
23 ms |
384 KB |
Output is correct |
10 |
Correct |
22 ms |
384 KB |
Output is correct |
11 |
Correct |
10 ms |
384 KB |
Output is correct |
12 |
Correct |
10 ms |
384 KB |
Output is correct |
13 |
Correct |
11 ms |
512 KB |
Output is correct |
14 |
Correct |
10 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
10 ms |
384 KB |
Output is correct |
20 |
Correct |
10 ms |
384 KB |
Output is correct |
21 |
Correct |
10 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
22 ms |
384 KB |
Output is correct |
27 |
Correct |
10 ms |
384 KB |
Output is correct |
28 |
Correct |
10 ms |
384 KB |
Output is correct |
29 |
Correct |
10 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
10 ms |
384 KB |
Output is correct |
33 |
Correct |
6 ms |
384 KB |
Output is correct |
34 |
Correct |
6 ms |
384 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
7 ms |
384 KB |
Output is correct |
37 |
Correct |
6 ms |
384 KB |
Output is correct |
38 |
Correct |
6 ms |
384 KB |
Output is correct |
39 |
Correct |
7 ms |
384 KB |
Output is correct |
40 |
Correct |
6 ms |
384 KB |
Output is correct |
41 |
Correct |
6 ms |
384 KB |
Output is correct |
42 |
Correct |
6 ms |
384 KB |
Output is correct |
43 |
Correct |
6 ms |
384 KB |
Output is correct |
44 |
Correct |
6 ms |
384 KB |
Output is correct |
45 |
Correct |
6 ms |
384 KB |
Output is correct |
46 |
Correct |
8 ms |
512 KB |
Output is correct |
47 |
Correct |
8 ms |
512 KB |
Output is correct |
48 |
Correct |
7 ms |
512 KB |
Output is correct |
49 |
Execution timed out |
2084 ms |
736 KB |
Time limit exceeded |
50 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
416 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
23 ms |
384 KB |
Output is correct |
9 |
Correct |
23 ms |
384 KB |
Output is correct |
10 |
Correct |
22 ms |
384 KB |
Output is correct |
11 |
Correct |
10 ms |
384 KB |
Output is correct |
12 |
Correct |
10 ms |
384 KB |
Output is correct |
13 |
Correct |
11 ms |
512 KB |
Output is correct |
14 |
Correct |
10 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
10 ms |
384 KB |
Output is correct |
20 |
Correct |
10 ms |
384 KB |
Output is correct |
21 |
Correct |
10 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
22 ms |
384 KB |
Output is correct |
27 |
Correct |
10 ms |
384 KB |
Output is correct |
28 |
Correct |
10 ms |
384 KB |
Output is correct |
29 |
Correct |
10 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
10 ms |
384 KB |
Output is correct |
33 |
Correct |
6 ms |
384 KB |
Output is correct |
34 |
Correct |
6 ms |
384 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
7 ms |
384 KB |
Output is correct |
37 |
Correct |
6 ms |
384 KB |
Output is correct |
38 |
Correct |
6 ms |
384 KB |
Output is correct |
39 |
Correct |
7 ms |
384 KB |
Output is correct |
40 |
Correct |
6 ms |
384 KB |
Output is correct |
41 |
Correct |
6 ms |
384 KB |
Output is correct |
42 |
Correct |
6 ms |
384 KB |
Output is correct |
43 |
Correct |
6 ms |
384 KB |
Output is correct |
44 |
Correct |
6 ms |
384 KB |
Output is correct |
45 |
Correct |
6 ms |
384 KB |
Output is correct |
46 |
Correct |
8 ms |
512 KB |
Output is correct |
47 |
Correct |
8 ms |
512 KB |
Output is correct |
48 |
Correct |
7 ms |
512 KB |
Output is correct |
49 |
Execution timed out |
2084 ms |
736 KB |
Time limit exceeded |
50 |
Halted |
0 ms |
0 KB |
- |