# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1112728 |
2024-11-14T17:09:57 Z |
hainam2k9 |
Race (IOI11_race) |
C++17 |
|
3000 ms |
22344 KB |
#include <bits/stdc++.h>
#include <race.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
using namespace std;
const int MOD = 1e9+7, MAXN = 2e5+5;
const string NAME = "";
int n,k,rs=MAXN,sz[MAXN],cnt[1000005];
bool del[MAXN];
vector<pair<int,int>> adj[MAXN];
set<int> s;
void GetSize(int u, int par){
sz[u]=1;
for(pair<int,int> p : adj[u])
if(p.fi!=par&&!del[p.fi]) GetSize(p.fi,u), sz[u]+=sz[p.fi];
}
int Centroid(int u, int par){
for(pair<int,int> p : adj[u])
if(p.fi!=par&&!del[p.fi]&&sz[p.fi]>(n>>1)) return Centroid(p.fi,u);
return u;
}
void dfs(int u, int par, bool type, int cur, ll len){
if(k<len||cur>rs) return;
if(type==1) cnt[len] = !cnt[len] ? cur : min(cnt[len],cur), s.ins(len);
else if(type==0&&cnt[k-len]) rs=min(rs,cnt[k-len]+cur);
else if(len==k) rs=min(rs,cur);
for(pair<int,int> p : adj[u])
if(p.fi!=par) dfs(p.fi,u,type,cur+1,len+p.se);
}
void CentroidDecomposition(int u){
GetSize(u,0), n=sz[u];
int root=Centroid(u,0);
for(pair<int,int> p : adj[root])
if(!del[p.fi]) dfs(p.fi,root,0,1,p.se), dfs(p.fi,root,1,1,p.se);
for(int x : s) cnt[x]=0;
s.clear();
del[root]=1;
for(pair<int,int> p : adj[root])
if(!del[p.fi]) CentroidDecomposition(p.fi);
}
int best_path(int N, int K, int h[][2], int l[]){
n=N, k=K;
for(int i = 1; i<n; ++i)
adj[h[i-1][0]+1].pb(h[i-1][1]+1,l[i-1]), adj[h[i-1][1]+1].pb(h[i-1][0]+1,l[i-1]);
CentroidDecomposition(1);
return rs==MAXN ? -1 : rs;
}
//int main()
//{
// tt;
// if(fopen((NAME + ".INP").c_str(), "r")) fo;
// cin >> n >> k;
// int h[n][2], l[n];
// for(int i = 0; i<n-1; ++i)
// cin >> h[i][0] >> h[i][1] >> l[i];
// cout << best_path(n,k,h,l);
// cerr << 1.0L*clock()/CLOCKS_PER_SEC << "s\n";
//}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8528 KB |
Output is correct |
2 |
Correct |
3 ms |
8528 KB |
Output is correct |
3 |
Correct |
2 ms |
8528 KB |
Output is correct |
4 |
Correct |
2 ms |
8528 KB |
Output is correct |
5 |
Correct |
2 ms |
8528 KB |
Output is correct |
6 |
Correct |
3 ms |
8528 KB |
Output is correct |
7 |
Correct |
2 ms |
8528 KB |
Output is correct |
8 |
Correct |
2 ms |
8528 KB |
Output is correct |
9 |
Correct |
2 ms |
8528 KB |
Output is correct |
10 |
Correct |
2 ms |
8696 KB |
Output is correct |
11 |
Correct |
2 ms |
8528 KB |
Output is correct |
12 |
Correct |
2 ms |
8528 KB |
Output is correct |
13 |
Correct |
2 ms |
8528 KB |
Output is correct |
14 |
Correct |
2 ms |
8528 KB |
Output is correct |
15 |
Correct |
2 ms |
8528 KB |
Output is correct |
16 |
Correct |
2 ms |
8696 KB |
Output is correct |
17 |
Correct |
2 ms |
8528 KB |
Output is correct |
18 |
Correct |
2 ms |
8528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8528 KB |
Output is correct |
2 |
Correct |
3 ms |
8528 KB |
Output is correct |
3 |
Correct |
2 ms |
8528 KB |
Output is correct |
4 |
Correct |
2 ms |
8528 KB |
Output is correct |
5 |
Correct |
2 ms |
8528 KB |
Output is correct |
6 |
Correct |
3 ms |
8528 KB |
Output is correct |
7 |
Correct |
2 ms |
8528 KB |
Output is correct |
8 |
Correct |
2 ms |
8528 KB |
Output is correct |
9 |
Correct |
2 ms |
8528 KB |
Output is correct |
10 |
Correct |
2 ms |
8696 KB |
Output is correct |
11 |
Correct |
2 ms |
8528 KB |
Output is correct |
12 |
Correct |
2 ms |
8528 KB |
Output is correct |
13 |
Correct |
2 ms |
8528 KB |
Output is correct |
14 |
Correct |
2 ms |
8528 KB |
Output is correct |
15 |
Correct |
2 ms |
8528 KB |
Output is correct |
16 |
Correct |
2 ms |
8696 KB |
Output is correct |
17 |
Correct |
2 ms |
8528 KB |
Output is correct |
18 |
Correct |
2 ms |
8528 KB |
Output is correct |
19 |
Correct |
2 ms |
8528 KB |
Output is correct |
20 |
Correct |
2 ms |
8528 KB |
Output is correct |
21 |
Correct |
14 ms |
8528 KB |
Output is correct |
22 |
Correct |
4 ms |
10232 KB |
Output is correct |
23 |
Correct |
3 ms |
9552 KB |
Output is correct |
24 |
Correct |
4 ms |
10064 KB |
Output is correct |
25 |
Correct |
20 ms |
10516 KB |
Output is correct |
26 |
Correct |
2 ms |
8528 KB |
Output is correct |
27 |
Correct |
2 ms |
8528 KB |
Output is correct |
28 |
Correct |
4 ms |
8528 KB |
Output is correct |
29 |
Correct |
7 ms |
8528 KB |
Output is correct |
30 |
Correct |
9 ms |
8528 KB |
Output is correct |
31 |
Correct |
15 ms |
9608 KB |
Output is correct |
32 |
Correct |
20 ms |
9808 KB |
Output is correct |
33 |
Correct |
25 ms |
10064 KB |
Output is correct |
34 |
Correct |
4 ms |
9296 KB |
Output is correct |
35 |
Correct |
6 ms |
10064 KB |
Output is correct |
36 |
Correct |
6 ms |
10576 KB |
Output is correct |
37 |
Correct |
35 ms |
10064 KB |
Output is correct |
38 |
Correct |
45 ms |
9040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8528 KB |
Output is correct |
2 |
Correct |
3 ms |
8528 KB |
Output is correct |
3 |
Correct |
2 ms |
8528 KB |
Output is correct |
4 |
Correct |
2 ms |
8528 KB |
Output is correct |
5 |
Correct |
2 ms |
8528 KB |
Output is correct |
6 |
Correct |
3 ms |
8528 KB |
Output is correct |
7 |
Correct |
2 ms |
8528 KB |
Output is correct |
8 |
Correct |
2 ms |
8528 KB |
Output is correct |
9 |
Correct |
2 ms |
8528 KB |
Output is correct |
10 |
Correct |
2 ms |
8696 KB |
Output is correct |
11 |
Correct |
2 ms |
8528 KB |
Output is correct |
12 |
Correct |
2 ms |
8528 KB |
Output is correct |
13 |
Correct |
2 ms |
8528 KB |
Output is correct |
14 |
Correct |
2 ms |
8528 KB |
Output is correct |
15 |
Correct |
2 ms |
8528 KB |
Output is correct |
16 |
Correct |
2 ms |
8696 KB |
Output is correct |
17 |
Correct |
2 ms |
8528 KB |
Output is correct |
18 |
Correct |
2 ms |
8528 KB |
Output is correct |
19 |
Correct |
358 ms |
11848 KB |
Output is correct |
20 |
Correct |
340 ms |
13644 KB |
Output is correct |
21 |
Correct |
506 ms |
13896 KB |
Output is correct |
22 |
Correct |
686 ms |
13964 KB |
Output is correct |
23 |
Correct |
52 ms |
15440 KB |
Output is correct |
24 |
Correct |
50 ms |
15436 KB |
Output is correct |
25 |
Correct |
2677 ms |
18820 KB |
Output is correct |
26 |
Execution timed out |
3061 ms |
22344 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8528 KB |
Output is correct |
2 |
Correct |
3 ms |
8528 KB |
Output is correct |
3 |
Correct |
2 ms |
8528 KB |
Output is correct |
4 |
Correct |
2 ms |
8528 KB |
Output is correct |
5 |
Correct |
2 ms |
8528 KB |
Output is correct |
6 |
Correct |
3 ms |
8528 KB |
Output is correct |
7 |
Correct |
2 ms |
8528 KB |
Output is correct |
8 |
Correct |
2 ms |
8528 KB |
Output is correct |
9 |
Correct |
2 ms |
8528 KB |
Output is correct |
10 |
Correct |
2 ms |
8696 KB |
Output is correct |
11 |
Correct |
2 ms |
8528 KB |
Output is correct |
12 |
Correct |
2 ms |
8528 KB |
Output is correct |
13 |
Correct |
2 ms |
8528 KB |
Output is correct |
14 |
Correct |
2 ms |
8528 KB |
Output is correct |
15 |
Correct |
2 ms |
8528 KB |
Output is correct |
16 |
Correct |
2 ms |
8696 KB |
Output is correct |
17 |
Correct |
2 ms |
8528 KB |
Output is correct |
18 |
Correct |
2 ms |
8528 KB |
Output is correct |
19 |
Correct |
2 ms |
8528 KB |
Output is correct |
20 |
Correct |
2 ms |
8528 KB |
Output is correct |
21 |
Correct |
14 ms |
8528 KB |
Output is correct |
22 |
Correct |
4 ms |
10232 KB |
Output is correct |
23 |
Correct |
3 ms |
9552 KB |
Output is correct |
24 |
Correct |
4 ms |
10064 KB |
Output is correct |
25 |
Correct |
20 ms |
10516 KB |
Output is correct |
26 |
Correct |
2 ms |
8528 KB |
Output is correct |
27 |
Correct |
2 ms |
8528 KB |
Output is correct |
28 |
Correct |
4 ms |
8528 KB |
Output is correct |
29 |
Correct |
7 ms |
8528 KB |
Output is correct |
30 |
Correct |
9 ms |
8528 KB |
Output is correct |
31 |
Correct |
15 ms |
9608 KB |
Output is correct |
32 |
Correct |
20 ms |
9808 KB |
Output is correct |
33 |
Correct |
25 ms |
10064 KB |
Output is correct |
34 |
Correct |
4 ms |
9296 KB |
Output is correct |
35 |
Correct |
6 ms |
10064 KB |
Output is correct |
36 |
Correct |
6 ms |
10576 KB |
Output is correct |
37 |
Correct |
35 ms |
10064 KB |
Output is correct |
38 |
Correct |
45 ms |
9040 KB |
Output is correct |
39 |
Correct |
358 ms |
11848 KB |
Output is correct |
40 |
Correct |
340 ms |
13644 KB |
Output is correct |
41 |
Correct |
506 ms |
13896 KB |
Output is correct |
42 |
Correct |
686 ms |
13964 KB |
Output is correct |
43 |
Correct |
52 ms |
15440 KB |
Output is correct |
44 |
Correct |
50 ms |
15436 KB |
Output is correct |
45 |
Correct |
2677 ms |
18820 KB |
Output is correct |
46 |
Execution timed out |
3061 ms |
22344 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |