Submission #1004833

#TimeUsernameProblemLanguageResultExecution timeMemory
1004833YassirSalamaRace (IOI11_race)C++17
31 / 100
185 ms190964 KiB
#include "race.h" #include <bits/stdc++.h> using namespace std; const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; #define endl "\n" using ull=unsigned long long; using ll=long long; using pii=pair<int,int>; const int mod=1e9+7; #define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n"; template <typename T> istream& operator>>(istream& is, vector<T> &a) { copy_n(istream_iterator<T>(is), a.size(), a.begin()); return is;} #ifdef IOI template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } void dbg_out() { cout << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); } #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__); #else #define dbg(...) 1337; #endif #define pb push_back #define F first #define S second #define all(v) v.begin(),v.end() const int mxN=2e5+100; const int mxK=200; int dp[mxN][mxK]; vector<pii> v[mxN]; int ans=1e9; int k; void dfs(int node,int par){ dp[node][0]=0; for(auto x:v[node]){ if(x.F==par) continue; dfs(x.F,node); for(int i=x.S;i<=k;i++){ ans=min(ans,dp[node][k-i]+dp[x.F][i-x.S]+1); // dbg(node,i,dp[node][k-i],dp[x.F][i-x.S]) } for(int i=x.S;i<=k;i++){ dp[node][i]=min(dp[node][i], dp[x.F][i-x.S]+1); } } } int best_path(int N, int K, int H[][2], int L[]){ k=K; for(int i=0;i<mxN;i++){ for(int j=0;j<mxK;j++){ dp[i][j]=1e9; } } for(int i=0;i+1<N;i++){ v[H[i][0]].pb({H[i][1],L[i]}); v[H[i][1]].pb({H[i][0],L[i]}); } dfs(0,0); // dbg(ans) if(ans==1e9){ return -1; } return ans; } #ifdef IOI #include "race.h" #include <stdio.h> #include <stdlib.h> #define MAX_N 500000 static int N, K; static int H[MAX_N][2]; static int L[MAX_N]; static int solution; inline void my_assert(int e) {if (!e) abort();} void read_input() { int i; my_assert(2==scanf("%d %d",&N,&K)); for(i=0; i<N-1; i++) my_assert(3==scanf("%d %d %d",&H[i][0],&H[i][1],&L[i])); my_assert(1==scanf("%d",&solution)); } int main() { int ans; read_input(); ans = best_path(N,K,H,L); if(ans==solution) printf("Correct.\n"); else printf("Incorrect. Returned %d, Expected %d.\n",ans,solution); return 0; } #endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...