Submission #1038154

# Submission time Handle Problem Language Result Execution time Memory
1038154 2024-07-29T13:33:12 Z elotelo966 Race (IOI11_race) C++17
100 / 100
589 ms 39648 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <race.h>
#include <bits/stdc++.h>
using namespace std;
 
//#define int long long
#define OYY LLONG_MAX
#define mod 998244353
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define FOR for(int i=1;i<=n;i++)
#define mid (start+end)/2
#define lim 200005
#define fi first
#define se second

typedef long long lo;

map<int,int> mp;

vector<pair<int,int>> noww;

vector<pair<int,int>> v[lim];

int x[lim],y[lim],l[lim];

int removed[lim],sub_tree[lim];

lo cev=LLONG_MAX,k;

inline int find_size(int node,int ata){
	sub_tree[node]=1;
	for(auto go:v[node]){
		if(go.fi==ata || removed[go.fi])continue;
		find_size(go.fi,node);
		sub_tree[node]+=sub_tree[go.fi];
	}
	return sub_tree[node];
}

inline int find_centroid(int node,int ata,int cur_size){
	for(auto go:v[node]){
		if(go.fi==ata || removed[go.fi])continue;
		if(sub_tree[go.fi]*2>cur_size)return find_centroid(go.fi,node,cur_size);
	}
	return node;
}

inline void dfs(int node,int ata,int cur,int sayac){
	if(cur>k)return ;
	noww.push_back({cur,sayac});
	for(auto go:v[node]){
		if(go.fi==ata || removed[go.fi])continue;
		dfs(go.fi,node,cur+go.se,sayac+1);
	}
}

inline void solve(int node){
	mp.clear();
	mp[0]=0;
	for(auto go:v[node]){
		if(removed[go.fi])continue;
		noww.clear();
		dfs(go.fi,node,go.se,1);
		for(auto x:noww){
			if(mp.find(k-x.fi)==mp.end()){
				continue;
			}
			cev=min(cev,(lo)mp[k-x.fi]+x.se);
		}
		for(auto x:noww){
			if(mp.find(x.fi)==mp.end())mp[x.fi]=x.se;
			else mp[x.fi]=min(mp[x.fi],x.se);
		}
	}
}

inline void build(int node){
	int cur_size=find_size(node,-1);
	int cur_centroid=find_centroid(node,-1,cur_size);
	removed[cur_centroid]=1;
	solve(cur_centroid);
	for(auto go:v[cur_centroid]){
		if(removed[go.fi])continue;
		build(go.fi);
	}
}

int best_path(int N, int K, int H[][2], int L[])
{
	int n=N;
	k=K;
	FOR{
		if(i==1)continue;
		x[i]=H[i-2][0];
		y[i]=H[i-2][1];
		l[i]=L[i-2];
		v[x[i]].push_back({y[i],l[i]});
		v[y[i]].push_back({x[i],l[i]});
	}
	
	build(0);
	
	if(cev==LLONG_MAX)return -1;
	else return cev;
}

