#include "bits/stdc++.h"
using namespace std;
// #define ORD_SET
// #define ROPE
#ifdef ORD_SET
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#endif
#ifdef ROPE
#include <ext/rope>
using namespace __gnu_cxx;
#endif
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using ll = long long;
using ld = long double;
#define pb push_back
#define ff first
#define ss second
#define sz(x) (ll)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// #define ll int
void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
void NotInteractive() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
void pre(ll a) { cout<<fixed<<setprecision(a); }
ll bit(ll a) { return __builtin_popcountll(a); }
ll binmul(ll a, ll b, ll c) { ll res = 0; while(b) { if(b&1) (res += a) %= c; (a += a) %= c; b >>= 1; } return res; }
ll binpow(ll a, ll b, ll c) { ll res = 1; while(b) { if(b&1) (res *= a) %= c; (a *= a) %= c; b >>= 1; } return res; }
template<typename T> T gcd(T a, T b) { if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b) { return a/gcd(a, b)*b; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ld rnd() { return rng()%INT_MAX*1.0/INT_MAX; }
struct sn { ll l, r, x; };
ll B = 316;
const ll mod = 1e9+7;
const ll inf = 1e18+7;
const ll MX = LLONG_MAX;
const ll MN = LLONG_MIN;
const ld P = acos(-1.0);
const ll N = 3e5+5;
ll c[N];
vector<ll> g[N];
void kigash() {
ll n;
cin>>n;
for(ll i=1; i<=n; i++) cin>>c[i];
g[1].pb(1);
for(ll t=1; t<n; t++) {
ll u, v, cnt = 0;
cin>>u>>v;
for(ll i=0; i<sz(g[u]); i++) {
for(ll j=i+1; j<sz(g[u]); j++) {
if(c[g[u][i]]>c[g[u][j]]) cnt++;
}
}
cout<<cnt<<"\n";
for(ll i=0; i<sz(g[u]); i++) c[g[u][i]] = c[v];
g[v] = g[u];
g[v].pb(v);
}
return;
}
signed main(/*Kigash Amir*/) {
// freopen("");
NotInteractive();
// precalc();
ll tt = 1;
// cin>>tt;
for(ll i=1; i<=tt; i++) kigash();
exit(0);
}
Compilation message
construction.cpp: In function 'void freopen(std::string)':
construction.cpp:31:33: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
construction.cpp:31:73: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7376 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
4 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7380 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Correct |
4 ms |
7380 KB |
Output is correct |
8 |
Correct |
31 ms |
9712 KB |
Output is correct |
9 |
Correct |
27 ms |
9728 KB |
Output is correct |
10 |
Correct |
27 ms |
9812 KB |
Output is correct |
11 |
Correct |
10 ms |
8276 KB |
Output is correct |
12 |
Correct |
10 ms |
8356 KB |
Output is correct |
13 |
Correct |
10 ms |
8272 KB |
Output is correct |
14 |
Correct |
10 ms |
8404 KB |
Output is correct |
15 |
Correct |
4 ms |
7380 KB |
Output is correct |
16 |
Correct |
4 ms |
7380 KB |
Output is correct |
17 |
Correct |
5 ms |
7380 KB |
Output is correct |
18 |
Correct |
4 ms |
7380 KB |
Output is correct |
19 |
Correct |
10 ms |
8276 KB |
Output is correct |
20 |
Correct |
10 ms |
8272 KB |
Output is correct |
21 |
Correct |
11 ms |
8276 KB |
Output is correct |
22 |
Correct |
5 ms |
7380 KB |
Output is correct |
23 |
Correct |
5 ms |
7380 KB |
Output is correct |
24 |
Correct |
4 ms |
7380 KB |
Output is correct |
25 |
Correct |
4 ms |
7380 KB |
Output is correct |
26 |
Correct |
28 ms |
9732 KB |
Output is correct |
27 |
Correct |
11 ms |
8304 KB |
Output is correct |
28 |
Correct |
11 ms |
8276 KB |
Output is correct |
29 |
Correct |
11 ms |
8376 KB |
Output is correct |
30 |
Correct |
4 ms |
7380 KB |
Output is correct |
31 |
Correct |
4 ms |
7380 KB |
Output is correct |
32 |
Correct |
14 ms |
8340 KB |
Output is correct |
33 |
Correct |
6 ms |
7892 KB |
Output is correct |
34 |
Correct |
6 ms |
7636 KB |
Output is correct |
35 |
Correct |
5 ms |
7616 KB |
Output is correct |
36 |
Correct |
8 ms |
7892 KB |
Output is correct |
37 |
Correct |
6 ms |
7668 KB |
Output is correct |
38 |
Correct |
5 ms |
7636 KB |
Output is correct |
39 |
Correct |
6 ms |
7892 KB |
Output is correct |
40 |
Correct |
5 ms |
7640 KB |
Output is correct |
41 |
Correct |
5 ms |
7640 KB |
Output is correct |
42 |
Correct |
6 ms |
7844 KB |
Output is correct |
43 |
Correct |
5 ms |
7636 KB |
Output is correct |
44 |
Correct |
5 ms |
7636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7376 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
4 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7380 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Correct |
4 ms |
7380 KB |
Output is correct |
8 |
Correct |
31 ms |
9712 KB |
Output is correct |
9 |
Correct |
27 ms |
9728 KB |
Output is correct |
10 |
Correct |
27 ms |
9812 KB |
Output is correct |
11 |
Correct |
10 ms |
8276 KB |
Output is correct |
12 |
Correct |
10 ms |
8356 KB |
Output is correct |
13 |
Correct |
10 ms |
8272 KB |
Output is correct |
14 |
Correct |
10 ms |
8404 KB |
Output is correct |
15 |
Correct |
4 ms |
7380 KB |
Output is correct |
16 |
Correct |
4 ms |
7380 KB |
Output is correct |
17 |
Correct |
5 ms |
7380 KB |
Output is correct |
18 |
Correct |
4 ms |
7380 KB |
Output is correct |
19 |
Correct |
10 ms |
8276 KB |
Output is correct |
20 |
Correct |
10 ms |
8272 KB |
Output is correct |
21 |
Correct |
11 ms |
8276 KB |
Output is correct |
22 |
Correct |
5 ms |
7380 KB |
Output is correct |
23 |
Correct |
5 ms |
7380 KB |
Output is correct |
24 |
Correct |
4 ms |
7380 KB |
Output is correct |
25 |
Correct |
4 ms |
7380 KB |
Output is correct |
26 |
Correct |
28 ms |
9732 KB |
Output is correct |
27 |
Correct |
11 ms |
8304 KB |
Output is correct |
28 |
Correct |
11 ms |
8276 KB |
Output is correct |
29 |
Correct |
11 ms |
8376 KB |
Output is correct |
30 |
Correct |
4 ms |
7380 KB |
Output is correct |
31 |
Correct |
4 ms |
7380 KB |
Output is correct |
32 |
Correct |
14 ms |
8340 KB |
Output is correct |
33 |
Correct |
6 ms |
7892 KB |
Output is correct |
34 |
Correct |
6 ms |
7636 KB |
Output is correct |
35 |
Correct |
5 ms |
7616 KB |
Output is correct |
36 |
Correct |
8 ms |
7892 KB |
Output is correct |
37 |
Correct |
6 ms |
7668 KB |
Output is correct |
38 |
Correct |
5 ms |
7636 KB |
Output is correct |
39 |
Correct |
6 ms |
7892 KB |
Output is correct |
40 |
Correct |
5 ms |
7640 KB |
Output is correct |
41 |
Correct |
5 ms |
7640 KB |
Output is correct |
42 |
Correct |
6 ms |
7844 KB |
Output is correct |
43 |
Correct |
5 ms |
7636 KB |
Output is correct |
44 |
Correct |
5 ms |
7636 KB |
Output is correct |
45 |
Correct |
4 ms |
7508 KB |
Output is correct |
46 |
Correct |
7 ms |
7892 KB |
Output is correct |
47 |
Correct |
7 ms |
8008 KB |
Output is correct |
48 |
Correct |
7 ms |
7892 KB |
Output is correct |
49 |
Execution timed out |
2087 ms |
47164 KB |
Time limit exceeded |
50 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7376 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
4 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7380 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Correct |
4 ms |
7380 KB |
Output is correct |
8 |
Correct |
31 ms |
9712 KB |
Output is correct |
9 |
Correct |
27 ms |
9728 KB |
Output is correct |
10 |
Correct |
27 ms |
9812 KB |
Output is correct |
11 |
Correct |
10 ms |
8276 KB |
Output is correct |
12 |
Correct |
10 ms |
8356 KB |
Output is correct |
13 |
Correct |
10 ms |
8272 KB |
Output is correct |
14 |
Correct |
10 ms |
8404 KB |
Output is correct |
15 |
Correct |
4 ms |
7380 KB |
Output is correct |
16 |
Correct |
4 ms |
7380 KB |
Output is correct |
17 |
Correct |
5 ms |
7380 KB |
Output is correct |
18 |
Correct |
4 ms |
7380 KB |
Output is correct |
19 |
Correct |
10 ms |
8276 KB |
Output is correct |
20 |
Correct |
10 ms |
8272 KB |
Output is correct |
21 |
Correct |
11 ms |
8276 KB |
Output is correct |
22 |
Correct |
5 ms |
7380 KB |
Output is correct |
23 |
Correct |
5 ms |
7380 KB |
Output is correct |
24 |
Correct |
4 ms |
7380 KB |
Output is correct |
25 |
Correct |
4 ms |
7380 KB |
Output is correct |
26 |
Correct |
28 ms |
9732 KB |
Output is correct |
27 |
Correct |
11 ms |
8304 KB |
Output is correct |
28 |
Correct |
11 ms |
8276 KB |
Output is correct |
29 |
Correct |
11 ms |
8376 KB |
Output is correct |
30 |
Correct |
4 ms |
7380 KB |
Output is correct |
31 |
Correct |
4 ms |
7380 KB |
Output is correct |
32 |
Correct |
14 ms |
8340 KB |
Output is correct |
33 |
Correct |
6 ms |
7892 KB |
Output is correct |
34 |
Correct |
6 ms |
7636 KB |
Output is correct |
35 |
Correct |
5 ms |
7616 KB |
Output is correct |
36 |
Correct |
8 ms |
7892 KB |
Output is correct |
37 |
Correct |
6 ms |
7668 KB |
Output is correct |
38 |
Correct |
5 ms |
7636 KB |
Output is correct |
39 |
Correct |
6 ms |
7892 KB |
Output is correct |
40 |
Correct |
5 ms |
7640 KB |
Output is correct |
41 |
Correct |
5 ms |
7640 KB |
Output is correct |
42 |
Correct |
6 ms |
7844 KB |
Output is correct |
43 |
Correct |
5 ms |
7636 KB |
Output is correct |
44 |
Correct |
5 ms |
7636 KB |
Output is correct |
45 |
Correct |
4 ms |
7508 KB |
Output is correct |
46 |
Correct |
7 ms |
7892 KB |
Output is correct |
47 |
Correct |
7 ms |
8008 KB |
Output is correct |
48 |
Correct |
7 ms |
7892 KB |
Output is correct |
49 |
Execution timed out |
2087 ms |
47164 KB |
Time limit exceeded |
50 |
Halted |
0 ms |
0 KB |
- |