# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1118013 |
2024-11-24T17:05:36 Z |
Newtonabc |
Race (IOI11_race) |
C++14 |
|
677 ms |
46748 KB |
#include "race.h"
#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
const int M=2e5+10;
vector<pair<long long,int> > adj[M];
int n,rem[M],sz[M],dist[M],lvl[M];
set<pair<long long,int> >::iterator it;
set<pair<long long,int> > s;
queue<pair<long long,int> > q;
int ans=INT_MAX,k;
void findsz(int u,int p){
sz[u]=1;
for(int i=0;i<adj[u].size();i++){
int v=adj[u][i].second;
if(v==p || rem[v]) continue;
findsz(v,u);
sz[u]+=sz[v];
}
}
void findlvl(int u,int p){
for(int i=0;i<adj[u].size();i++){
int v=adj[u][i].second;
if(v==p || rem[v]) continue;
lvl[v]=lvl[u]+1;
findlvl(v,u);
}
}
int getcentroid(int u,int p,int treesz){
for(int i=0;i<adj[u].size();i++){
int v=adj[u][i].second;
if(v==p || rem[v]) continue;
if(sz[v]*2>treesz) return getcentroid(v,u,treesz);
}
return u;
}
void dfs(int u,int p){
if(dist[u]>k) return;
for(int i=0;i<adj[u].size();i++){
if(!lvl[u]) while(!q.empty()) s.insert(mp(k-q.front().first,q.front().second)),q.pop();
int v=adj[u][i].second;
long long w=adj[u][i].first;
if(v==p || rem[v]) continue;
dist[v]=dist[u]+w;
it=s.lower_bound(mp(dist[v],0));
if(it->first==dist[v]) ans=min(ans,it->second+lvl[v]);
q.push(mp(dist[v],lvl[v]));
dfs(v,u);
}
}
void decom(int u){
findsz(u,u);
int cen=getcentroid(u,u,sz[u]);
//cout<<cen <<"\n";
//for(int i=0;i<n;i++) cout<<dist[i] <<" ";
s.insert(mp(k,0));
lvl[cen]=0;
dist[cen]=0;
findlvl(cen,cen);
dfs(cen,cen);
s.clear();
while(!q.empty()) q.pop();
rem[cen]=true;
for(int i=0;i<adj[cen].size();i++){
int v=adj[cen][i].second;
if(rem[v]) continue;
decom(v);
}
}
int best_path(int N, int K, int H[][2], int L[]){
n=N,k=K;
for(int i=0;i<n-1;i++){
adj[H[i][0]].push_back(mp(L[i],H[i][1]));
adj[H[i][1]].push_back(mp(L[i],H[i][0]));
}
decom(0);
if(ans==INT_MAX) return -1;
return ans;
}
Compilation message
race.cpp: In function 'void findsz(int, int)':
race.cpp:14:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for(int i=0;i<adj[u].size();i++){
| ~^~~~~~~~~~~~~~
race.cpp: In function 'void findlvl(int, int)':
race.cpp:22:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for(int i=0;i<adj[u].size();i++){
| ~^~~~~~~~~~~~~~
race.cpp: In function 'int getcentroid(int, int, int)':
race.cpp:30:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for(int i=0;i<adj[u].size();i++){
| ~^~~~~~~~~~~~~~
race.cpp: In function 'void dfs(int, int)':
race.cpp:39:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int i=0;i<adj[u].size();i++){
| ~^~~~~~~~~~~~~~
race.cpp: In function 'void decom(int)':
race.cpp:64:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int i=0;i<adj[cen].size();i++){
| ~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5200 KB |
Output is correct |
2 |
Correct |
4 ms |
4944 KB |
Output is correct |
3 |
Correct |
4 ms |
4944 KB |
Output is correct |
4 |
Correct |
5 ms |
4944 KB |
Output is correct |
5 |
Correct |
4 ms |
4956 KB |
Output is correct |
6 |
Correct |
4 ms |
4944 KB |
Output is correct |
7 |
Correct |
4 ms |
4944 KB |
Output is correct |
8 |
Correct |
4 ms |
4944 KB |
Output is correct |
9 |
Correct |
6 ms |
4944 KB |
Output is correct |
10 |
Correct |
4 ms |
4944 KB |
Output is correct |
11 |
Correct |
4 ms |
4944 KB |
Output is correct |
12 |
Correct |
5 ms |
5112 KB |
Output is correct |
13 |
Correct |
4 ms |
5152 KB |
Output is correct |
14 |
Correct |
5 ms |
4944 KB |
Output is correct |
15 |
Correct |
4 ms |
4944 KB |
Output is correct |
16 |
Correct |
4 ms |
4944 KB |
Output is correct |
17 |
Correct |
4 ms |
4948 KB |
Output is correct |
18 |
Correct |
4 ms |
4944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5200 KB |
Output is correct |
2 |
Correct |
4 ms |
4944 KB |
Output is correct |
3 |
Correct |
4 ms |
4944 KB |
Output is correct |
4 |
Correct |
5 ms |
4944 KB |
Output is correct |
5 |
Correct |
4 ms |
4956 KB |
Output is correct |
6 |
Correct |
4 ms |
4944 KB |
Output is correct |
7 |
Correct |
4 ms |
4944 KB |
Output is correct |
8 |
Correct |
4 ms |
4944 KB |
Output is correct |
9 |
Correct |
6 ms |
4944 KB |
Output is correct |
10 |
Correct |
4 ms |
4944 KB |
Output is correct |
11 |
Correct |
4 ms |
4944 KB |
Output is correct |
12 |
Correct |
5 ms |
5112 KB |
Output is correct |
13 |
Correct |
4 ms |
5152 KB |
Output is correct |
14 |
Correct |
5 ms |
4944 KB |
Output is correct |
15 |
Correct |
4 ms |
4944 KB |
Output is correct |
16 |
Correct |
4 ms |
4944 KB |
Output is correct |
17 |
Correct |
4 ms |
4948 KB |
Output is correct |
18 |
Correct |
4 ms |
4944 KB |
Output is correct |
19 |
Correct |
4 ms |
4944 KB |
Output is correct |
20 |
Correct |
5 ms |
5152 KB |
Output is correct |
21 |
Correct |
5 ms |
5156 KB |
Output is correct |
22 |
Correct |
5 ms |
5200 KB |
Output is correct |
23 |
Correct |
4 ms |
5200 KB |
Output is correct |
24 |
Correct |
5 ms |
5200 KB |
Output is correct |
25 |
Correct |
4 ms |
5200 KB |
Output is correct |
26 |
Correct |
4 ms |
5272 KB |
Output is correct |
27 |
Correct |
5 ms |
5200 KB |
Output is correct |
28 |
Correct |
4 ms |
5200 KB |
Output is correct |
29 |
Correct |
5 ms |
5200 KB |
Output is correct |
30 |
Correct |
5 ms |
5200 KB |
Output is correct |
31 |
Correct |
5 ms |
5200 KB |
Output is correct |
32 |
Correct |
5 ms |
5200 KB |
Output is correct |
33 |
Correct |
5 ms |
5200 KB |
Output is correct |
34 |
Correct |
5 ms |
5216 KB |
Output is correct |
35 |
Correct |
5 ms |
5280 KB |
Output is correct |
36 |
Correct |
5 ms |
5200 KB |
Output is correct |
37 |
Correct |
7 ms |
5200 KB |
Output is correct |
38 |
Correct |
4 ms |
5208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5200 KB |
Output is correct |
2 |
Correct |
4 ms |
4944 KB |
Output is correct |
3 |
Correct |
4 ms |
4944 KB |
Output is correct |
4 |
Correct |
5 ms |
4944 KB |
Output is correct |
5 |
Correct |
4 ms |
4956 KB |
Output is correct |
6 |
Correct |
4 ms |
4944 KB |
Output is correct |
7 |
Correct |
4 ms |
4944 KB |
Output is correct |
8 |
Correct |
4 ms |
4944 KB |
Output is correct |
9 |
Correct |
6 ms |
4944 KB |
Output is correct |
10 |
Correct |
4 ms |
4944 KB |
Output is correct |
11 |
Correct |
4 ms |
4944 KB |
Output is correct |
12 |
Correct |
5 ms |
5112 KB |
Output is correct |
13 |
Correct |
4 ms |
5152 KB |
Output is correct |
14 |
Correct |
5 ms |
4944 KB |
Output is correct |
15 |
Correct |
4 ms |
4944 KB |
Output is correct |
16 |
Correct |
4 ms |
4944 KB |
Output is correct |
17 |
Correct |
4 ms |
4948 KB |
Output is correct |
18 |
Correct |
4 ms |
4944 KB |
Output is correct |
19 |
Correct |
164 ms |
14452 KB |
Output is correct |
20 |
Correct |
175 ms |
14440 KB |
Output is correct |
21 |
Correct |
181 ms |
14616 KB |
Output is correct |
22 |
Correct |
167 ms |
14920 KB |
Output is correct |
23 |
Correct |
79 ms |
14676 KB |
Output is correct |
24 |
Correct |
73 ms |
13976 KB |
Output is correct |
25 |
Correct |
177 ms |
18000 KB |
Output is correct |
26 |
Correct |
149 ms |
25672 KB |
Output is correct |
27 |
Correct |
160 ms |
24136 KB |
Output is correct |
28 |
Correct |
279 ms |
38660 KB |
Output is correct |
29 |
Correct |
258 ms |
37388 KB |
Output is correct |
30 |
Correct |
159 ms |
24136 KB |
Output is correct |
31 |
Correct |
153 ms |
24136 KB |
Output is correct |
32 |
Correct |
197 ms |
24392 KB |
Output is correct |
33 |
Correct |
226 ms |
22944 KB |
Output is correct |
34 |
Correct |
189 ms |
23896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5200 KB |
Output is correct |
2 |
Correct |
4 ms |
4944 KB |
Output is correct |
3 |
Correct |
4 ms |
4944 KB |
Output is correct |
4 |
Correct |
5 ms |
4944 KB |
Output is correct |
5 |
Correct |
4 ms |
4956 KB |
Output is correct |
6 |
Correct |
4 ms |
4944 KB |
Output is correct |
7 |
Correct |
4 ms |
4944 KB |
Output is correct |
8 |
Correct |
4 ms |
4944 KB |
Output is correct |
9 |
Correct |
6 ms |
4944 KB |
Output is correct |
10 |
Correct |
4 ms |
4944 KB |
Output is correct |
11 |
Correct |
4 ms |
4944 KB |
Output is correct |
12 |
Correct |
5 ms |
5112 KB |
Output is correct |
13 |
Correct |
4 ms |
5152 KB |
Output is correct |
14 |
Correct |
5 ms |
4944 KB |
Output is correct |
15 |
Correct |
4 ms |
4944 KB |
Output is correct |
16 |
Correct |
4 ms |
4944 KB |
Output is correct |
17 |
Correct |
4 ms |
4948 KB |
Output is correct |
18 |
Correct |
4 ms |
4944 KB |
Output is correct |
19 |
Correct |
4 ms |
4944 KB |
Output is correct |
20 |
Correct |
5 ms |
5152 KB |
Output is correct |
21 |
Correct |
5 ms |
5156 KB |
Output is correct |
22 |
Correct |
5 ms |
5200 KB |
Output is correct |
23 |
Correct |
4 ms |
5200 KB |
Output is correct |
24 |
Correct |
5 ms |
5200 KB |
Output is correct |
25 |
Correct |
4 ms |
5200 KB |
Output is correct |
26 |
Correct |
4 ms |
5272 KB |
Output is correct |
27 |
Correct |
5 ms |
5200 KB |
Output is correct |
28 |
Correct |
4 ms |
5200 KB |
Output is correct |
29 |
Correct |
5 ms |
5200 KB |
Output is correct |
30 |
Correct |
5 ms |
5200 KB |
Output is correct |
31 |
Correct |
5 ms |
5200 KB |
Output is correct |
32 |
Correct |
5 ms |
5200 KB |
Output is correct |
33 |
Correct |
5 ms |
5200 KB |
Output is correct |
34 |
Correct |
5 ms |
5216 KB |
Output is correct |
35 |
Correct |
5 ms |
5280 KB |
Output is correct |
36 |
Correct |
5 ms |
5200 KB |
Output is correct |
37 |
Correct |
7 ms |
5200 KB |
Output is correct |
38 |
Correct |
4 ms |
5208 KB |
Output is correct |
39 |
Correct |
164 ms |
14452 KB |
Output is correct |
40 |
Correct |
175 ms |
14440 KB |
Output is correct |
41 |
Correct |
181 ms |
14616 KB |
Output is correct |
42 |
Correct |
167 ms |
14920 KB |
Output is correct |
43 |
Correct |
79 ms |
14676 KB |
Output is correct |
44 |
Correct |
73 ms |
13976 KB |
Output is correct |
45 |
Correct |
177 ms |
18000 KB |
Output is correct |
46 |
Correct |
149 ms |
25672 KB |
Output is correct |
47 |
Correct |
160 ms |
24136 KB |
Output is correct |
48 |
Correct |
279 ms |
38660 KB |
Output is correct |
49 |
Correct |
258 ms |
37388 KB |
Output is correct |
50 |
Correct |
159 ms |
24136 KB |
Output is correct |
51 |
Correct |
153 ms |
24136 KB |
Output is correct |
52 |
Correct |
197 ms |
24392 KB |
Output is correct |
53 |
Correct |
226 ms |
22944 KB |
Output is correct |
54 |
Correct |
189 ms |
23896 KB |
Output is correct |
55 |
Correct |
17 ms |
6468 KB |
Output is correct |
56 |
Correct |
14 ms |
6124 KB |
Output is correct |
57 |
Correct |
91 ms |
15148 KB |
Output is correct |
58 |
Correct |
37 ms |
13500 KB |
Output is correct |
59 |
Correct |
141 ms |
25680 KB |
Output is correct |
60 |
Correct |
528 ms |
46748 KB |
Output is correct |
61 |
Correct |
174 ms |
25928 KB |
Output is correct |
62 |
Correct |
231 ms |
27676 KB |
Output is correct |
63 |
Correct |
263 ms |
27604 KB |
Output is correct |
64 |
Correct |
677 ms |
34864 KB |
Output is correct |
65 |
Correct |
224 ms |
24640 KB |
Output is correct |
66 |
Correct |
384 ms |
35116 KB |
Output is correct |
67 |
Correct |
116 ms |
23476 KB |
Output is correct |
68 |
Correct |
330 ms |
30792 KB |
Output is correct |
69 |
Correct |
346 ms |
30536 KB |
Output is correct |
70 |
Correct |
301 ms |
29552 KB |
Output is correct |