Submission #420287

#TimeUsernameProblemLanguageResultExecution timeMemory
420287KalasLavasRace (IOI11_race)C++14
9 / 100
3064 ms10060 KiB
#include <bits/stdc++.h> #include "race.h" using namespace std; mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); //#undef LOCALKL #define IO \ ios_base::sync_with_stdio(0);(cin).tie(0);(cout).tie(0) #define y1 y1_ #define prev prev_ #define all(a) (a).begin(),(a).end() #define pb push_back #define eb emplace_back #define F first #define S second #ifdef LOCALKL // #define cerr cerr<<"\33[1;32m" // #define cout cout<<"\33[0m" #else #ifndef OO #define endl '\n' #define cerr if(1){}else cerr #endif #endif #define OK cerr<<"OK\n"<<endl; #define setpre(k) fixed<<setprecision(k) #define mmset(k,y) memset(k,y,sizeof(k)) #define sz(x) ((int)(x).size()) using pii = pair<int,int>; using pll = pair<long long,long long>; using ull = unsigned long long; using intt = long long; using ll = long long; using ld = long double; const ll m9 = 998244353; const ll m7 = 1000000007; const ll m18 = 1000000000000000000; const ll i127 = 2139062143; const ll l127 = 9187201950435737471; int n, k, ans = i127; bool removed[200002]; vector<pii>g[200002]; // map<ll,int>m; int m[102]; void calc(int v, int parent, int dis, int depth) { if(dis > k) return; if(m[k-dis] or dis==k) ans=min(ans, m[k-dis]+depth); for(pii u : g[v]) if(u.F!=parent and !removed[u.F]) calc(u.F, v, dis+u.S, depth+1); } void add_dis(int v, int parent, int dis, int depth) { if(dis >= k) return; m[dis] = depth; for(pii u : g[v]) if(u.F!=parent and !removed[u.F]) add_dis(u.F, v, dis+u.S, depth+1); } int best_path(int N, int K, int H[][2], int L[]) { n=N; k=K; for(int i=0;i<n-1;i++) { g[H[i][0]].emplace_back(H[i][1], L[i]); g[H[i][1]].emplace_back(H[i][0], L[i]); } for(int i=0;i<n;i++) { // m.clear(); memset(m, 0, sizeof(m)); for(pii u : g[i]) if(!removed[u.F]) { calc(u.F, i, u.S, 1); add_dis(u.F, i, u.S, 1); } // cerr<<i<<' '<<ans<<endl; } return ans==i127?-1:ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...