#pragma gcc diagnostic "-std=c++1z"
#include <bits/stdc++.h>
#include "race.h"
using namespace std;
/* /\_/\
(= ._.)
/ > \>
*/
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") // codeforces
// #define int long long
#define fi first
#define se second
#define pb push_back
#define ins insert
#define mp make_pair
#define send {ios_base::sync_with_stdio(false);}
#define help {cin.tie(0);}
#define endl '\n'
#define sz(x) ((long long) (x).size())
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<" ";
#define printl(x) cout<<(x)<<endl
#define dbg(x) cerr<<#x<<" "<<x<<endl
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
const int inf=1e9,MAXN=2e5+5;
vpi g[MAXN]; set<pair<ll,int>> st[MAXN];
int ans;
void dfs(int v,int p,int d,int k,ll curr = 0) {
for(auto [u,w] : g[v]) {
if(u == p) continue;
dfs(u,v,d+1,k,curr+w);
if(st[v].size() < st[u].size()) swap(st[u],st[v]);
for(auto x : st[u]) st[v].ins(x);
}
auto x = st[v].lower_bound({curr+k,0});
if(x != st[v].end() and (*x).fi == curr+k) ans = min(ans,(*x).se - d);
st[v].ins({curr,d});
}
int best_path(int N, int K, int H[][2], int L[]) {
ans = inf;
for(int i=0;i<N;i++) g[i].clear(),st[i].clear();
for(int i=0;i<N-1;i++) {
g[H[i][0]].pb({H[i][1],L[i]});
g[H[i][1]].pb({H[i][0],L[i]});
}
dfs(0,-1,0,K);
return (ans == inf ? -1 : ans);
}
/* int main() {
send help
int H[][2] = { {0,1}, {0,2}, {2,3}, {3,4}, {4,5}, {0,6}, {6,7}, {6,8}, {8,9}, {8,10} };
int L[] = {3,4,5,4,6,3,2,5,6,7};
printl(best_path(11,12,H,L));
return 0;
} */
Compilation message
race.cpp:1: warning: ignoring '#pragma gcc diagnostic' [-Wunknown-pragmas]
1 | #pragma gcc diagnostic "-std=c++1z"
|
race.cpp: In function 'void dfs(int, int, int, int, ll)':
race.cpp:47:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
47 | for(auto [u,w] : g[v]) {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
18012 KB |
Output is correct |
2 |
Correct |
3 ms |
18012 KB |
Output is correct |
3 |
Correct |
3 ms |
18012 KB |
Output is correct |
4 |
Correct |
3 ms |
18012 KB |
Output is correct |
5 |
Correct |
3 ms |
18196 KB |
Output is correct |
6 |
Correct |
3 ms |
18268 KB |
Output is correct |
7 |
Correct |
3 ms |
18192 KB |
Output is correct |
8 |
Correct |
3 ms |
18012 KB |
Output is correct |
9 |
Correct |
3 ms |
18012 KB |
Output is correct |
10 |
Correct |
3 ms |
18012 KB |
Output is correct |
11 |
Correct |
4 ms |
18012 KB |
Output is correct |
12 |
Correct |
3 ms |
18012 KB |
Output is correct |
13 |
Correct |
3 ms |
18008 KB |
Output is correct |
14 |
Correct |
3 ms |
18012 KB |
Output is correct |
15 |
Correct |
3 ms |
18012 KB |
Output is correct |
16 |
Correct |
3 ms |
18012 KB |
Output is correct |
17 |
Correct |
3 ms |
18012 KB |
Output is correct |
18 |
Correct |
3 ms |
18172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
18012 KB |
Output is correct |
2 |
Correct |
3 ms |
18012 KB |
Output is correct |
3 |
Correct |
3 ms |
18012 KB |
Output is correct |
4 |
Correct |
3 ms |
18012 KB |
Output is correct |
5 |
Correct |
3 ms |
18196 KB |
Output is correct |
6 |
Correct |
3 ms |
18268 KB |
Output is correct |
7 |
Correct |
3 ms |
18192 KB |
Output is correct |
8 |
Correct |
3 ms |
18012 KB |
Output is correct |
9 |
Correct |
3 ms |
18012 KB |
Output is correct |
10 |
Correct |
3 ms |
18012 KB |
Output is correct |
11 |
Correct |
4 ms |
18012 KB |
Output is correct |
12 |
Correct |
3 ms |
18012 KB |
Output is correct |
13 |
Correct |
3 ms |
18008 KB |
Output is correct |
14 |
Correct |
3 ms |
18012 KB |
Output is correct |
15 |
Correct |
3 ms |
18012 KB |
Output is correct |
16 |
Correct |
3 ms |
18012 KB |
Output is correct |
17 |
Correct |
3 ms |
18012 KB |
Output is correct |
18 |
Correct |
3 ms |
18172 KB |
Output is correct |
19 |
Incorrect |
3 ms |
18008 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
18012 KB |
Output is correct |
2 |
Correct |
3 ms |
18012 KB |
Output is correct |
3 |
Correct |
3 ms |
18012 KB |
Output is correct |
4 |
Correct |
3 ms |
18012 KB |
Output is correct |
5 |
Correct |
3 ms |
18196 KB |
Output is correct |
6 |
Correct |
3 ms |
18268 KB |
Output is correct |
7 |
Correct |
3 ms |
18192 KB |
Output is correct |
8 |
Correct |
3 ms |
18012 KB |
Output is correct |
9 |
Correct |
3 ms |
18012 KB |
Output is correct |
10 |
Correct |
3 ms |
18012 KB |
Output is correct |
11 |
Correct |
4 ms |
18012 KB |
Output is correct |
12 |
Correct |
3 ms |
18012 KB |
Output is correct |
13 |
Correct |
3 ms |
18008 KB |
Output is correct |
14 |
Correct |
3 ms |
18012 KB |
Output is correct |
15 |
Correct |
3 ms |
18012 KB |
Output is correct |
16 |
Correct |
3 ms |
18012 KB |
Output is correct |
17 |
Correct |
3 ms |
18012 KB |
Output is correct |
18 |
Correct |
3 ms |
18172 KB |
Output is correct |
19 |
Incorrect |
72 ms |
41516 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
18012 KB |
Output is correct |
2 |
Correct |
3 ms |
18012 KB |
Output is correct |
3 |
Correct |
3 ms |
18012 KB |
Output is correct |
4 |
Correct |
3 ms |
18012 KB |
Output is correct |
5 |
Correct |
3 ms |
18196 KB |
Output is correct |
6 |
Correct |
3 ms |
18268 KB |
Output is correct |
7 |
Correct |
3 ms |
18192 KB |
Output is correct |
8 |
Correct |
3 ms |
18012 KB |
Output is correct |
9 |
Correct |
3 ms |
18012 KB |
Output is correct |
10 |
Correct |
3 ms |
18012 KB |
Output is correct |
11 |
Correct |
4 ms |
18012 KB |
Output is correct |
12 |
Correct |
3 ms |
18012 KB |
Output is correct |
13 |
Correct |
3 ms |
18008 KB |
Output is correct |
14 |
Correct |
3 ms |
18012 KB |
Output is correct |
15 |
Correct |
3 ms |
18012 KB |
Output is correct |
16 |
Correct |
3 ms |
18012 KB |
Output is correct |
17 |
Correct |
3 ms |
18012 KB |
Output is correct |
18 |
Correct |
3 ms |
18172 KB |
Output is correct |
19 |
Incorrect |
3 ms |
18008 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |