이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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]) {
auto y = st[v].lower_bound({k-x.fi+2*curr,0});
if(y != st[v].end() and (*y).fi == k-x.fi+2*curr) ans = min(ans,(*y).se + x.se - 2 * d);
}
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} };
int L[] = {2,2};
printl(best_path(3,4,H,L));
return 0;
} */
컴파일 시 표준 에러 (stderr) 메시지
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]) {
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |