Submission #542713

#TimeUsernameProblemLanguageResultExecution timeMemory
542713AmirElarbiRace (IOI11_race)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #define vi vector<int> #define ve vector #define ll long long #define vf vector<float> #define vll vector<pair<ll,ll>> #define ii pair<int,int> #define pll pair<ll,ll> #define vvi vector<vi> #define vii vector<ii> #define gii greater<ii> #define pb push_back #define mp make_pair #define fi first #define se second #define INF 2e9+5 #define eps 1e-7 #define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define MAX_A 1e5+5 #define V 450 #define MAX_N 500000 using namespace std; const int MOD = 1e9+7; //#include "race.h" const int nax = 2e5+5; const int nax2 = 1e6+5; vii adj[nax]; bool vis[nax]; int N, K; int H[MAX_N][2]; int L[MAX_N]; int solution; int sb[nax], cnt[nax2], ans = INF; int dfs(int u, int p){ sb[u] = 1; for(auto x : adj[u]){ if(x.fi == p || vis[x.fi]) continue; sb[u] += dfs(x.fi,u); } return sb[u]; } int getc(int u, int p, int ms){ for(auto x : adj[u]){ if(x.fi == p || vis[x.fi]) continue; if(sb[x.fi]*2 > ms) return getc(x.fi,u,ms); } return u; } void update(int u, int p, bool feel, int dep, int dist){ if(dist > K) return; if(feel) cnt[dist] = min(cnt[dist],dep); else ans = min(ans, dep+cnt[K-dist]); for(auto x : adj[u]){ if(x.fi == p || vis[x.fi]) continue; update(x.fi,u,feel,dep+1,dist+x.se); } } void del(int u, int p, int dist){ if(dist > K) return; cnt[dist] = INF; for(auto x : adj[u]){ if(x.fi == p || vis[x.fi]) continue; del(x.fi,u,dist+x.se); } } void centdec(int u, int p){ int c = getc(u,u,dfs(u,u)); vis[c] = 1; for(auto x : adj[c]){ if(vis[x.fi]) continue; update(x.fi,u,0,1,x.se); update(x.fi,u,1,1,x.se); } for(auto x : adj[c]){ if(vis[x.fi]) continue; del(x.fi,c,x.se); } for(auto x : adj[c]){ if(vis[x.fi]) continue; centdec(x.fi,c); } } int best_path(int n, int k, int h[][2], int s[]) { for (int i = 0; i < n-1; ++i) { adj[h[i][0]].pb({h[i][1],s[i]}); adj[h[i][1]].pb({h[i][0],s[i]}); } for (int i = 0; i <= k; ++i) { cnt[i] = INF; } centdec(0,-1); if(ans == INF) return -1; else return ans; } void read_input() { int i; scanf("%d %d",&N,&K); for(i=0; i<N-1; i++) scanf("%d %d %d",&H[i][0],&H[i][1],&L[i]); scanf("%d",&solution); } int main() { optimise; #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif 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; }

Compilation message (stderr)

race.cpp: In function 'void read_input()':
race.cpp:102:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |   scanf("%d %d",&N,&K);
      |   ~~~~~^~~~~~~~~~~~~~~
race.cpp:104:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |     scanf("%d %d %d",&H[i][0],&H[i][1],&L[i]);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
race.cpp:105:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |   scanf("%d",&solution);
      |   ~~~~~^~~~~~~~~~~~~~~~
race.cpp: In function 'int main()':
race.cpp:112:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  112 |         freopen("input.txt","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
race.cpp:113:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  113 |         freopen("output.txt","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccACSihP.o: in function `read_input()':
race.cpp:(.text+0x420): multiple definition of `read_input()'; /tmp/cc1JLKOM.o:grader.cpp:(.text+0x0): first defined here
/usr/bin/ld: /tmp/ccACSihP.o: in function `main':
race.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc1JLKOM.o:grader.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status