Submission #982373

#TimeUsernameProblemLanguageResultExecution timeMemory
982373Godgift42Race (IOI11_race)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; vector<vector<pair<int,int>>> adj; int n, k; vector<int> subtr; vector<bool> vis; unordered_map<int,int> mp; int ans=INT_MAX; void findsize(int u, int p){ subtr[u]=1; for(auto [v,w]:adj[u]){ if(v!=p and !vis[v]){ findsize(v,u); subtr[u]+=subtr[v]; } } } int findcentroid(int u, int p, int sz){ for(auto [v,w]:adj[u]){ if(v!=p and !vis[v] and subtr[v]>sz/2)return findcentroid(v,u,sz); } return u; } void dfs1(int u, int p, int dist, int depth){ if(dist>k)return; if(mp[k-dist] or k==dist) ans=min(ans,mp[k-dist]+depth); for(auto [v,w]:adj[u]){ if(v!=p and !vis[v]){ dfs1(v,u,dist+w,depth+1); } } } void dfs2(int u, int p, int dist, int depth){ if(dist>k)return; if(mp[dist]==0)mp[dist]=depth; else mp[dist]=min(mp[dist],depth); for(auto [v,w]:adj[u]){ if(v!=p and !vis[v]){ dfs2(v,u,dist+w,depth+1); } } } void buildcentroid(int u, int p){ findsize(u,u); int c=findcentroid(u,u,subtr[u]); vis[c]=true; for(auto [v,w]:adj[c]){ if(v!=p and !vis[v]){ dfs1(v,c,w,1); dfs2(v,c,w,1); } } mp.clear(); for(auto [v,w]:adj[c]){ if(!vis[v])buildcentroid(v,c); } } int bestpath(int N, int K, int H[][2], int L[]){ n=N; k=K; adj.resize(n); subtr.resize(n); vis.resize(n); for(int i=0;i<n-1;i++){ adj[H[i][1]].push_back({H[i][0],L[i]}); adj[H[i][0]].push_back({H[i][1],L[i]}); } buildcentroid(0,-1); if(ans==INT_MAX)return -1; return ans; }

Compilation message (stderr)

race.cpp: In function 'void findsize(int, int)':
race.cpp:14:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   14 |     for(auto [v,w]:adj[u]){
      |              ^
race.cpp: In function 'int findcentroid(int, int, int)':
race.cpp:23:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   23 |     for(auto [v,w]:adj[u]){
      |              ^
race.cpp: In function 'void dfs1(int, int, int, int)':
race.cpp:32:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   32 |     for(auto [v,w]:adj[u]){
      |              ^
race.cpp: In function 'void dfs2(int, int, int, int)':
race.cpp:43:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   43 |     for(auto [v,w]:adj[u]){
      |              ^
race.cpp: In function 'void buildcentroid(int, int)':
race.cpp:54:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   54 |     for(auto [v,w]:adj[c]){
      |              ^
race.cpp:61:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   61 |     for(auto [v,w]:adj[c]){
      |              ^
/usr/bin/ld: /tmp/ccaonVI2.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