# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
106176 | 2019-04-17T04:53:48 Z | cki86201 | Election Campaign (JOI15_election_campaign) | C++11 | 445 ms | 32560 KB |
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <memory.h> #include <math.h> #include <assert.h> #include <stack> #include <queue> #include <map> #include <set> #include <string> #include <algorithm> #include <iostream> #include <functional> #include <unordered_set> #include <bitset> #include <time.h> #include <limits.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define Fi first #define Se second #define pb push_back #define szz(x) (int)x.size() #define rep(i,n) for(int i=0;i<n;i++) #define all(x) x.begin(),x.end() typedef tuple<int, int, int> t3; int N, M; vector <int> E[100010]; int In[100010][3]; vector <int> qs[100010]; int ST[100010], EN[100010], cs; int dep[100010]; int up[100010][20]; void pdfs(int x, int fa) { ST[x] = ++cs; for(int e : E[x]) if(e != fa) { dep[e] = dep[x] + 1; up[e][0] = x; for(int i=1;i<20;i++) up[e][i] = up[ up[e][i-1] ][i-1]; pdfs(e, x); } EN[x] = cs; } int get_lca(int x, int y) { if(dep[x] < dep[y]) swap(x, y); rep(i, 20) if(1<<i & (dep[x] - dep[y])) x = up[x][i]; for(int i=19;i>=0;i--) if(up[x][i] != up[y][i]) x = up[x][i], y = up[y][i]; return x == y ? x : up[x][0]; } ll T[100010]; void update_s(int x, ll v) { int l = ST[x], r = EN[x]; for(int i=l;i<=N;i+=(i&-i)) T[i] += v; for(int i=r+1;i<=N;i+=(i&-i)) T[i] -= v; } ll read(int x) { ll res = 0; for(int i=ST[x];i;i-=(i&-i)) res += T[i]; return res; } ll A[100010], B[100010]; void dfs(int x, int fa) { for(int e : E[x]) if(e != fa) { dfs(e, x); B[x] += A[e]; } A[x] = B[x]; for(int e : qs[x]) { int u = In[e][0], v = In[e][1], cost = In[e][2]; ll val = B[x] + cost - read(u) - read(v); if(A[x] < val) A[x] = val; } update_s(x, A[x] - B[x]); } int main() { scanf("%d", &N); for(int i=1;i<N;i++) { int x, y; scanf("%d%d", &x, &y); E[x].pb(y); E[y].pb(x); } scanf("%d", &M); pdfs(1, -1); for(int i=1;i<=M;i++) { int x, y, z; scanf("%d%d%d", &x, &y, &z); int lca = get_lca(x, y); qs[lca].pb(i); In[i][0] = x; In[i][1] = y; In[i][2] = z; } dfs(1, -1); printf("%lld\n", A[1]); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 4992 KB | Output is correct |
2 | Correct | 8 ms | 5120 KB | Output is correct |
3 | Correct | 6 ms | 5120 KB | Output is correct |
4 | Correct | 8 ms | 5248 KB | Output is correct |
5 | Correct | 189 ms | 20988 KB | Output is correct |
6 | Correct | 87 ms | 28536 KB | Output is correct |
7 | Correct | 162 ms | 25752 KB | Output is correct |
8 | Correct | 148 ms | 20548 KB | Output is correct |
9 | Correct | 170 ms | 24312 KB | Output is correct |
10 | Correct | 141 ms | 20476 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 4992 KB | Output is correct |
2 | Correct | 6 ms | 4992 KB | Output is correct |
3 | Correct | 6 ms | 5248 KB | Output is correct |
4 | Correct | 199 ms | 32120 KB | Output is correct |
5 | Correct | 172 ms | 32136 KB | Output is correct |
6 | Correct | 175 ms | 32148 KB | Output is correct |
7 | Correct | 223 ms | 32088 KB | Output is correct |
8 | Correct | 172 ms | 31992 KB | Output is correct |
9 | Correct | 222 ms | 32120 KB | Output is correct |
10 | Correct | 265 ms | 32200 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 4992 KB | Output is correct |
2 | Correct | 6 ms | 4992 KB | Output is correct |
3 | Correct | 6 ms | 5248 KB | Output is correct |
4 | Correct | 199 ms | 32120 KB | Output is correct |
5 | Correct | 172 ms | 32136 KB | Output is correct |
6 | Correct | 175 ms | 32148 KB | Output is correct |
7 | Correct | 223 ms | 32088 KB | Output is correct |
8 | Correct | 172 ms | 31992 KB | Output is correct |
9 | Correct | 222 ms | 32120 KB | Output is correct |
10 | Correct | 265 ms | 32200 KB | Output is correct |
11 | Correct | 19 ms | 6008 KB | Output is correct |
12 | Correct | 191 ms | 32308 KB | Output is correct |
13 | Correct | 218 ms | 32312 KB | Output is correct |
14 | Correct | 196 ms | 32560 KB | Output is correct |
15 | Correct | 218 ms | 32508 KB | Output is correct |
16 | Correct | 217 ms | 32380 KB | Output is correct |
17 | Correct | 260 ms | 32340 KB | Output is correct |
18 | Correct | 291 ms | 32348 KB | Output is correct |
19 | Correct | 225 ms | 32368 KB | Output is correct |
20 | Correct | 274 ms | 32376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 301 ms | 24068 KB | Output is correct |
2 | Correct | 250 ms | 32324 KB | Output is correct |
3 | Correct | 321 ms | 29048 KB | Output is correct |
4 | Correct | 186 ms | 23540 KB | Output is correct |
5 | Correct | 354 ms | 28628 KB | Output is correct |
6 | Correct | 215 ms | 23476 KB | Output is correct |
7 | Correct | 370 ms | 28280 KB | Output is correct |
8 | Correct | 334 ms | 24328 KB | Output is correct |
9 | Correct | 282 ms | 32204 KB | Output is correct |
10 | Correct | 445 ms | 27552 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 4992 KB | Output is correct |
2 | Correct | 8 ms | 5120 KB | Output is correct |
3 | Correct | 6 ms | 5120 KB | Output is correct |
4 | Correct | 8 ms | 5248 KB | Output is correct |
5 | Correct | 189 ms | 20988 KB | Output is correct |
6 | Correct | 87 ms | 28536 KB | Output is correct |
7 | Correct | 162 ms | 25752 KB | Output is correct |
8 | Correct | 148 ms | 20548 KB | Output is correct |
9 | Correct | 170 ms | 24312 KB | Output is correct |
10 | Correct | 141 ms | 20476 KB | Output is correct |
11 | Correct | 9 ms | 5248 KB | Output is correct |
12 | Correct | 8 ms | 5376 KB | Output is correct |
13 | Correct | 8 ms | 5376 KB | Output is correct |
14 | Correct | 8 ms | 5248 KB | Output is correct |
15 | Correct | 7 ms | 5248 KB | Output is correct |
16 | Correct | 9 ms | 5376 KB | Output is correct |
17 | Correct | 9 ms | 5248 KB | Output is correct |
18 | Correct | 8 ms | 5272 KB | Output is correct |
19 | Correct | 9 ms | 5248 KB | Output is correct |
20 | Correct | 8 ms | 5376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 4992 KB | Output is correct |
2 | Correct | 8 ms | 5120 KB | Output is correct |
3 | Correct | 6 ms | 5120 KB | Output is correct |
4 | Correct | 8 ms | 5248 KB | Output is correct |
5 | Correct | 189 ms | 20988 KB | Output is correct |
6 | Correct | 87 ms | 28536 KB | Output is correct |
7 | Correct | 162 ms | 25752 KB | Output is correct |
8 | Correct | 148 ms | 20548 KB | Output is correct |
9 | Correct | 170 ms | 24312 KB | Output is correct |
10 | Correct | 141 ms | 20476 KB | Output is correct |
11 | Correct | 7 ms | 4992 KB | Output is correct |
12 | Correct | 6 ms | 4992 KB | Output is correct |
13 | Correct | 6 ms | 5248 KB | Output is correct |
14 | Correct | 199 ms | 32120 KB | Output is correct |
15 | Correct | 172 ms | 32136 KB | Output is correct |
16 | Correct | 175 ms | 32148 KB | Output is correct |
17 | Correct | 223 ms | 32088 KB | Output is correct |
18 | Correct | 172 ms | 31992 KB | Output is correct |
19 | Correct | 222 ms | 32120 KB | Output is correct |
20 | Correct | 265 ms | 32200 KB | Output is correct |
21 | Correct | 19 ms | 6008 KB | Output is correct |
22 | Correct | 191 ms | 32308 KB | Output is correct |
23 | Correct | 218 ms | 32312 KB | Output is correct |
24 | Correct | 196 ms | 32560 KB | Output is correct |
25 | Correct | 218 ms | 32508 KB | Output is correct |
26 | Correct | 217 ms | 32380 KB | Output is correct |
27 | Correct | 260 ms | 32340 KB | Output is correct |
28 | Correct | 291 ms | 32348 KB | Output is correct |
29 | Correct | 225 ms | 32368 KB | Output is correct |
30 | Correct | 274 ms | 32376 KB | Output is correct |
31 | Correct | 301 ms | 24068 KB | Output is correct |
32 | Correct | 250 ms | 32324 KB | Output is correct |
33 | Correct | 321 ms | 29048 KB | Output is correct |
34 | Correct | 186 ms | 23540 KB | Output is correct |
35 | Correct | 354 ms | 28628 KB | Output is correct |
36 | Correct | 215 ms | 23476 KB | Output is correct |
37 | Correct | 370 ms | 28280 KB | Output is correct |
38 | Correct | 334 ms | 24328 KB | Output is correct |
39 | Correct | 282 ms | 32204 KB | Output is correct |
40 | Correct | 445 ms | 27552 KB | Output is correct |
41 | Correct | 9 ms | 5248 KB | Output is correct |
42 | Correct | 8 ms | 5376 KB | Output is correct |
43 | Correct | 8 ms | 5376 KB | Output is correct |
44 | Correct | 8 ms | 5248 KB | Output is correct |
45 | Correct | 7 ms | 5248 KB | Output is correct |
46 | Correct | 9 ms | 5376 KB | Output is correct |
47 | Correct | 9 ms | 5248 KB | Output is correct |
48 | Correct | 8 ms | 5272 KB | Output is correct |
49 | Correct | 9 ms | 5248 KB | Output is correct |
50 | Correct | 8 ms | 5376 KB | Output is correct |
51 | Correct | 295 ms | 24568 KB | Output is correct |
52 | Correct | 259 ms | 32364 KB | Output is correct |
53 | Correct | 425 ms | 27764 KB | Output is correct |
54 | Correct | 277 ms | 23800 KB | Output is correct |
55 | Correct | 279 ms | 24184 KB | Output is correct |
56 | Correct | 256 ms | 32492 KB | Output is correct |
57 | Correct | 379 ms | 28736 KB | Output is correct |
58 | Correct | 242 ms | 23772 KB | Output is correct |
59 | Correct | 270 ms | 24568 KB | Output is correct |
60 | Correct | 192 ms | 32376 KB | Output is correct |
61 | Correct | 302 ms | 28680 KB | Output is correct |
62 | Correct | 241 ms | 23728 KB | Output is correct |
63 | Correct | 328 ms | 24268 KB | Output is correct |
64 | Correct | 240 ms | 32376 KB | Output is correct |
65 | Correct | 412 ms | 28404 KB | Output is correct |
66 | Correct | 280 ms | 23928 KB | Output is correct |
67 | Correct | 279 ms | 24048 KB | Output is correct |
68 | Correct | 259 ms | 32400 KB | Output is correct |
69 | Correct | 335 ms | 27432 KB | Output is correct |
70 | Correct | 244 ms | 23780 KB | Output is correct |