# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
31083 |
2017-08-06T17:00:23 Z |
WhipppedCream |
Race (IOI11_race) |
C++14 |
|
1327 ms |
38380 KB |
#include <bits/stdc++.h>
#include "race.h"
#define ii pair<int, int>
#define X first
#define Y second
#define pb push_back
#define vi vector<int>
#define vii vector< pair<int, int> >
#define iii pair< ii, int >
typedef long long ll;
using namespace std;
vector< ii > adj[200005];
int use[200005];
int deg[200005];
int maxnow[200005];
int mic[200005];
void memsetNode(int u, int par)
{
mic[u] = -1;
maxnow[u] = 0;
//printf("set 0 at %d\n", u);
for(int i = 0; i< (int) adj[u].size(); i++)
{
int v = adj[u][i].X;
if(use[v]) continue;
if(v == par) continue;
memsetNode(v, u);
}
}
int cnt(int u, int par)
{
if(mic[u] != -1) return mic[u];
int sum = 1;
for(int i = 0; i< (int) adj[u].size(); i++)
{
int v = adj[u][i].X;
if(use[v]) continue;
if(v == par) continue;
sum += cnt(v, u);
}
//printf("computed %d %d\n", u, par);
return mic[u] = sum;
}
void update(int u, int par, int book)
{
//printf("update %d %d %d\n", u, par, book);
maxnow[u] = max(maxnow[u], book);
int sm = 1;
for(int i = 0; i< (int) adj[u].size(); i++)
{
ii k = adj[u][i];
if(k.X == par) continue;
if(use[k.X]) continue;
maxnow[k.X] = max(maxnow[k.X], 1+book);
maxnow[u] = max(maxnow[u], cnt(k.X, u));
//printf("added (%d, %d)", k.X, u);
sm += cnt(k.X, u);
}
sm += book;
//printf("sm is %d for %d\n", sm, u);
for(int i = 0; i< (int) adj[u].size(); i++)
{
ii k = adj[u][i];
if(k.X == par) continue;
if(use[k.X]) continue;
update(k.X, u, sm - cnt(k.X, u));
}
}
int findBest(int u, int par)
{
int best = -1;
//printf("%d: %d\n", u, maxnow[u]);
for(int i = 0; i< (int) adj[u].size(); i++)
{
int v = adj[u][i].X;
if(use[v]) continue;
if(v == par) continue;
int here = findBest(v, u);
if(best == -1 || maxnow[here]< maxnow[best]) best = here;
}
int res;
if(best == -1) res = u;
else if(maxnow[best]< maxnow[u]) res = best;
else res = u;
//printf("of size %d\n", maxnow[res]);
return res;
}
int memsetcnt = 0;
void findNode(int u, int par)
{
//printf("its me\n");
int st = u;
//printf("--------memsetting %d %d\n", u, par);
memsetcnt++;
//if(memsetcnt % 10000 == 0) printf("%d\n", memsetcnt/1000);
memsetNode(u, par);
update(st, par, 0);
//printf("kuy\n");
}
int bestPath[1000005];
vii joe;
void diep(int u, int par, int dist, int len)
{
if(dist > 1000000) return;
joe.pb(ii(dist, len));
//printf("%d %d %d %d\n", u, par, dist, len);
for(int i = 0; i< (int) adj[u].size(); i++)
{
int v = adj[u][i].X;
int w = adj[u][i].Y;
if(v == par) continue;
if(use[v]) continue;
diep(v, u, dist+w, len+1);
}
}
int k;
int n;
int solve(int u, int par)
{
//memset maxnow 0
//memset mic
//printf("hello\n");
findNode(u, par);
int root = findBest(u, par);
//printf("--------------root is %d\n", root);
vector<int> Set;
int best = 1e9;
bestPath[0] = 0;
for(int i = 0; i< (int) adj[root].size(); i++)
{
joe.clear();
int v = adj[root][i].X;
if(v == par) continue;
if(use[v]) continue;
diep(v, root, adj[root][i].Y, 1);
for(int j = 0; j< (int) joe.size(); j++)
{
Set.pb(joe[j].X);
if(k-joe[j].X >= 0 && bestPath[k-joe[j].X] != -1)
{
best = min(best, bestPath[k-joe[j].X] + joe[j].Y);
}
}
for(int j = 0; j< (int) joe.size(); j++)
{
if(bestPath[joe[j].X] == -1 || bestPath[joe[j].X] > joe[j].Y) bestPath[joe[j].X] = joe[j].Y;
//lprintf("%d\n", joe[j].X);
}
}
use[root] = 1;
for(int i = 0; i< (int) Set.size(); i++)
{
bestPath[Set[i]] = -1;
}
for(int i = 0; i< (int) adj[root].size(); i++)
{
int v = adj[root][i].X;
if(v == par) continue;
if(use[v]) continue;
best = min(best, solve(v, root));
}
return best;
}
int best_path(int N, int K, int H[][2], int L[])
{
memset(bestPath, -1, sizeof bestPath);
memset(mic, -1, sizeof mic);
//freopen("grader.in.16", "r", stdin);
n = N; k = K;
for(int i = 0; i< n-1; i++)
{
int a, b, w;
a = H[i][0], b = H[i][1], w = L[i];
adj[a].pb(ii(b, w));
adj[b].pb(ii(a, w));
deg[a]++; deg[b]++;
}
int res = solve(0, -1);
if(res == 1e9) return -1;
return res;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
9848 KB |
Output is correct |
2 |
Correct |
11 ms |
9848 KB |
Output is correct |
3 |
Correct |
10 ms |
9892 KB |
Output is correct |
4 |
Correct |
10 ms |
10016 KB |
Output is correct |
5 |
Correct |
10 ms |
10016 KB |
Output is correct |
6 |
Correct |
10 ms |
10016 KB |
Output is correct |
7 |
Correct |
10 ms |
10016 KB |
Output is correct |
8 |
Correct |
9 ms |
10016 KB |
Output is correct |
9 |
Correct |
9 ms |
10016 KB |
Output is correct |
10 |
Correct |
10 ms |
10016 KB |
Output is correct |
11 |
Correct |
11 ms |
10016 KB |
Output is correct |
12 |
Correct |
10 ms |
10016 KB |
Output is correct |
13 |
Correct |
10 ms |
10016 KB |
Output is correct |
14 |
Correct |
10 ms |
10016 KB |
Output is correct |
15 |
Correct |
10 ms |
10016 KB |
Output is correct |
16 |
Correct |
10 ms |
10092 KB |
Output is correct |
17 |
Correct |
9 ms |
10092 KB |
Output is correct |
18 |
Correct |
10 ms |
10092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
9848 KB |
Output is correct |
2 |
Correct |
11 ms |
9848 KB |
Output is correct |
3 |
Correct |
10 ms |
9892 KB |
Output is correct |
4 |
Correct |
10 ms |
10016 KB |
Output is correct |
5 |
Correct |
10 ms |
10016 KB |
Output is correct |
6 |
Correct |
10 ms |
10016 KB |
Output is correct |
7 |
Correct |
10 ms |
10016 KB |
Output is correct |
8 |
Correct |
9 ms |
10016 KB |
Output is correct |
9 |
Correct |
9 ms |
10016 KB |
Output is correct |
10 |
Correct |
10 ms |
10016 KB |
Output is correct |
11 |
Correct |
11 ms |
10016 KB |
Output is correct |
12 |
Correct |
10 ms |
10016 KB |
Output is correct |
13 |
Correct |
10 ms |
10016 KB |
Output is correct |
14 |
Correct |
10 ms |
10016 KB |
Output is correct |
15 |
Correct |
10 ms |
10016 KB |
Output is correct |
16 |
Correct |
10 ms |
10092 KB |
Output is correct |
17 |
Correct |
9 ms |
10092 KB |
Output is correct |
18 |
Correct |
10 ms |
10092 KB |
Output is correct |
19 |
Correct |
10 ms |
10092 KB |
Output is correct |
20 |
Correct |
9 ms |
10092 KB |
Output is correct |
21 |
Correct |
11 ms |
10092 KB |
Output is correct |
22 |
Correct |
10 ms |
10108 KB |
Output is correct |
23 |
Correct |
12 ms |
10108 KB |
Output is correct |
24 |
Correct |
10 ms |
10108 KB |
Output is correct |
25 |
Correct |
13 ms |
10108 KB |
Output is correct |
26 |
Correct |
11 ms |
10108 KB |
Output is correct |
27 |
Correct |
11 ms |
10108 KB |
Output is correct |
28 |
Correct |
10 ms |
10108 KB |
Output is correct |
29 |
Correct |
12 ms |
10108 KB |
Output is correct |
30 |
Correct |
10 ms |
10108 KB |
Output is correct |
31 |
Correct |
11 ms |
10108 KB |
Output is correct |
32 |
Correct |
11 ms |
10108 KB |
Output is correct |
33 |
Correct |
11 ms |
10108 KB |
Output is correct |
34 |
Correct |
12 ms |
10108 KB |
Output is correct |
35 |
Correct |
11 ms |
10108 KB |
Output is correct |
36 |
Correct |
10 ms |
10108 KB |
Output is correct |
37 |
Correct |
11 ms |
10108 KB |
Output is correct |
38 |
Correct |
10 ms |
10108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
9848 KB |
Output is correct |
2 |
Correct |
11 ms |
9848 KB |
Output is correct |
3 |
Correct |
10 ms |
9892 KB |
Output is correct |
4 |
Correct |
10 ms |
10016 KB |
Output is correct |
5 |
Correct |
10 ms |
10016 KB |
Output is correct |
6 |
Correct |
10 ms |
10016 KB |
Output is correct |
7 |
Correct |
10 ms |
10016 KB |
Output is correct |
8 |
Correct |
9 ms |
10016 KB |
Output is correct |
9 |
Correct |
9 ms |
10016 KB |
Output is correct |
10 |
Correct |
10 ms |
10016 KB |
Output is correct |
11 |
Correct |
11 ms |
10016 KB |
Output is correct |
12 |
Correct |
10 ms |
10016 KB |
Output is correct |
13 |
Correct |
10 ms |
10016 KB |
Output is correct |
14 |
Correct |
10 ms |
10016 KB |
Output is correct |
15 |
Correct |
10 ms |
10016 KB |
Output is correct |
16 |
Correct |
10 ms |
10092 KB |
Output is correct |
17 |
Correct |
9 ms |
10092 KB |
Output is correct |
18 |
Correct |
10 ms |
10092 KB |
Output is correct |
19 |
Correct |
346 ms |
17248 KB |
Output is correct |
20 |
Correct |
306 ms |
17264 KB |
Output is correct |
21 |
Correct |
371 ms |
17264 KB |
Output is correct |
22 |
Correct |
352 ms |
17264 KB |
Output is correct |
23 |
Correct |
338 ms |
17276 KB |
Output is correct |
24 |
Correct |
155 ms |
17276 KB |
Output is correct |
25 |
Correct |
346 ms |
20856 KB |
Output is correct |
26 |
Correct |
186 ms |
24496 KB |
Output is correct |
27 |
Correct |
411 ms |
24496 KB |
Output is correct |
28 |
Correct |
1061 ms |
37448 KB |
Output is correct |
29 |
Correct |
1154 ms |
37448 KB |
Output is correct |
30 |
Correct |
364 ms |
37448 KB |
Output is correct |
31 |
Correct |
372 ms |
37448 KB |
Output is correct |
32 |
Correct |
531 ms |
37448 KB |
Output is correct |
33 |
Correct |
835 ms |
37448 KB |
Output is correct |
34 |
Correct |
705 ms |
37448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
9848 KB |
Output is correct |
2 |
Correct |
11 ms |
9848 KB |
Output is correct |
3 |
Correct |
10 ms |
9892 KB |
Output is correct |
4 |
Correct |
10 ms |
10016 KB |
Output is correct |
5 |
Correct |
10 ms |
10016 KB |
Output is correct |
6 |
Correct |
10 ms |
10016 KB |
Output is correct |
7 |
Correct |
10 ms |
10016 KB |
Output is correct |
8 |
Correct |
9 ms |
10016 KB |
Output is correct |
9 |
Correct |
9 ms |
10016 KB |
Output is correct |
10 |
Correct |
10 ms |
10016 KB |
Output is correct |
11 |
Correct |
11 ms |
10016 KB |
Output is correct |
12 |
Correct |
10 ms |
10016 KB |
Output is correct |
13 |
Correct |
10 ms |
10016 KB |
Output is correct |
14 |
Correct |
10 ms |
10016 KB |
Output is correct |
15 |
Correct |
10 ms |
10016 KB |
Output is correct |
16 |
Correct |
10 ms |
10092 KB |
Output is correct |
17 |
Correct |
9 ms |
10092 KB |
Output is correct |
18 |
Correct |
10 ms |
10092 KB |
Output is correct |
19 |
Correct |
10 ms |
10092 KB |
Output is correct |
20 |
Correct |
9 ms |
10092 KB |
Output is correct |
21 |
Correct |
11 ms |
10092 KB |
Output is correct |
22 |
Correct |
10 ms |
10108 KB |
Output is correct |
23 |
Correct |
12 ms |
10108 KB |
Output is correct |
24 |
Correct |
10 ms |
10108 KB |
Output is correct |
25 |
Correct |
13 ms |
10108 KB |
Output is correct |
26 |
Correct |
11 ms |
10108 KB |
Output is correct |
27 |
Correct |
11 ms |
10108 KB |
Output is correct |
28 |
Correct |
10 ms |
10108 KB |
Output is correct |
29 |
Correct |
12 ms |
10108 KB |
Output is correct |
30 |
Correct |
10 ms |
10108 KB |
Output is correct |
31 |
Correct |
11 ms |
10108 KB |
Output is correct |
32 |
Correct |
11 ms |
10108 KB |
Output is correct |
33 |
Correct |
11 ms |
10108 KB |
Output is correct |
34 |
Correct |
12 ms |
10108 KB |
Output is correct |
35 |
Correct |
11 ms |
10108 KB |
Output is correct |
36 |
Correct |
10 ms |
10108 KB |
Output is correct |
37 |
Correct |
11 ms |
10108 KB |
Output is correct |
38 |
Correct |
10 ms |
10108 KB |
Output is correct |
39 |
Correct |
346 ms |
17248 KB |
Output is correct |
40 |
Correct |
306 ms |
17264 KB |
Output is correct |
41 |
Correct |
371 ms |
17264 KB |
Output is correct |
42 |
Correct |
352 ms |
17264 KB |
Output is correct |
43 |
Correct |
338 ms |
17276 KB |
Output is correct |
44 |
Correct |
155 ms |
17276 KB |
Output is correct |
45 |
Correct |
346 ms |
20856 KB |
Output is correct |
46 |
Correct |
186 ms |
24496 KB |
Output is correct |
47 |
Correct |
411 ms |
24496 KB |
Output is correct |
48 |
Correct |
1061 ms |
37448 KB |
Output is correct |
49 |
Correct |
1154 ms |
37448 KB |
Output is correct |
50 |
Correct |
364 ms |
37448 KB |
Output is correct |
51 |
Correct |
372 ms |
37448 KB |
Output is correct |
52 |
Correct |
531 ms |
37448 KB |
Output is correct |
53 |
Correct |
835 ms |
37448 KB |
Output is correct |
54 |
Correct |
705 ms |
37448 KB |
Output is correct |
55 |
Correct |
28 ms |
37448 KB |
Output is correct |
56 |
Correct |
27 ms |
37448 KB |
Output is correct |
57 |
Correct |
161 ms |
37448 KB |
Output is correct |
58 |
Correct |
60 ms |
37448 KB |
Output is correct |
59 |
Correct |
194 ms |
37448 KB |
Output is correct |
60 |
Correct |
1327 ms |
38380 KB |
Output is correct |
61 |
Correct |
375 ms |
38380 KB |
Output is correct |
62 |
Correct |
323 ms |
38380 KB |
Output is correct |
63 |
Correct |
556 ms |
38380 KB |
Output is correct |
64 |
Correct |
1062 ms |
38380 KB |
Output is correct |
65 |
Correct |
565 ms |
38380 KB |
Output is correct |
66 |
Correct |
857 ms |
38380 KB |
Output is correct |
67 |
Correct |
197 ms |
38380 KB |
Output is correct |
68 |
Correct |
492 ms |
38380 KB |
Output is correct |
69 |
Correct |
528 ms |
38380 KB |
Output is correct |
70 |
Correct |
501 ms |
38380 KB |
Output is correct |