Submission #1140914

#TimeUsernameProblemLanguageResultExecution timeMemory
1140914why1Race (IOI11_race)C++20
Compilation error
0 ms0 KiB
#include "race.h" #include <bits/stdc++.h> using namespace std; #define pii pair<int,int> #define fi first #define se second #define sz size() #define pb push_back const int N = 2e5; int n,k; int h[N+1][2],l[N+1]; vector<pii> g[N+1]; int dw[N+1],d[N+1]; set<pii> st[N+1]; int ans=1e9; void calc(int v,int pr){ for(auto [to,i]: g[v]){ if(to!=pr){ dw[to]=dw[v]+l[i]; d[to]=d[v]+1; calc(to,v); } } } void dfs(int v,int pr){ st[v].insert({dw[v],v}); for(auto [to,i]: g[v]){ if(to!=pr){ dfs(to,v); if(st[v].sz<st[to].sz) st[v].swap(st[to]); for(auto [D,j]: st[to]){ int x=k+2*dw[v]-D; auto it=st[v].lower_bound({x,0}); if(it!=st[v].end() && it->fi==x){ ans=min(ans,d[j]+d[it->se]-2*d[v]); } } for(auto j: st[to]){ st[v].insert(j); } } } } int best_path(int n, int k, int h[][2], int l[]) //void solve(){ cin>>n>>k; for(int i = 1; i <= n-1; i++){ cin>>h[i][0]>>h[i][1]>>l[i]; h[i][0]++,h[i][1]++; g[h[i][0]].pb({h[i][1],i}); g[h[i][1]].pb({h[i][0],i}); } calc(1,-1); dfs(1,-1); /* for(int i = 1; i <= n; i++){ cout<<i<<": "; for(auto j: st[i]){ cout<<"{"<<j.fi<<" "<<j.se<<"} "; } cout<<"\n"; } cout<<ans<<"\n"; */ return ans; } /* int main(){ solve(); return 0; } */

Compilation message (stderr)

race.cpp:55:9: error: expected initializer before 'cin'
   55 |         cin>>n>>k;
      |         ^~~
race.cpp:56:9: error: expected unqualified-id before 'for'
   56 |         for(int i = 1; i <= n-1; i++){
      |         ^~~
race.cpp:56:24: error: 'i' does not name a type; did you mean 'fi'?
   56 |         for(int i = 1; i <= n-1; i++){
      |                        ^
      |                        fi
race.cpp:56:34: error: 'i' does not name a type; did you mean 'fi'?
   56 |         for(int i = 1; i <= n-1; i++){
      |                                  ^
      |                                  fi
race.cpp:63:13: error: expected constructor, destructor, or type conversion before '(' token
   63 |         calc(1,-1);
      |             ^
race.cpp:64:12: error: expected constructor, destructor, or type conversion before '(' token
   64 |         dfs(1,-1);
      |            ^
race.cpp:76:9: error: expected unqualified-id before 'return'
   76 |         return ans;
      |         ^~~~~~
race.cpp:77:1: error: expected declaration before '}' token
   77 | }
      | ^