/*

int32_t main(){
	faster
	int n;cin>>n>>k;
	FOR{
		if(i==1)continue;
		cin>>x[i]>>y[i];
	}
	
	FOR{
		if(i==1)continue;
		cin>>l[i];
		v[x[i]].push_back({y[i],l[i]});
		v[y[i]].push_back({x[i],l[i]});
	}
	
	build(1);
	
	if(cev==LLONG_MAX)cout<<-1<<'\n';
	else cout<<cev<<'\n';
	
	return 0;
}*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 3 ms 12636 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 3 ms 12636 KB Output is correct
5 Correct 2 ms 12636 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 3 ms 12636 KB Output is correct
8 Correct 2 ms 12636 KB Output is correct
9 Correct 2 ms 12636 KB Output is correct
10 Correct 3 ms 12636 KB Output is correct
11 Correct 3 ms 12636 KB Output is correct
12 Correct 3 ms 12636 KB Output is correct
13 Correct 2 ms 12636 KB Output is correct
14 Correct 2 ms 12636 KB Output is correct
15 Correct 3 ms 12636 KB Output is correct
16 Correct 3 ms 12636 KB Output is correct
17 Correct 3 ms 12636 KB Output is correct
18 Correct 3 ms 12636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 3 ms 12636 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 3 ms 12636 KB Output is correct
5 Correct 2 ms 12636 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 3 ms 12636 KB Output is correct
8 Correct 2 ms 12636 KB Output is correct
9 Correct 2 ms 12636 KB Output is correct
10 Correct 3 ms 12636 KB Output is correct
11 Correct 3 ms 12636 KB Output is correct
12 Correct 3 ms 12636 KB Output is correct
13 Correct 2 ms 12636 KB Output is correct
14 Correct 2 ms 12636 KB Output is correct
15 Correct 3 ms 12636 KB Output is correct
16 Correct 3 ms 12636 KB Output is correct
17 Correct 3 ms 12636 KB Output is correct
18 Correct 3 ms 12636 KB Output is correct
19 Correct 3 ms 12632 KB Output is correct
20 Correct 3 ms 12636 KB Output is correct
21 Correct 3 ms 12636 KB Output is correct
22 Correct 2 ms 12636 KB Output is correct
23 Correct 3 ms 12636 KB Output is correct
24 Correct 3 ms 12632 KB Output is correct
25 Correct 3 ms 12636 KB Output is correct
26 Correct 2 ms 12636 KB Output is correct
27 Correct 3 ms 12636 KB Output is correct
28 Correct 4 ms 12636 KB Output is correct
29 Correct 3 ms 12636 KB Output is correct
30 Correct 3 ms 12636 KB Output is correct
31 Correct 4 ms 12636 KB Output is correct
32 Correct 3 ms 12636 KB Output is correct
33 Correct 4 ms 12636 KB Output is correct
34 Correct 3 ms 12636 KB Output is correct
35 Correct 3 ms 12636 KB Output is correct
36 Correct 4 ms 12636 KB Output is correct
37 Correct 4 ms 12632 KB Output is correct
38 Correct 3 ms 12636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 3 ms 12636 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 3 ms 12636 KB Output is correct
5 Correct 2 ms 12636 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 3 ms 12636 KB Output is correct
8 Correct 2 ms 12636 KB Output is correct
9 Correct 2 ms 12636 KB Output is correct
10 Correct 3 ms 12636 KB Output is correct
11 Correct 3 ms 12636 KB Output is correct
12 Correct 3 ms 12636 KB Output is correct
13 Correct 2 ms 12636 KB Output is correct
14 Correct 2 ms 12636 KB Output is correct
15 Correct 3 ms 12636 KB Output is correct
16 Correct 3 ms 12636 KB Output is correct
17 Correct 3 ms 12636 KB Output is correct
18 Correct 3 ms 12636 KB Output is correct
19 Correct 143 ms 18656 KB Output is correct
20 Correct 140 ms 18616 KB Output is correct
21 Correct 115 ms 18908 KB Output is correct
22 Correct 115 ms 19032 KB Output is correct
23 Correct 67 ms 18788 KB Output is correct
24 Correct 74 ms 18520 KB Output is correct
25 Correct 83 ms 19800 KB Output is correct
26 Correct 64 ms 21972 KB Output is correct
27 Correct 142 ms 22352 KB Output is correct
28 Correct 134 ms 30800 KB Output is correct
29 Correct 153 ms 30292 KB Output is correct
30 Correct 118 ms 25172 KB Output is correct
31 Correct 140 ms 25128 KB Output is correct
32 Correct 123 ms 25428 KB Output is correct
33 Correct 153 ms 24140 KB Output is correct
34 Correct 108 ms 24916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 3 ms 12636 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 3 ms 12636 KB Output is correct
5 Correct 2 ms 12636 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 3 ms 12636 KB Output is correct
8 Correct 2 ms 12636 KB Output is correct
9 Correct 2 ms 12636 KB Output is correct
10 Correct 3 ms 12636 KB Output is correct
11 Correct 3 ms 12636 KB Output is correct
12 Correct 3 ms 12636 KB Output is correct
13 Correct 2 ms 12636 KB Output is correct
14 Correct 2 ms 12636 KB Output is correct
15 Correct 3 ms 12636 KB Output is correct
16 Correct 3 ms 12636 KB Output is correct
17 Correct 3 ms 12636 KB Output is correct
18 Correct 3 ms 12636 KB Output is correct
19 Correct 3 ms 12632 KB Output is correct
20 Correct 3 ms 12636 KB Output is correct
21 Correct 3 ms 12636 KB Output is correct
22 Correct 2 ms 12636 KB Output is correct
23 Correct 3 ms 12636 KB Output is correct
24 Correct 3 ms 12632 KB Output is correct
25 Correct 3 ms 12636 KB Output is correct
26 Correct 2 ms 12636 KB Output is correct
27 Correct 3 ms 12636 KB Output is correct
28 Correct 4 ms 12636 KB Output is correct
29 Correct 3 ms 12636 KB Output is correct
30 Correct 3 ms 12636 KB Output is correct
31 Correct 4 ms 12636 KB Output is correct
32 Correct 3 ms 12636 KB Output is correct
33 Correct 4 ms 12636 KB Output is correct
34 Correct 3 ms 12636 KB Output is correct
35 Correct 3 ms 12636 KB Output is correct
36 Correct 4 ms 12636 KB Output is correct
37 Correct 4 ms 12632 KB Output is correct
38 Correct 3 ms 12636 KB Output is correct
39 Correct 143 ms 18656 KB Output is correct
40 Correct 140 ms 18616 KB Output is correct
41 Correct 115 ms 18908 KB Output is correct
42 Correct 115 ms 19032 KB Output is correct
43 Correct 67 ms 18788 KB Output is correct
44 Correct 74 ms 18520 KB Output is correct
45 Correct 83 ms 19800 KB Output is correct
46 Correct 64 ms 21972 KB Output is correct
47 Correct 142 ms 22352 KB Output is correct
48 Correct 134 ms 30800 KB Output is correct
49 Correct 153 ms 30292 KB Output is correct
50 Correct 118 ms 25172 KB Output is correct
51 Correct 140 ms 25128 KB Output is correct
52 Correct 123 ms 25428 KB Output is correct
53 Correct 153 ms 24140 KB Output is correct
54 Correct 108 ms 24916 KB Output is correct
55 Correct 17 ms 13404 KB Output is correct
56 Correct 11 ms 13148 KB Output is correct
57 Correct 88 ms 20700 KB Output is correct
58 Correct 30 ms 19664 KB Output is correct
59 Correct 200 ms 26576 KB Output is correct
60 Correct 589 ms 39648 KB Output is correct
61 Correct 191 ms 25636 KB Output is correct
62 Correct 211 ms 25508 KB Output is correct
63 Correct 202 ms 25416 KB Output is correct
64 Correct 572 ms 30920 KB Output is correct
65 Correct 103 ms 26196 KB Output is correct
66 Correct 348 ms 29568 KB Output is correct
67 Correct 100 ms 26052 KB Output is correct
68 Correct 273 ms 29752 KB Output is correct
69 Correct 240 ms 29820 KB Output is correct
70 Correct 246 ms 29252 KB Output is correct