# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
43665 |
2018-03-19T08:10:15 Z |
smu201111192 |
Race (IOI11_race) |
C++14 |
|
2546 ms |
58372 KB |
#include "race.h"
#include <iostream>
#include <cstdio>
#include <cassert>
#include <bitset>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <queue>
#include <numeric>
#include <iomanip>
#define ll long long
using namespace std;
const int MAXN = 300001;
vector<pair<int,ll> > tree[MAXN];
int sz[MAXN],kill[MAXN];
void addEdge(int u,int v,ll w){
tree[u].push_back(make_pair(v,w));
tree[v].push_back(make_pair(u,w));
}
void dfs(int here,int dad){
sz[here] = 1;
for(int i=0;i<tree[here].size();i++){
int there = tree[here][i].first;
if(there == dad || kill[there]) continue;
dfs(there,here);
sz[here] += sz[there];
}
}
int getCenter(int here,int dad,int cap){
for(int i=0;i<tree[here].size();i++){
int there = tree[here][i].first;
if(there == dad || kill[there]) continue;
if(sz[there] > cap) return getCenter(there,here,cap);
}
return here;
}
void dfs2(int here,int dad,ll dep,map<ll,ll> &tcnt,int d){
if(tcnt.find(dep) == tcnt.end()) tcnt[dep] = d;
else{ tcnt[dep] = min(tcnt[dep],1LL * d); }
for(int i=0;i<tree[here].size();i++){
int there = tree[here][i].first;
ll w = tree[here][i].second;
if(there == dad || kill[there]) continue;
dfs2(there,here,dep+w,tcnt,d+1);
}
}
long long ans;
void decompose(int root,ll K){
dfs(root,-1);
int center = getCenter(root,-1,sz[root]/2);
map<ll,ll> cnt;
cnt[0] = 0;
for(int i=0;i<tree[center].size();i++){
int there = tree[center][i].first;
ll w = tree[center][i].second;
if(kill[there]) continue;
map<ll,ll> tcnt;
dfs2(there,center,w,tcnt,1);
for(auto it = tcnt.begin(); it!= tcnt.end(); it++){
ll need = K - it->first;
if(cnt.find(need) != cnt.end()) ans = min(ans,it->second + cnt[need]);
}
for(auto it = tcnt.begin(); it!= tcnt.end(); it++){
if(cnt.find(it->first) == cnt.end()) cnt[it->first] = it->second;
else{ cnt[it->first] = min(cnt[it->first],it->second); }
}
}
kill[center] = 1;
for(int i=0;i<tree[center].size();i++){
int there = tree[center][i].first;
if(kill[there]) continue;
decompose(there,K);
}
}
int best_path(int N, int K, int H[][2], int L[])
{
ans = 4e18;
for(int i=0;i<N-1;i++){
addEdge(H[i][0],H[i][1],L[i]);
}
decompose(0,K);
if(ans == 4e18) ans = -1;
return (int)ans;
}
Compilation message
race.cpp: In function 'void dfs(int, int)':
race.cpp:31:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<tree[here].size();i++){
~^~~~~~~~~~~~~~~~~~
race.cpp: In function 'int getCenter(int, int, int)':
race.cpp:39:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<tree[here].size();i++){
~^~~~~~~~~~~~~~~~~~
race.cpp: In function 'void dfs2(int, int, long long int, std::map<long long int, long long int>&, int)':
race.cpp:49:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<tree[here].size();i++){
~^~~~~~~~~~~~~~~~~~
race.cpp: In function 'void decompose(int, long long int)':
race.cpp:62:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<tree[center].size();i++){
~^~~~~~~~~~~~~~~~~~~~
race.cpp:78:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<tree[center].size();i++){
~^~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
9 ms |
7472 KB |
Output is correct |
3 |
Correct |
8 ms |
7472 KB |
Output is correct |
4 |
Correct |
8 ms |
7584 KB |
Output is correct |
5 |
Correct |
8 ms |
7584 KB |
Output is correct |
6 |
Correct |
7 ms |
7584 KB |
Output is correct |
7 |
Correct |
7 ms |
7584 KB |
Output is correct |
8 |
Correct |
7 ms |
7592 KB |
Output is correct |
9 |
Correct |
8 ms |
7592 KB |
Output is correct |
10 |
Correct |
7 ms |
7636 KB |
Output is correct |
11 |
Correct |
7 ms |
7724 KB |
Output is correct |
12 |
Correct |
7 ms |
7724 KB |
Output is correct |
13 |
Correct |
7 ms |
7724 KB |
Output is correct |
14 |
Correct |
7 ms |
7724 KB |
Output is correct |
15 |
Correct |
7 ms |
7724 KB |
Output is correct |
16 |
Correct |
9 ms |
7724 KB |
Output is correct |
17 |
Correct |
7 ms |
7724 KB |
Output is correct |
18 |
Correct |
7 ms |
7724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
9 ms |
7472 KB |
Output is correct |
3 |
Correct |
8 ms |
7472 KB |
Output is correct |
4 |
Correct |
8 ms |
7584 KB |
Output is correct |
5 |
Correct |
8 ms |
7584 KB |
Output is correct |
6 |
Correct |
7 ms |
7584 KB |
Output is correct |
7 |
Correct |
7 ms |
7584 KB |
Output is correct |
8 |
Correct |
7 ms |
7592 KB |
Output is correct |
9 |
Correct |
8 ms |
7592 KB |
Output is correct |
10 |
Correct |
7 ms |
7636 KB |
Output is correct |
11 |
Correct |
7 ms |
7724 KB |
Output is correct |
12 |
Correct |
7 ms |
7724 KB |
Output is correct |
13 |
Correct |
7 ms |
7724 KB |
Output is correct |
14 |
Correct |
7 ms |
7724 KB |
Output is correct |
15 |
Correct |
7 ms |
7724 KB |
Output is correct |
16 |
Correct |
9 ms |
7724 KB |
Output is correct |
17 |
Correct |
7 ms |
7724 KB |
Output is correct |
18 |
Correct |
7 ms |
7724 KB |
Output is correct |
19 |
Correct |
7 ms |
7724 KB |
Output is correct |
20 |
Correct |
7 ms |
7724 KB |
Output is correct |
21 |
Correct |
9 ms |
7780 KB |
Output is correct |
22 |
Correct |
10 ms |
7900 KB |
Output is correct |
23 |
Correct |
11 ms |
7900 KB |
Output is correct |
24 |
Correct |
11 ms |
7900 KB |
Output is correct |
25 |
Correct |
13 ms |
7900 KB |
Output is correct |
26 |
Correct |
13 ms |
7900 KB |
Output is correct |
27 |
Correct |
9 ms |
7900 KB |
Output is correct |
28 |
Correct |
11 ms |
7900 KB |
Output is correct |
29 |
Correct |
9 ms |
7900 KB |
Output is correct |
30 |
Correct |
15 ms |
7900 KB |
Output is correct |
31 |
Correct |
11 ms |
7900 KB |
Output is correct |
32 |
Correct |
11 ms |
7900 KB |
Output is correct |
33 |
Correct |
11 ms |
7900 KB |
Output is correct |
34 |
Correct |
11 ms |
7900 KB |
Output is correct |
35 |
Correct |
9 ms |
7900 KB |
Output is correct |
36 |
Correct |
9 ms |
7900 KB |
Output is correct |
37 |
Correct |
9 ms |
7900 KB |
Output is correct |
38 |
Correct |
11 ms |
7900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
9 ms |
7472 KB |
Output is correct |
3 |
Correct |
8 ms |
7472 KB |
Output is correct |
4 |
Correct |
8 ms |
7584 KB |
Output is correct |
5 |
Correct |
8 ms |
7584 KB |
Output is correct |
6 |
Correct |
7 ms |
7584 KB |
Output is correct |
7 |
Correct |
7 ms |
7584 KB |
Output is correct |
8 |
Correct |
7 ms |
7592 KB |
Output is correct |
9 |
Correct |
8 ms |
7592 KB |
Output is correct |
10 |
Correct |
7 ms |
7636 KB |
Output is correct |
11 |
Correct |
7 ms |
7724 KB |
Output is correct |
12 |
Correct |
7 ms |
7724 KB |
Output is correct |
13 |
Correct |
7 ms |
7724 KB |
Output is correct |
14 |
Correct |
7 ms |
7724 KB |
Output is correct |
15 |
Correct |
7 ms |
7724 KB |
Output is correct |
16 |
Correct |
9 ms |
7724 KB |
Output is correct |
17 |
Correct |
7 ms |
7724 KB |
Output is correct |
18 |
Correct |
7 ms |
7724 KB |
Output is correct |
19 |
Correct |
360 ms |
14844 KB |
Output is correct |
20 |
Correct |
340 ms |
14844 KB |
Output is correct |
21 |
Correct |
328 ms |
14844 KB |
Output is correct |
22 |
Correct |
320 ms |
14844 KB |
Output is correct |
23 |
Correct |
540 ms |
15428 KB |
Output is correct |
24 |
Correct |
289 ms |
15428 KB |
Output is correct |
25 |
Correct |
391 ms |
20476 KB |
Output is correct |
26 |
Correct |
138 ms |
20604 KB |
Output is correct |
27 |
Correct |
548 ms |
22788 KB |
Output is correct |
28 |
Correct |
2379 ms |
58372 KB |
Output is correct |
29 |
Correct |
1964 ms |
58372 KB |
Output is correct |
30 |
Correct |
490 ms |
58372 KB |
Output is correct |
31 |
Correct |
476 ms |
58372 KB |
Output is correct |
32 |
Correct |
566 ms |
58372 KB |
Output is correct |
33 |
Correct |
1112 ms |
58372 KB |
Output is correct |
34 |
Correct |
2162 ms |
58372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
9 ms |
7472 KB |
Output is correct |
3 |
Correct |
8 ms |
7472 KB |
Output is correct |
4 |
Correct |
8 ms |
7584 KB |
Output is correct |
5 |
Correct |
8 ms |
7584 KB |
Output is correct |
6 |
Correct |
7 ms |
7584 KB |
Output is correct |
7 |
Correct |
7 ms |
7584 KB |
Output is correct |
8 |
Correct |
7 ms |
7592 KB |
Output is correct |
9 |
Correct |
8 ms |
7592 KB |
Output is correct |
10 |
Correct |
7 ms |
7636 KB |
Output is correct |
11 |
Correct |
7 ms |
7724 KB |
Output is correct |
12 |
Correct |
7 ms |
7724 KB |
Output is correct |
13 |
Correct |
7 ms |
7724 KB |
Output is correct |
14 |
Correct |
7 ms |
7724 KB |
Output is correct |
15 |
Correct |
7 ms |
7724 KB |
Output is correct |
16 |
Correct |
9 ms |
7724 KB |
Output is correct |
17 |
Correct |
7 ms |
7724 KB |
Output is correct |
18 |
Correct |
7 ms |
7724 KB |
Output is correct |
19 |
Correct |
7 ms |
7724 KB |
Output is correct |
20 |
Correct |
7 ms |
7724 KB |
Output is correct |
21 |
Correct |
9 ms |
7780 KB |
Output is correct |
22 |
Correct |
10 ms |
7900 KB |
Output is correct |
23 |
Correct |
11 ms |
7900 KB |
Output is correct |
24 |
Correct |
11 ms |
7900 KB |
Output is correct |
25 |
Correct |
13 ms |
7900 KB |
Output is correct |
26 |
Correct |
13 ms |
7900 KB |
Output is correct |
27 |
Correct |
9 ms |
7900 KB |
Output is correct |
28 |
Correct |
11 ms |
7900 KB |
Output is correct |
29 |
Correct |
9 ms |
7900 KB |
Output is correct |
30 |
Correct |
15 ms |
7900 KB |
Output is correct |
31 |
Correct |
11 ms |
7900 KB |
Output is correct |
32 |
Correct |
11 ms |
7900 KB |
Output is correct |
33 |
Correct |
11 ms |
7900 KB |
Output is correct |
34 |
Correct |
11 ms |
7900 KB |
Output is correct |
35 |
Correct |
9 ms |
7900 KB |
Output is correct |
36 |
Correct |
9 ms |
7900 KB |
Output is correct |
37 |
Correct |
9 ms |
7900 KB |
Output is correct |
38 |
Correct |
11 ms |
7900 KB |
Output is correct |
39 |
Correct |
360 ms |
14844 KB |
Output is correct |
40 |
Correct |
340 ms |
14844 KB |
Output is correct |
41 |
Correct |
328 ms |
14844 KB |
Output is correct |
42 |
Correct |
320 ms |
14844 KB |
Output is correct |
43 |
Correct |
540 ms |
15428 KB |
Output is correct |
44 |
Correct |
289 ms |
15428 KB |
Output is correct |
45 |
Correct |
391 ms |
20476 KB |
Output is correct |
46 |
Correct |
138 ms |
20604 KB |
Output is correct |
47 |
Correct |
548 ms |
22788 KB |
Output is correct |
48 |
Correct |
2379 ms |
58372 KB |
Output is correct |
49 |
Correct |
1964 ms |
58372 KB |
Output is correct |
50 |
Correct |
490 ms |
58372 KB |
Output is correct |
51 |
Correct |
476 ms |
58372 KB |
Output is correct |
52 |
Correct |
566 ms |
58372 KB |
Output is correct |
53 |
Correct |
1112 ms |
58372 KB |
Output is correct |
54 |
Correct |
2162 ms |
58372 KB |
Output is correct |
55 |
Correct |
50 ms |
58372 KB |
Output is correct |
56 |
Correct |
31 ms |
58372 KB |
Output is correct |
57 |
Correct |
240 ms |
58372 KB |
Output is correct |
58 |
Correct |
75 ms |
58372 KB |
Output is correct |
59 |
Correct |
788 ms |
58372 KB |
Output is correct |
60 |
Correct |
2546 ms |
58372 KB |
Output is correct |
61 |
Correct |
645 ms |
58372 KB |
Output is correct |
62 |
Correct |
557 ms |
58372 KB |
Output is correct |
63 |
Correct |
660 ms |
58372 KB |
Output is correct |
64 |
Correct |
2181 ms |
58372 KB |
Output is correct |
65 |
Correct |
1646 ms |
58372 KB |
Output is correct |
66 |
Correct |
1980 ms |
58372 KB |
Output is correct |
67 |
Correct |
248 ms |
58372 KB |
Output is correct |
68 |
Correct |
994 ms |
58372 KB |
Output is correct |
69 |
Correct |
852 ms |
58372 KB |
Output is correct |
70 |
Correct |
800 ms |
58372 KB |
Output is correct |