# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1093762 |
2024-09-27T11:29:11 Z |
asli_bg |
Race (IOI11_race) |
C++11 |
|
98 ms |
45372 KB |
#pragma GCC optimize("O3,unroll-loops")
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define FOR(i,a) for(int i=0;i<(a);i++)
#define FORE(i,a,b) for(int i=(a);i<(b);i++)
#define cont(x) {for(auto el:x) cout<<el<<' ';cout<<endl;}
#define contp(x) {for(auto el:x) cout<<el.fi<<'-'<<el.se<<' ';cout<<endl;}
#define sp <<" "<<
#define mid (l+r)/2
#define endl '\n'
#define DEBUG(X) {cout<<#X<<' '<<(X)<<endl;}
#define carp(x,y) ((x%MOD)*(y%MOD))%MOD
#define topla(x,y) ((x%MOD)+(y%MOD))%MOD
typedef vector<int> vi;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<bool> vb;
const int MAXN=3e5+5;
const int INF=INT_MAX;
const int MOD=1e9+7;
vii adj[MAXN];
int n,k;
ll res;
pll t[MAXN];
set<pll> s[MAXN];
void merge(set<pll>& a,set<pll>& b, int nd){
if(a.size()<b.size()) swap(a,b);
//setteki elemanlar--> {dist,edge sayisi}
//adjdeki elemanlar--> {kom,dist}
auto aranan=k+2*t[nd].se;
auto cikar=t[nd].fi;
//önce cevabı bul
for(auto el:b){
auto deg=aranan-el.fi;
auto it=a.lower_bound({deg,0});
auto bir=(*it).fi; //distance
auto iki=(*it).se; //no of edges
if(bir==deg){
res=min(res,iki+el.se-2*cikar);
}
}
//sonra insertle
for(auto el:b) a.insert(el);
}
void dfs(int nd,int ata,ll h,ll edg){
t[nd]={edg,h};
for(auto el:adj[nd]){
auto kom=el.fi;
auto cost=el.se;
if(kom!=ata){
dfs(kom,nd,h+cost,edg+1);
merge(s[nd],s[kom],nd);
}
}
auto aranan=k+t[nd].se;
auto cikar=t[nd].fi;
auto it=s[nd].lower_bound({aranan,0});
if((*it).fi==aranan){
res=min(res,(*it).se-cikar);
}
s[nd].insert({t[nd].se,t[nd].fi});
}
int best_path(int N, int K, int H[][2], int L[]){
//#define int long long
res=INF;
k=K;
n=N;
FOR(i,n-1){
adj[H[i][0]+1].pb({H[i][1]+1,L[i]});
adj[H[i][1]+1].pb({H[i][0]+1,L[i]});
}
dfs(1,0,0,0);
//#undef int
if(res==INF) res=-1;
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
21596 KB |
Output is correct |
2 |
Correct |
10 ms |
21600 KB |
Output is correct |
3 |
Correct |
9 ms |
21468 KB |
Output is correct |
4 |
Correct |
10 ms |
21592 KB |
Output is correct |
5 |
Correct |
10 ms |
21480 KB |
Output is correct |
6 |
Correct |
10 ms |
21592 KB |
Output is correct |
7 |
Correct |
9 ms |
21456 KB |
Output is correct |
8 |
Correct |
9 ms |
21596 KB |
Output is correct |
9 |
Correct |
10 ms |
21596 KB |
Output is correct |
10 |
Correct |
9 ms |
21608 KB |
Output is correct |
11 |
Correct |
9 ms |
21596 KB |
Output is correct |
12 |
Correct |
9 ms |
21604 KB |
Output is correct |
13 |
Correct |
10 ms |
21596 KB |
Output is correct |
14 |
Correct |
10 ms |
21620 KB |
Output is correct |
15 |
Correct |
10 ms |
21592 KB |
Output is correct |
16 |
Correct |
11 ms |
21592 KB |
Output is correct |
17 |
Correct |
11 ms |
21596 KB |
Output is correct |
18 |
Correct |
10 ms |
21416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
21596 KB |
Output is correct |
2 |
Correct |
10 ms |
21600 KB |
Output is correct |
3 |
Correct |
9 ms |
21468 KB |
Output is correct |
4 |
Correct |
10 ms |
21592 KB |
Output is correct |
5 |
Correct |
10 ms |
21480 KB |
Output is correct |
6 |
Correct |
10 ms |
21592 KB |
Output is correct |
7 |
Correct |
9 ms |
21456 KB |
Output is correct |
8 |
Correct |
9 ms |
21596 KB |
Output is correct |
9 |
Correct |
10 ms |
21596 KB |
Output is correct |
10 |
Correct |
9 ms |
21608 KB |
Output is correct |
11 |
Correct |
9 ms |
21596 KB |
Output is correct |
12 |
Correct |
9 ms |
21604 KB |
Output is correct |
13 |
Correct |
10 ms |
21596 KB |
Output is correct |
14 |
Correct |
10 ms |
21620 KB |
Output is correct |
15 |
Correct |
10 ms |
21592 KB |
Output is correct |
16 |
Correct |
11 ms |
21592 KB |
Output is correct |
17 |
Correct |
11 ms |
21596 KB |
Output is correct |
18 |
Correct |
10 ms |
21416 KB |
Output is correct |
19 |
Correct |
10 ms |
21596 KB |
Output is correct |
20 |
Correct |
11 ms |
21548 KB |
Output is correct |
21 |
Correct |
11 ms |
21596 KB |
Output is correct |
22 |
Correct |
10 ms |
21852 KB |
Output is correct |
23 |
Correct |
11 ms |
21852 KB |
Output is correct |
24 |
Correct |
11 ms |
21852 KB |
Output is correct |
25 |
Correct |
11 ms |
21852 KB |
Output is correct |
26 |
Correct |
11 ms |
21852 KB |
Output is correct |
27 |
Correct |
10 ms |
21596 KB |
Output is correct |
28 |
Correct |
11 ms |
21852 KB |
Output is correct |
29 |
Correct |
10 ms |
21852 KB |
Output is correct |
30 |
Correct |
10 ms |
21848 KB |
Output is correct |
31 |
Correct |
12 ms |
21720 KB |
Output is correct |
32 |
Correct |
11 ms |
21852 KB |
Output is correct |
33 |
Correct |
11 ms |
21852 KB |
Output is correct |
34 |
Correct |
11 ms |
21596 KB |
Output is correct |
35 |
Correct |
11 ms |
21720 KB |
Output is correct |
36 |
Correct |
11 ms |
21592 KB |
Output is correct |
37 |
Correct |
12 ms |
21596 KB |
Output is correct |
38 |
Correct |
10 ms |
21596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
21596 KB |
Output is correct |
2 |
Correct |
10 ms |
21600 KB |
Output is correct |
3 |
Correct |
9 ms |
21468 KB |
Output is correct |
4 |
Correct |
10 ms |
21592 KB |
Output is correct |
5 |
Correct |
10 ms |
21480 KB |
Output is correct |
6 |
Correct |
10 ms |
21592 KB |
Output is correct |
7 |
Correct |
9 ms |
21456 KB |
Output is correct |
8 |
Correct |
9 ms |
21596 KB |
Output is correct |
9 |
Correct |
10 ms |
21596 KB |
Output is correct |
10 |
Correct |
9 ms |
21608 KB |
Output is correct |
11 |
Correct |
9 ms |
21596 KB |
Output is correct |
12 |
Correct |
9 ms |
21604 KB |
Output is correct |
13 |
Correct |
10 ms |
21596 KB |
Output is correct |
14 |
Correct |
10 ms |
21620 KB |
Output is correct |
15 |
Correct |
10 ms |
21592 KB |
Output is correct |
16 |
Correct |
11 ms |
21592 KB |
Output is correct |
17 |
Correct |
11 ms |
21596 KB |
Output is correct |
18 |
Correct |
10 ms |
21416 KB |
Output is correct |
19 |
Incorrect |
98 ms |
45372 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
21596 KB |
Output is correct |
2 |
Correct |
10 ms |
21600 KB |
Output is correct |
3 |
Correct |
9 ms |
21468 KB |
Output is correct |
4 |
Correct |
10 ms |
21592 KB |
Output is correct |
5 |
Correct |
10 ms |
21480 KB |
Output is correct |
6 |
Correct |
10 ms |
21592 KB |
Output is correct |
7 |
Correct |
9 ms |
21456 KB |
Output is correct |
8 |
Correct |
9 ms |
21596 KB |
Output is correct |
9 |
Correct |
10 ms |
21596 KB |
Output is correct |
10 |
Correct |
9 ms |
21608 KB |
Output is correct |
11 |
Correct |
9 ms |
21596 KB |
Output is correct |
12 |
Correct |
9 ms |
21604 KB |
Output is correct |
13 |
Correct |
10 ms |
21596 KB |
Output is correct |
14 |
Correct |
10 ms |
21620 KB |
Output is correct |
15 |
Correct |
10 ms |
21592 KB |
Output is correct |
16 |
Correct |
11 ms |
21592 KB |
Output is correct |
17 |
Correct |
11 ms |
21596 KB |
Output is correct |
18 |
Correct |
10 ms |
21416 KB |
Output is correct |
19 |
Correct |
10 ms |
21596 KB |
Output is correct |
20 |
Correct |
11 ms |
21548 KB |
Output is correct |
21 |
Correct |
11 ms |
21596 KB |
Output is correct |
22 |
Correct |
10 ms |
21852 KB |
Output is correct |
23 |
Correct |
11 ms |
21852 KB |
Output is correct |
24 |
Correct |
11 ms |
21852 KB |
Output is correct |
25 |
Correct |
11 ms |
21852 KB |
Output is correct |
26 |
Correct |
11 ms |
21852 KB |
Output is correct |
27 |
Correct |
10 ms |
21596 KB |
Output is correct |
28 |
Correct |
11 ms |
21852 KB |
Output is correct |
29 |
Correct |
10 ms |
21852 KB |
Output is correct |
30 |
Correct |
10 ms |
21848 KB |
Output is correct |
31 |
Correct |
12 ms |
21720 KB |
Output is correct |
32 |
Correct |
11 ms |
21852 KB |
Output is correct |
33 |
Correct |
11 ms |
21852 KB |
Output is correct |
34 |
Correct |
11 ms |
21596 KB |
Output is correct |
35 |
Correct |
11 ms |
21720 KB |
Output is correct |
36 |
Correct |
11 ms |
21592 KB |
Output is correct |
37 |
Correct |
12 ms |
21596 KB |
Output is correct |
38 |
Correct |
10 ms |
21596 KB |
Output is correct |
39 |
Incorrect |
98 ms |
45372 KB |
Output isn't correct |
40 |
Halted |
0 ms |
0 KB |
- |