Submission #680473

#TimeUsernameProblemLanguageResultExecution timeMemory
680473tommy1024Race (IOI11_race)C++17
Compilation error
0 ms0 KiB
#include <iostream> #include <vector> #include <algorithm> #include <map> #define pii pair<int,int> using namespace std; typedef long long ll; const int inf=1e9; int N,K; int a,b,c; int sz[200005],kill[200005]; int ans=inf; vector <pii> v[200005]; map <int,int> m,tmp; int get_sz(int x,int par){ sz[x]=1; // reset for(auto[i,d]:v[x]){ if(i==par)continue; if(kill[i])continue; sz[x]+=get_sz(i,x); } return sz[x]; } int get_cent(int x,int par,int c){ for(auto[i,d]:v[x]){ if(i==par)continue; if(kill[i])continue; if(sz[i]>c)return get_cent(i,x,c); } return x; } void sch(int x,int d,int st,int tab){ // step if(d>K)return; auto it=tmp.find(d); if(it==tmp.end())tmp[d]=st; else tmp[d]=min(tmp[d],st); for(auto[i,D]:v[x]){ if(i==tab)continue; if(kill[i])continue; sch(i,d+D,st+1,x); } } void update(){ for(auto[a,b]:tmp){ auto it=m.find(a); if(it==m.end())m[a]=b; else m[a]=min(m[a],b); } } void f(int x){ int s=get_sz(x,-1); // already considered in kill[] int ct=get_cent(x,-1,s/2); kill[ct]=1; for(auto[i,d]:v[ct]){ tmp.clear(); sch(i,d,1,x); for(auto[a,b]:tmp){ auto it=m.find(K-a); if(it!=m.end()){ ans=min(ans,m[K-a]+b); //printf("[%d %d]",m[K-a],b); } } update(); } m.clear(); m[0]=0; for(auto[i,d]:v[ct]){ if(kill[i])continue; f(i); } kill[ct]=0; } int main() { scanf("%d%d",&N,&K); for(int i=1;i<=N-1;i++){ scanf("%d%d%d",&a,&b,&c); v[a].push_back({b,c}); v[b].push_back({a,c}); } m[0]=0; f(0); if(ans==inf)ans=-1; printf("%d",ans); return 0; }

Compilation message (stderr)

race.cpp: In function 'int main()':
race.cpp:76:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |     scanf("%d%d",&N,&K);
      |     ~~~~~^~~~~~~~~~~~~~
race.cpp:78:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         scanf("%d%d%d",&a,&b,&c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccz0I3XZ.o: in function `main':
race.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccIzDHh0.o:grader.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccIzDHh0.o: in function `main':
grader.cpp:(.text.startup+0x28): undefined reference to `best_path(int, int, int (*) [2], int*)'
collect2: error: ld returned 1 exit status