제출 #405253

#제출 시각아이디문제언어결과실행 시간메모리
405253jaaguptamme경주 (Race) (IOI11_race)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> const int N=200005,M=20; using namespace std; typedef long long ll; typedef pair<ll,ll>pii; vector<pii>g[N]; vector<ll>r[N],sub[N]; ll pr[M][N],cst[M][N],dep[N],sz[N],n,k,dn[N],fa[N]; void D(ll u,ll p=-1){ for(auto el:g[u]){ auto v=el.first,w=el.second; if(v==p)continue; dep[v]=dep[u]+1; D(v,u); pr[0][v]=u; cst[0][v]=w; } } ll calc(ll u,ll p=-1){ if(dn[u])return 0; sz[u]=0; for(auto el:g[u]){ auto v=el.first; if(v==p)continue; if(dn[v])continue; sz[u]+=calc(v,u)+1; } return sz[u]; } ll cent(ll u,ll n,ll p=-1){ for(auto el:g[u]){ auto v=el.first; if(v==p)continue; if(dn[v])continue; if(sz[v]>=n/2)return cent(v,n,u); } return u; } void solve(ll u,ll p=-1){ if(dn[u])return; calc(u,p); ll c=cent(u,sz[u],-1); sub[c].push_back(c); fa[c]=p; if(p!=-1){ r[p].push_back(c); ll cur=c; while(fa[cur]!=-1){ cur=fa[cur]; sub[cur].push_back(c); } //cout<<p<<' '<<c<<'\n'; } dn[c]=1; for(auto el:g[c]){ auto v=el.first; if(dn[v])continue; solve(v,c); } } pii dist(ll u,ll v){ if(dep[u]<dep[v])swap(u,v); ll ans=0,ln=0; for(ll j=M-1;j>=0;j--){ if(dep[u]-(1<<j)>=dep[v]){ ans+=cst[j][u]; ln+=1<<j; u=pr[j][u]; } } if(u==v)return {ans,ln}; for(ll j=M-1;j>=0;j--){ if(pr[j][u]!=pr[j][v]){ ans+=cst[j][u]+cst[j][v]; u=pr[j][u]; v=pr[j][v]; ln+=2*(1<<j); } } ans+=cst[0][u]+cst[0][v]; ln+=2; return {ans,ln}; } vector<ll>kaugus(N,0),pikkus(N,0); int main() {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>n>>k; for(ll i=1;i<n;i++){ int u,v,c;cin>>u>>v>>c; g[u].push_back({v,c}); g[v].push_back({u,c}); } D(0,-1); for(ll j=1;j<M;j++){ for(ll i=0;i<n;i++){ pr[j][i]=pr[j-1][pr[j-1][i]]; cst[j][i]=cst[j-1][i]+cst[j-1][pr[j-1][i]]; } } solve(0,-1); /*for(int i=0;i<n;i++){ cout<<i<<": "; for(auto j:sub[i])cout<<j<<' '; cout<<'\n'; }*/ ll res=INT_MAX; for(ll i=0;i<n;i++){ //vector<vector<pii>>vals; //cout<<i<<endl; for(auto j:sub[i]){ auto el=dist(i,j); kaugus[j]=el.first; pikkus[j]=el.second; //cout<<i<<' '<<j<<' '<<kaugus[j]<<' '<<pikkus[j]<<'\n'; } map<ll,ll>mp; mp[0]=0; for(auto j:r[i]){ for(auto l:sub[j]){ if(mp.count(k-kaugus[l]))res=min(res,pikkus[l]+mp[k-kaugus[l]]); } for(auto l:sub[j]){ if(!mp.count(kaugus[l]))mp[kaugus[l]]=INT_MAX; mp[kaugus[l]]=min(mp[kaugus[l]],pikkus[l]); } } } if(res!=INT_MAX)cout<<res<<' '; else cout<<-1<<endl; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

/usr/bin/ld: /tmp/ccG4KXkn.o: in function `main':
race.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccxlqNHl.o:grader.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccxlqNHl.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