# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
797887 | 2023-07-30T05:01:25 Z | vjudge1 | Construction of Highway (JOI18_construction) | C++17 | 2000 ms | 12548 KB |
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define rall(s) s.rbegin(),s.rend() #define all(s) s.begin(),s.end() #define pb push_back #define fi first #define se second #define ll long long #define ld long double #define YES cout<<"YES\n" #define Yes cout<<"Yes\n" #define yes cout<<"yes\n" #define NO cout<<"NO\n" #define No cout<<"No\n" #define no cout<<"no\n" tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>st; const int N = 1e5 + 9 , mod = 1e9 + 7; ll d[N] = {} , a[N] = {}, dp[N] = {}, b[N] , c[N] , sz[N] = {} , h[N] = {} , us[N] , p[N] , cnt = 0; vector<int>v[N]; /* void get_sz(int n , int p= 0){ sz[n] = 1; for(auto to : v[n]) if(to != p){ get_sz(to , n); if(sz[to] > h[n] && n) h[n] = sz[to] , swap(v[n][0] ,to); } sz[p] += sz[n]; }*/ void dfs(int n){ for(auto to : v[n]) if(p[n] != to) p[to] = n , dfs(to); } void solve(){ ll q , i , j , m ,n, z , s = 0, f, l , r , k , x , y , mn = 1e18 , mx = -1; cin>>n; for(i = 1; i <= n; i++) cin>>a[i] , d[i] = a[i]; for(i = 1; i < n; i++){ cin>>b[i]>>c[i]; v[b[i]].pb(c[i]); v[c[i]].pb(b[i]); } dfs(1); for(i = 1; i < n; i++){ l = b[i] , r = c[i]; cnt= s = 0; while(l){ if(st.size() && st.begin()->fi < d[l]){ auto it = st.lower_bound({d[l] , 0}); it--; x = st.order_of_key({it->fi , it->se}); s += x + 1; } st.insert({d[l],++cnt}); l = p[l]; } cout<<s<<"\n"; l = b[i]; while(l) d[l] = a[c[i]] , l = p[l]; st.clear(); } } int main(){ TL; /* #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif */ int t = 1; //cin>>t; while(t--) { solve(); } } // Author : حسن
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2644 KB | Output is correct |
2 | Correct | 1 ms | 2644 KB | Output is correct |
3 | Correct | 1 ms | 2644 KB | Output is correct |
4 | Correct | 1 ms | 2644 KB | Output is correct |
5 | Correct | 2 ms | 2644 KB | Output is correct |
6 | Correct | 2 ms | 2644 KB | Output is correct |
7 | Correct | 2 ms | 2644 KB | Output is correct |
8 | Correct | 13 ms | 2784 KB | Output is correct |
9 | Correct | 12 ms | 2772 KB | Output is correct |
10 | Correct | 16 ms | 2780 KB | Output is correct |
11 | Correct | 6 ms | 2756 KB | Output is correct |
12 | Correct | 8 ms | 2644 KB | Output is correct |
13 | Correct | 9 ms | 2748 KB | Output is correct |
14 | Correct | 7 ms | 2676 KB | Output is correct |
15 | Correct | 2 ms | 2644 KB | Output is correct |
16 | Correct | 2 ms | 2644 KB | Output is correct |
17 | Correct | 2 ms | 2644 KB | Output is correct |
18 | Correct | 2 ms | 2644 KB | Output is correct |
19 | Correct | 7 ms | 2756 KB | Output is correct |
20 | Correct | 9 ms | 2756 KB | Output is correct |
21 | Correct | 9 ms | 2760 KB | Output is correct |
22 | Correct | 2 ms | 2644 KB | Output is correct |
23 | Correct | 2 ms | 2644 KB | Output is correct |
24 | Correct | 2 ms | 2644 KB | Output is correct |
25 | Correct | 2 ms | 2644 KB | Output is correct |
26 | Correct | 12 ms | 2772 KB | Output is correct |
27 | Correct | 6 ms | 2748 KB | Output is correct |
28 | Correct | 6 ms | 2644 KB | Output is correct |
29 | Correct | 7 ms | 2756 KB | Output is correct |
30 | Correct | 2 ms | 2644 KB | Output is correct |
31 | Correct | 2 ms | 2644 KB | Output is correct |
32 | Correct | 7 ms | 2752 KB | Output is correct |
33 | Correct | 4 ms | 2644 KB | Output is correct |
34 | Correct | 3 ms | 2644 KB | Output is correct |
35 | Correct | 2 ms | 2644 KB | Output is correct |
36 | Correct | 4 ms | 2644 KB | Output is correct |
37 | Correct | 3 ms | 2644 KB | Output is correct |
38 | Correct | 2 ms | 2644 KB | Output is correct |
39 | Correct | 4 ms | 2644 KB | Output is correct |
40 | Correct | 3 ms | 2644 KB | Output is correct |
41 | Correct | 3 ms | 2644 KB | Output is correct |
42 | Correct | 4 ms | 2644 KB | Output is correct |
43 | Correct | 3 ms | 2644 KB | Output is correct |
44 | Correct | 3 ms | 2644 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2644 KB | Output is correct |
2 | Correct | 1 ms | 2644 KB | Output is correct |
3 | Correct | 1 ms | 2644 KB | Output is correct |
4 | Correct | 1 ms | 2644 KB | Output is correct |
5 | Correct | 2 ms | 2644 KB | Output is correct |
6 | Correct | 2 ms | 2644 KB | Output is correct |
7 | Correct | 2 ms | 2644 KB | Output is correct |
8 | Correct | 13 ms | 2784 KB | Output is correct |
9 | Correct | 12 ms | 2772 KB | Output is correct |
10 | Correct | 16 ms | 2780 KB | Output is correct |
11 | Correct | 6 ms | 2756 KB | Output is correct |
12 | Correct | 8 ms | 2644 KB | Output is correct |
13 | Correct | 9 ms | 2748 KB | Output is correct |
14 | Correct | 7 ms | 2676 KB | Output is correct |
15 | Correct | 2 ms | 2644 KB | Output is correct |
16 | Correct | 2 ms | 2644 KB | Output is correct |
17 | Correct | 2 ms | 2644 KB | Output is correct |
18 | Correct | 2 ms | 2644 KB | Output is correct |
19 | Correct | 7 ms | 2756 KB | Output is correct |
20 | Correct | 9 ms | 2756 KB | Output is correct |
21 | Correct | 9 ms | 2760 KB | Output is correct |
22 | Correct | 2 ms | 2644 KB | Output is correct |
23 | Correct | 2 ms | 2644 KB | Output is correct |
24 | Correct | 2 ms | 2644 KB | Output is correct |
25 | Correct | 2 ms | 2644 KB | Output is correct |
26 | Correct | 12 ms | 2772 KB | Output is correct |
27 | Correct | 6 ms | 2748 KB | Output is correct |
28 | Correct | 6 ms | 2644 KB | Output is correct |
29 | Correct | 7 ms | 2756 KB | Output is correct |
30 | Correct | 2 ms | 2644 KB | Output is correct |
31 | Correct | 2 ms | 2644 KB | Output is correct |
32 | Correct | 7 ms | 2752 KB | Output is correct |
33 | Correct | 4 ms | 2644 KB | Output is correct |
34 | Correct | 3 ms | 2644 KB | Output is correct |
35 | Correct | 2 ms | 2644 KB | Output is correct |
36 | Correct | 4 ms | 2644 KB | Output is correct |
37 | Correct | 3 ms | 2644 KB | Output is correct |
38 | Correct | 2 ms | 2644 KB | Output is correct |
39 | Correct | 4 ms | 2644 KB | Output is correct |
40 | Correct | 3 ms | 2644 KB | Output is correct |
41 | Correct | 3 ms | 2644 KB | Output is correct |
42 | Correct | 4 ms | 2644 KB | Output is correct |
43 | Correct | 3 ms | 2644 KB | Output is correct |
44 | Correct | 3 ms | 2644 KB | Output is correct |
45 | Correct | 2 ms | 2644 KB | Output is correct |
46 | Correct | 5 ms | 2900 KB | Output is correct |
47 | Correct | 5 ms | 2900 KB | Output is correct |
48 | Correct | 4 ms | 2900 KB | Output is correct |
49 | Correct | 986 ms | 3316 KB | Output is correct |
50 | Correct | 999 ms | 3276 KB | Output is correct |
51 | Correct | 973 ms | 3352 KB | Output is correct |
52 | Correct | 483 ms | 3124 KB | Output is correct |
53 | Correct | 455 ms | 3140 KB | Output is correct |
54 | Correct | 449 ms | 3136 KB | Output is correct |
55 | Correct | 482 ms | 3240 KB | Output is correct |
56 | Correct | 448 ms | 3064 KB | Output is correct |
57 | Correct | 5 ms | 2900 KB | Output is correct |
58 | Correct | 5 ms | 2988 KB | Output is correct |
59 | Correct | 5 ms | 2900 KB | Output is correct |
60 | Correct | 5 ms | 2900 KB | Output is correct |
61 | Correct | 479 ms | 3092 KB | Output is correct |
62 | Correct | 492 ms | 3148 KB | Output is correct |
63 | Correct | 482 ms | 3088 KB | Output is correct |
64 | Correct | 5 ms | 2900 KB | Output is correct |
65 | Correct | 5 ms | 2968 KB | Output is correct |
66 | Correct | 5 ms | 2900 KB | Output is correct |
67 | Correct | 4 ms | 2900 KB | Output is correct |
68 | Correct | 986 ms | 3312 KB | Output is correct |
69 | Correct | 441 ms | 3144 KB | Output is correct |
70 | Correct | 447 ms | 3148 KB | Output is correct |
71 | Correct | 476 ms | 3156 KB | Output is correct |
72 | Correct | 5 ms | 2900 KB | Output is correct |
73 | Correct | 5 ms | 2988 KB | Output is correct |
74 | Correct | 485 ms | 3136 KB | Output is correct |
75 | Correct | 213 ms | 3052 KB | Output is correct |
76 | Correct | 129 ms | 3028 KB | Output is correct |
77 | Correct | 102 ms | 3016 KB | Output is correct |
78 | Correct | 222 ms | 3048 KB | Output is correct |
79 | Correct | 129 ms | 3028 KB | Output is correct |
80 | Correct | 99 ms | 3004 KB | Output is correct |
81 | Correct | 219 ms | 3060 KB | Output is correct |
82 | Correct | 141 ms | 3028 KB | Output is correct |
83 | Correct | 104 ms | 3008 KB | Output is correct |
84 | Correct | 218 ms | 3044 KB | Output is correct |
85 | Correct | 143 ms | 3028 KB | Output is correct |
86 | Correct | 102 ms | 3012 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2644 KB | Output is correct |
2 | Correct | 1 ms | 2644 KB | Output is correct |
3 | Correct | 1 ms | 2644 KB | Output is correct |
4 | Correct | 1 ms | 2644 KB | Output is correct |
5 | Correct | 2 ms | 2644 KB | Output is correct |
6 | Correct | 2 ms | 2644 KB | Output is correct |
7 | Correct | 2 ms | 2644 KB | Output is correct |
8 | Correct | 13 ms | 2784 KB | Output is correct |
9 | Correct | 12 ms | 2772 KB | Output is correct |
10 | Correct | 16 ms | 2780 KB | Output is correct |
11 | Correct | 6 ms | 2756 KB | Output is correct |
12 | Correct | 8 ms | 2644 KB | Output is correct |
13 | Correct | 9 ms | 2748 KB | Output is correct |
14 | Correct | 7 ms | 2676 KB | Output is correct |
15 | Correct | 2 ms | 2644 KB | Output is correct |
16 | Correct | 2 ms | 2644 KB | Output is correct |
17 | Correct | 2 ms | 2644 KB | Output is correct |
18 | Correct | 2 ms | 2644 KB | Output is correct |
19 | Correct | 7 ms | 2756 KB | Output is correct |
20 | Correct | 9 ms | 2756 KB | Output is correct |
21 | Correct | 9 ms | 2760 KB | Output is correct |
22 | Correct | 2 ms | 2644 KB | Output is correct |
23 | Correct | 2 ms | 2644 KB | Output is correct |
24 | Correct | 2 ms | 2644 KB | Output is correct |
25 | Correct | 2 ms | 2644 KB | Output is correct |
26 | Correct | 12 ms | 2772 KB | Output is correct |
27 | Correct | 6 ms | 2748 KB | Output is correct |
28 | Correct | 6 ms | 2644 KB | Output is correct |
29 | Correct | 7 ms | 2756 KB | Output is correct |
30 | Correct | 2 ms | 2644 KB | Output is correct |
31 | Correct | 2 ms | 2644 KB | Output is correct |
32 | Correct | 7 ms | 2752 KB | Output is correct |
33 | Correct | 4 ms | 2644 KB | Output is correct |
34 | Correct | 3 ms | 2644 KB | Output is correct |
35 | Correct | 2 ms | 2644 KB | Output is correct |
36 | Correct | 4 ms | 2644 KB | Output is correct |
37 | Correct | 3 ms | 2644 KB | Output is correct |
38 | Correct | 2 ms | 2644 KB | Output is correct |
39 | Correct | 4 ms | 2644 KB | Output is correct |
40 | Correct | 3 ms | 2644 KB | Output is correct |
41 | Correct | 3 ms | 2644 KB | Output is correct |
42 | Correct | 4 ms | 2644 KB | Output is correct |
43 | Correct | 3 ms | 2644 KB | Output is correct |
44 | Correct | 3 ms | 2644 KB | Output is correct |
45 | Correct | 2 ms | 2644 KB | Output is correct |
46 | Correct | 5 ms | 2900 KB | Output is correct |
47 | Correct | 5 ms | 2900 KB | Output is correct |
48 | Correct | 4 ms | 2900 KB | Output is correct |
49 | Correct | 986 ms | 3316 KB | Output is correct |
50 | Correct | 999 ms | 3276 KB | Output is correct |
51 | Correct | 973 ms | 3352 KB | Output is correct |
52 | Correct | 483 ms | 3124 KB | Output is correct |
53 | Correct | 455 ms | 3140 KB | Output is correct |
54 | Correct | 449 ms | 3136 KB | Output is correct |
55 | Correct | 482 ms | 3240 KB | Output is correct |
56 | Correct | 448 ms | 3064 KB | Output is correct |
57 | Correct | 5 ms | 2900 KB | Output is correct |
58 | Correct | 5 ms | 2988 KB | Output is correct |
59 | Correct | 5 ms | 2900 KB | Output is correct |
60 | Correct | 5 ms | 2900 KB | Output is correct |
61 | Correct | 479 ms | 3092 KB | Output is correct |
62 | Correct | 492 ms | 3148 KB | Output is correct |
63 | Correct | 482 ms | 3088 KB | Output is correct |
64 | Correct | 5 ms | 2900 KB | Output is correct |
65 | Correct | 5 ms | 2968 KB | Output is correct |
66 | Correct | 5 ms | 2900 KB | Output is correct |
67 | Correct | 4 ms | 2900 KB | Output is correct |
68 | Correct | 986 ms | 3312 KB | Output is correct |
69 | Correct | 441 ms | 3144 KB | Output is correct |
70 | Correct | 447 ms | 3148 KB | Output is correct |
71 | Correct | 476 ms | 3156 KB | Output is correct |
72 | Correct | 5 ms | 2900 KB | Output is correct |
73 | Correct | 5 ms | 2988 KB | Output is correct |
74 | Correct | 485 ms | 3136 KB | Output is correct |
75 | Correct | 213 ms | 3052 KB | Output is correct |
76 | Correct | 129 ms | 3028 KB | Output is correct |
77 | Correct | 102 ms | 3016 KB | Output is correct |
78 | Correct | 222 ms | 3048 KB | Output is correct |
79 | Correct | 129 ms | 3028 KB | Output is correct |
80 | Correct | 99 ms | 3004 KB | Output is correct |
81 | Correct | 219 ms | 3060 KB | Output is correct |
82 | Correct | 141 ms | 3028 KB | Output is correct |
83 | Correct | 104 ms | 3008 KB | Output is correct |
84 | Correct | 218 ms | 3044 KB | Output is correct |
85 | Correct | 143 ms | 3028 KB | Output is correct |
86 | Correct | 102 ms | 3012 KB | Output is correct |
87 | Correct | 11 ms | 3420 KB | Output is correct |
88 | Correct | 32 ms | 4848 KB | Output is correct |
89 | Correct | 146 ms | 10160 KB | Output is correct |
90 | Correct | 130 ms | 10072 KB | Output is correct |
91 | Correct | 141 ms | 10040 KB | Output is correct |
92 | Execution timed out | 2071 ms | 12548 KB | Time limit exceeded |
93 | Halted | 0 ms | 0 KB | - |