제출 #946855

#제출 시각아이디문제언어결과실행 시간메모리
946855Esgeer경주 (Race) (IOI11_race)C++17
9 / 100
155 ms53236 KiB
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <unistd.h> using namespace __gnu_pbds; template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #ifndef Local #pragma GCC optimize("O3,unroll-loops") #endif #define int long long #define vi vector<int> #define vvi vector<vi> #define pii pair<int, int> #define vpi vector<pii> #define vvpi vector<vpi> #define vb vector<bool> #define vvb vector<vb> #define endl '\n' #define sp << " " << #define F(i, s, n) for(int i = s; i < n; i++) #define pb push_back #define fi first #define se second #include "race.h" int mod = 1e9 + 7; int inf = 1e15; const int N = 2e5+5; vvpi adj(N); map<int, int> mp[N]; int k; int ans = inf; inline void dfs(int node, int par, int depth, int depl) { for(pii go : adj[node]) if(go.fi != par) dfs(go.fi, node, depth+1, depl+go.se); mp[node][depl] = depth+1; for(pii go : adj[node]) if(go.fi != par) { if(mp[go.fi].size() > mp[node].size()) swap(mp[go.fi], mp[node]); for(pii el : mp[go.fi]) { int remK = k - (el.fi - depl); if(remK >= 0 && mp[node][remK + depl]) { ans = min(ans, mp[node][remK + depl] + el.se - 2 - depth*2); } } for(pii el : mp[go.fi]) { if(mp[node][el.fi]) mp[node][el.fi] = min(mp[node][el.fi], el.se); else mp[node][el.fi] = el.se; } } } int32_t best_path(int32_t n, int32_t k, int32_t h[][2], int32_t l[]) { F(i, 0, n-1) { int u = h[i][0], v = h[i][1]; adj[u].pb({v, l[i]}); adj[v].pb({u, l[i]}); } ::k = k; ans = inf; dfs(0, 0, 0, 0); if(ans < inf) return ans; else return -1; } /* void solve() { int32_t n, k; cin >> n >> k; int32_t h[n-1][2]; int32_t l[n-1]; F(i, 0, n-1) cin >> h[i][0] >> h[i][1]; F(i, 0, n-1) cin >> l[i]; cout << best_path(n, k, h, l) << endl; } void setIO() { ios_base::sync_with_stdio(0); cin.tie(0); #ifdef Local freopen("local.in", "r", stdin); freopen("local.out", "w", stdout); #else // freopen("disrupt.in","r",stdin); // freopen("disrupt.out","w",stdout); #endif } signed main() { setIO(); int t = 1; //cin >> t; while(t--) solve(); }*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...