Submission #1088063

#TimeUsernameProblemLanguageResultExecution timeMemory
1088063quan606303Race (IOI11_race)C++11
Compilation error
0 ms0 KiB
///0-0 : what is your motivation, quan606303? ///quan606303 : Hutao /*idea : */ #include <bits/stdc++.h> #define int long long #define ll long long #define INTMAX INT_MAX #define INTMIN INT_MIN #define LONGMAX LLONG_MAX #define LONGMIN LLONG_MIN #define fi first #define se second #define memfull(a,b) memset(a,b,sizeof(a)); #define endl '\n' #define file(a) freopen(a".inp","r",stdin); freopen(a".out","w",stdout); using namespace std; const int MOD=1e9+7; const int maxn=2e5+7; const int maxk=1e6+7; int n,k,del[maxn],child[maxn]; vector<pair<int,int> > adj[maxn]; int ans=1e15,cnt[maxk]; const int inf=1e15; void dfs(int u,int p) { child[u]=1; for (auto v:adj[u]) { if (v.fi!=p&&!del[v.fi]) { dfs(v.fi,u); child[u]+=child[v.fi]; } } } int find_centroid(int u,int p,int N) { for (auto v:adj[u]) { if (v.fi!=p&&!del[v.fi]&&child[v.fi]>N/2) { return find_centroid(v.fi,u,N); } } return u; } int mxdis=0; void cal(int u,int p,bool filling,int distance,int depth) { if (distance>k)return ; mxdis=max(mxdis,distance); if (filling)cnt[distance]=min(cnt[distance],depth); else { ans=min(ans,cnt[k-distance]+depth); // cout<<u<<" "<<distance<<" "<<depth<<" "<<cnt[k-distance]<<endl; } for (auto v:adj[u]) { if (!del[v.fi]&&v.fi!=p)cal(v.fi,u,filling,distance+v.se,depth+1); } } void solve(int u) { dfs(u,0); int N=child[u]; int root=find_centroid(u,0,N); // for (int i=1;i<=n;i++)cout<<child[i]<<endl; del[root]=true; mxdis=0; for (auto v:adj[root]) { if (!del[v.fi]) { // cout<<v.fi<<" "<<root<<" "<<v.se<<" "<<1<<endl; cal(v.fi,root,false,v.se,1); cal(v.fi,root,true,v.se,1); } } fill(cnt+1,cnt+1+mxdis,inf); for (auto v:adj[root]) { if (!del[v.fi])solve(v.fi); } } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // file(""); cin>>n>>k; for (int i=1;i<n;i++) { int x,y,w; cin>>x>>y>>w; x++; y++; adj[x].push_back({y,w}); adj[y].push_back({x,w}); } for (int i=1;i<maxk;i++)cnt[i]=inf; solve(1); if (ans==inf)cout<<-1; else cout<<ans; return 0; }

Compilation message (stderr)

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