제출 #679295

#제출 시각아이디문제언어결과실행 시간메모리
679295bachhoangxuanRace (IOI11_race)C++17
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; #define maxn 200005 #define int long long #define pii pair<int,int> int n,k,son[maxn],lans,nans,d[maxn],dist[maxn]; vector<pii> edge[maxn]; map<int,pii> mp; vector<int> p; int pre_dfs(int u,int par){ int Max=0,cu=1; d[u]=d[par]+1; for(pii v:edge[u]){ if(v.first==par) continue; dist[v.first]=dist[u]+v.second; int cv=pre_dfs(v.first,u); if(cv>Max){Max=cv;son[u]=v.first;} cu+=cv; } return cu; } void add(int u){ if(mp.find(dist[u])==mp.end() || mp[dist[u]].first>d[u]) mp[dist[u]]={d[u],1}; else if(mp[dist[u]].first==d[u]) mp[dist[u]].second++; } void update(int l,int u,int anc){ if(mp.find(l)!=mp.end()){ if(lans>mp[l].first+d[u]-2*d[anc]){ lans=mp[l].first+d[u]-2*d[anc]; nans=mp[l].second; } else if(lans==mp[l].first+d[u]-2*d[anc]) nans+=mp[l].second; } } void cal(int u,int par,int anc){ p.push_back(u); update(k+2*dist[anc]-dist[u],u,anc); for(pii v:edge[u]){ if(v.first==par) continue; cal(v.first,u,anc); } } void dfs(int u,int par,int t){ for(pii v:edge[u]){ if(v.first!=son[u] && v.first!=par) dfs(v.first,u,1); } if(son[u]) dfs(son[u],u,0); //cout << u << " " << dist[u] << ' ' << par << ' ' << t << '\n'; add(u);update(dist[u]+k,u,u); for(pii v:edge[u]){ if(v.first==par || v.first==son[u]) continue; cal(v.first,u,u); for(int x:p) add(x); p.clear(); } //for(auto it:mp) cout << it.first << " " << it.second.first << " " << it.second.second << '\n'; if(t) mp.clear(); } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); cin >> n >> k; for(int i=1;i<n;i++){ int u,v,w;cin >> u >> v >> w; u++;v++; edge[u].push_back({v,w}); edge[v].push_back({u,w}); } lans=LLONG_MAX; pre_dfs(1,0);dfs(1,0,0); if(lans==LLONG_MAX) cout << -1 << '\n'; else cout << lans << '\n'; }

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

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