# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
101193 |
2019-03-17T09:44:25 Z |
davitmarg |
Race (IOI11_race) |
C++17 |
|
3000 ms |
24140 KB |
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iterator>
#include <ctype.h>
#include <stdlib.h>
#include <cassert>
#include <fstream>
#ifndef death
#include "race.h"
#endif
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;
int n, k, d[200005], used[200005], used1[200005], usedc[200005], ans = mod,color;
vector<pair<int, LL>> g[200005];
map<LL, int> dp;
vector<pair<LL, int>> upd;
void dfs1(int v)
{
usedc[v] = 1;
d[v] = 1;
for (int i = 0; i<g[v].size(); i++)
{
int to = g[v][i].first;
if (usedc[to])
continue;
dfs1(to);
d[v] += d[to];
}
}
int centroid(int v)
{
usedc[v] = 1;
for (int i = 0; i<g[v].size(); i++)
{
int to = g[v][i].first;
if (usedc[to])
continue;
if (d[to] > d[v] / 2)
return centroid(to);
}
return v;
}
void dfs(int v, LL dist, int depth)
{
used[v] = color;
if (dp[dist] == 0)
dp[dist] = mod;
if (k > dist && dp[k - dist] == 0)
dp[k - dist] = mod;
upd.PB(MP(dist, depth));
if (k > dist)
ans = min(depth + dp[k - dist], ans);
else if (dist == k)
ans = min(depth, ans);
for (int i = 0; i<g[v].size(); i++)
{
int to = g[v][i].first;
LL D = g[v][i].second;
if (used[to]==color || used1[to])
continue;
dfs(to, dist + D, depth + 1);
}
}
void solve(int v)
{
color++;
used1[v] = 1;
vector<int> nxt;
dp.clear();
for (int i = 0; i<g[v].size(); i++)
{
int to = g[v][i].first;
LL D = g[v][i].second;
if (used1[to])
continue;
nxt.PB(to);
upd.resize(0);
dfs(to, D, 1);
for (int j = 0; j < upd.size(); j++)
dp[upd[j].first] = min(upd[j].second, dp[upd[j].first]);
}
for (int i = 0; i < nxt.size(); i++)
solve(centroid(nxt[i]));
}
int Main()
{
dfs1(1);
memset(usedc, 0, sizeof(int)*(n + 2));
int c = centroid(1);
//memset(usedc, 0, sizeof(int)*(n + 2));
solve(c);
if (ans == mod)
ans = -1;
return 0;
}
int best_path(int N, int K, int h[][2], int l[])
{
n = N;
k = K;
for (int i = 0; i < n-1; i++)
{
h[i][0]++;
h[i][1]++;
g[h[i][0]].PB(MP(h[i][1], l[i]));
g[h[i][1]].PB(MP(h[i][0], l[i]));
}
Main();
return ans;
}
#ifdef death
int main()
{
cin >> n >> k;
for (int i = 0; i < n - 1; i++)
{
int a, b;
LL D;
cin >> a >> b >> D;
a++;
b++;
g[a].PB(MP(b, D));
g[b].PB(MP(a, D));
}
Main();
cout << ans << endl;
return 0;
}
#endif
/*
*/
Compilation message
race.cpp: In function 'void dfs1(int)':
race.cpp:39:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i<g[v].size(); i++)
~^~~~~~~~~~~~
race.cpp: In function 'int centroid(int)':
race.cpp:52:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i<g[v].size(); i++)
~^~~~~~~~~~~~
race.cpp: In function 'void dfs(int, long long int, int)':
race.cpp:80:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i<g[v].size(); i++)
~^~~~~~~~~~~~
race.cpp: In function 'void solve(int)':
race.cpp:98:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i<g[v].size(); i++)
~^~~~~~~~~~~~
race.cpp:107:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < upd.size(); j++)
~~^~~~~~~~~~~~
race.cpp:110:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < nxt.size(); i++)
~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5120 KB |
Output is correct |
2 |
Correct |
8 ms |
5120 KB |
Output is correct |
3 |
Correct |
8 ms |
5120 KB |
Output is correct |
4 |
Correct |
9 ms |
5120 KB |
Output is correct |
5 |
Correct |
7 ms |
5120 KB |
Output is correct |
6 |
Correct |
8 ms |
5120 KB |
Output is correct |
7 |
Correct |
7 ms |
5120 KB |
Output is correct |
8 |
Correct |
7 ms |
5120 KB |
Output is correct |
9 |
Correct |
7 ms |
5120 KB |
Output is correct |
10 |
Correct |
8 ms |
5120 KB |
Output is correct |
11 |
Correct |
8 ms |
5120 KB |
Output is correct |
12 |
Correct |
8 ms |
5120 KB |
Output is correct |
13 |
Correct |
8 ms |
5120 KB |
Output is correct |
14 |
Correct |
9 ms |
5120 KB |
Output is correct |
15 |
Correct |
7 ms |
5120 KB |
Output is correct |
16 |
Correct |
7 ms |
5120 KB |
Output is correct |
17 |
Correct |
9 ms |
5120 KB |
Output is correct |
18 |
Correct |
7 ms |
5120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5120 KB |
Output is correct |
2 |
Correct |
8 ms |
5120 KB |
Output is correct |
3 |
Correct |
8 ms |
5120 KB |
Output is correct |
4 |
Correct |
9 ms |
5120 KB |
Output is correct |
5 |
Correct |
7 ms |
5120 KB |
Output is correct |
6 |
Correct |
8 ms |
5120 KB |
Output is correct |
7 |
Correct |
7 ms |
5120 KB |
Output is correct |
8 |
Correct |
7 ms |
5120 KB |
Output is correct |
9 |
Correct |
7 ms |
5120 KB |
Output is correct |
10 |
Correct |
8 ms |
5120 KB |
Output is correct |
11 |
Correct |
8 ms |
5120 KB |
Output is correct |
12 |
Correct |
8 ms |
5120 KB |
Output is correct |
13 |
Correct |
8 ms |
5120 KB |
Output is correct |
14 |
Correct |
9 ms |
5120 KB |
Output is correct |
15 |
Correct |
7 ms |
5120 KB |
Output is correct |
16 |
Correct |
7 ms |
5120 KB |
Output is correct |
17 |
Correct |
9 ms |
5120 KB |
Output is correct |
18 |
Correct |
7 ms |
5120 KB |
Output is correct |
19 |
Correct |
6 ms |
4992 KB |
Output is correct |
20 |
Correct |
6 ms |
4992 KB |
Output is correct |
21 |
Correct |
10 ms |
5248 KB |
Output is correct |
22 |
Correct |
15 ms |
5248 KB |
Output is correct |
23 |
Correct |
16 ms |
5248 KB |
Output is correct |
24 |
Correct |
9 ms |
5376 KB |
Output is correct |
25 |
Correct |
12 ms |
5248 KB |
Output is correct |
26 |
Correct |
10 ms |
5248 KB |
Output is correct |
27 |
Correct |
8 ms |
5248 KB |
Output is correct |
28 |
Correct |
13 ms |
5248 KB |
Output is correct |
29 |
Correct |
10 ms |
5248 KB |
Output is correct |
30 |
Correct |
11 ms |
5248 KB |
Output is correct |
31 |
Correct |
10 ms |
5248 KB |
Output is correct |
32 |
Correct |
10 ms |
5376 KB |
Output is correct |
33 |
Correct |
23 ms |
5312 KB |
Output is correct |
34 |
Correct |
54 ms |
5248 KB |
Output is correct |
35 |
Correct |
57 ms |
5376 KB |
Output is correct |
36 |
Correct |
66 ms |
5496 KB |
Output is correct |
37 |
Correct |
107 ms |
5220 KB |
Output is correct |
38 |
Correct |
87 ms |
5248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5120 KB |
Output is correct |
2 |
Correct |
8 ms |
5120 KB |
Output is correct |
3 |
Correct |
8 ms |
5120 KB |
Output is correct |
4 |
Correct |
9 ms |
5120 KB |
Output is correct |
5 |
Correct |
7 ms |
5120 KB |
Output is correct |
6 |
Correct |
8 ms |
5120 KB |
Output is correct |
7 |
Correct |
7 ms |
5120 KB |
Output is correct |
8 |
Correct |
7 ms |
5120 KB |
Output is correct |
9 |
Correct |
7 ms |
5120 KB |
Output is correct |
10 |
Correct |
8 ms |
5120 KB |
Output is correct |
11 |
Correct |
8 ms |
5120 KB |
Output is correct |
12 |
Correct |
8 ms |
5120 KB |
Output is correct |
13 |
Correct |
8 ms |
5120 KB |
Output is correct |
14 |
Correct |
9 ms |
5120 KB |
Output is correct |
15 |
Correct |
7 ms |
5120 KB |
Output is correct |
16 |
Correct |
7 ms |
5120 KB |
Output is correct |
17 |
Correct |
9 ms |
5120 KB |
Output is correct |
18 |
Correct |
7 ms |
5120 KB |
Output is correct |
19 |
Correct |
1446 ms |
14732 KB |
Output is correct |
20 |
Correct |
722 ms |
13980 KB |
Output is correct |
21 |
Correct |
880 ms |
14016 KB |
Output is correct |
22 |
Correct |
514 ms |
13816 KB |
Output is correct |
23 |
Correct |
672 ms |
15124 KB |
Output is correct |
24 |
Correct |
220 ms |
12936 KB |
Output is correct |
25 |
Execution timed out |
3102 ms |
24140 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5120 KB |
Output is correct |
2 |
Correct |
8 ms |
5120 KB |
Output is correct |
3 |
Correct |
8 ms |
5120 KB |
Output is correct |
4 |
Correct |
9 ms |
5120 KB |
Output is correct |
5 |
Correct |
7 ms |
5120 KB |
Output is correct |
6 |
Correct |
8 ms |
5120 KB |
Output is correct |
7 |
Correct |
7 ms |
5120 KB |
Output is correct |
8 |
Correct |
7 ms |
5120 KB |
Output is correct |
9 |
Correct |
7 ms |
5120 KB |
Output is correct |
10 |
Correct |
8 ms |
5120 KB |
Output is correct |
11 |
Correct |
8 ms |
5120 KB |
Output is correct |
12 |
Correct |
8 ms |
5120 KB |
Output is correct |
13 |
Correct |
8 ms |
5120 KB |
Output is correct |
14 |
Correct |
9 ms |
5120 KB |
Output is correct |
15 |
Correct |
7 ms |
5120 KB |
Output is correct |
16 |
Correct |
7 ms |
5120 KB |
Output is correct |
17 |
Correct |
9 ms |
5120 KB |
Output is correct |
18 |
Correct |
7 ms |
5120 KB |
Output is correct |
19 |
Correct |
6 ms |
4992 KB |
Output is correct |
20 |
Correct |
6 ms |
4992 KB |
Output is correct |
21 |
Correct |
10 ms |
5248 KB |
Output is correct |
22 |
Correct |
15 ms |
5248 KB |
Output is correct |
23 |
Correct |
16 ms |
5248 KB |
Output is correct |
24 |
Correct |
9 ms |
5376 KB |
Output is correct |
25 |
Correct |
12 ms |
5248 KB |
Output is correct |
26 |
Correct |
10 ms |
5248 KB |
Output is correct |
27 |
Correct |
8 ms |
5248 KB |
Output is correct |
28 |
Correct |
13 ms |
5248 KB |
Output is correct |
29 |
Correct |
10 ms |
5248 KB |
Output is correct |
30 |
Correct |
11 ms |
5248 KB |
Output is correct |
31 |
Correct |
10 ms |
5248 KB |
Output is correct |
32 |
Correct |
10 ms |
5376 KB |
Output is correct |
33 |
Correct |
23 ms |
5312 KB |
Output is correct |
34 |
Correct |
54 ms |
5248 KB |
Output is correct |
35 |
Correct |
57 ms |
5376 KB |
Output is correct |
36 |
Correct |
66 ms |
5496 KB |
Output is correct |
37 |
Correct |
107 ms |
5220 KB |
Output is correct |
38 |
Correct |
87 ms |
5248 KB |
Output is correct |
39 |
Correct |
1446 ms |
14732 KB |
Output is correct |
40 |
Correct |
722 ms |
13980 KB |
Output is correct |
41 |
Correct |
880 ms |
14016 KB |
Output is correct |
42 |
Correct |
514 ms |
13816 KB |
Output is correct |
43 |
Correct |
672 ms |
15124 KB |
Output is correct |
44 |
Correct |
220 ms |
12936 KB |
Output is correct |
45 |
Execution timed out |
3102 ms |
24140 KB |
Time limit exceeded |
46 |
Halted |
0 ms |
0 KB |
- |