Submission #638419

#TimeUsernameProblemLanguageResultExecution timeMemory
638419ojoConmigoTraffic (IOI10_traffic)C++17
Compilation error
0 ms0 KiB
#include "traffic.h" //#include <bits/stdc++.h> //using namespace std; vector<vector<int>> g; vector<long long> fir,sec,ans,subarbol; void dfs1(int nodo, int p, int pp[]){ for(int v : g[nodo]){ if(v == p)continue; dfs1(v,nodo,pp); subarbol[nodo] += subarbol[v] + pp[v]; if(subarbol[v] + pp[v] > fir[nodo]){ sec[nodo] = fir[nodo]; fir[nodo] = subarbol[v] + pp[v]; }else if(subarbol[v] + pp[v] > sec[nodo]){ sec[nodo] = subarbol[v] + pp[v]; } } //cout << nodo << " " << fir[nodo] << " " << sec[nodo] << endl; } void dfs2(int nodo, int p, long long cont, int pp[]){ ans[nodo] = max(cont,fir[nodo]); for(int v : g[nodo]){ if(v == p)continue; if(subarbol[v] + pp[v] == fir[nodo]) dfs2(v,nodo,(cont > sec[nodo] ? cont + subarbol[nodo] - subarbol[v] : sec[nodo] + pp[nodo]),pp); else dfs2(v,nodo,cont + subarbol[nodo] - subarbol[v], pp); } } int LocateCentre(int N, int pp[], int S[], int D[]) { g.resize(N); for(int i=0; i<N-1; i++){ int x,y; x = S[i]; y = D[i]; //cout << x << " " << y << endl; g[x].push_back(y); g[y].push_back(x); } fir.assign(N,0); sec.assign(N,0); subarbol.assign(N,0); ans.resize(N); dfs1(0,-1,pp); dfs2(0,-1,0,pp); int arena = 0; long long congestion = 2e9 + 1; for(int i=0; i<N; i++){ //cout << i << " " << ans[i] << " " << congestion << endl; if(ans[i] < congestion){ congestion = ans[i]; arena = i; } } //cout << arena << endl; return arena; /* long long pre[N]; pre[0] = pp[0]; for(int i=1; i<N; i++){ pre[i] = pre[i-1] + pp[i]; } int sol = 0; long long congestion = pre[N-1] - pre[0]; for(int i=1; i<N; i++){ long long mayor = (pre[i-1] > pre[N-1] - pre[i] ? pre[i-1] : pre[N-1] - pre[i]); //cout << mayor << endl; if(mayor < congestion){ congestion = mayor; sol = i; } } return sol; */ } /* int main(){ int n; cin >> n; int pp[n],s[n-1],d[n-1]; for(int i=0; i<n; i++){ cin >> pp[i]; } for(int i=0; i<n-1; i++){ cin >> s[i] >> d[i]; } cout << LocateCentre(n,pp,s,d) << endl; } */

Compilation message (stderr)

traffic.cpp:5:1: error: 'vector' does not name a type
    5 | vector<vector<int>> g;
      | ^~~~~~
traffic.cpp:6:1: error: 'vector' does not name a type
    6 | vector<long long> fir,sec,ans,subarbol;
      | ^~~~~~
traffic.cpp: In function 'void dfs1(int, int, int*)':
traffic.cpp:9:16: error: 'g' was not declared in this scope
    9 |    for(int v : g[nodo]){
      |                ^
traffic.cpp:12:7: error: 'subarbol' was not declared in this scope
   12 |       subarbol[nodo] += subarbol[v] + pp[v];
      |       ^~~~~~~~
traffic.cpp:13:32: error: 'fir' was not declared in this scope
   13 |       if(subarbol[v] + pp[v] > fir[nodo]){
      |                                ^~~
traffic.cpp:14:10: error: 'sec' was not declared in this scope
   14 |          sec[nodo] = fir[nodo];
      |          ^~~
traffic.cpp:16:38: error: 'sec' was not declared in this scope
   16 |       }else if(subarbol[v] + pp[v] > sec[nodo]){
      |                                      ^~~
traffic.cpp: In function 'void dfs2(int, int, long long int, int*)':
traffic.cpp:24:4: error: 'ans' was not declared in this scope
   24 |    ans[nodo] = max(cont,fir[nodo]);
      |    ^~~
traffic.cpp:24:25: error: 'fir' was not declared in this scope
   24 |    ans[nodo] = max(cont,fir[nodo]);
      |                         ^~~
traffic.cpp:24:16: error: 'max' was not declared in this scope
   24 |    ans[nodo] = max(cont,fir[nodo]);
      |                ^~~
traffic.cpp:25:16: error: 'g' was not declared in this scope
   25 |    for(int v : g[nodo]){
      |                ^
traffic.cpp:27:10: error: 'subarbol' was not declared in this scope
   27 |       if(subarbol[v] + pp[v] == fir[nodo]) dfs2(v,nodo,(cont > sec[nodo] ? cont + subarbol[nodo] - subarbol[v] : sec[nodo] + pp[nodo]),pp);
      |          ^~~~~~~~
traffic.cpp:27:64: error: 'sec' was not declared in this scope
   27 |       if(subarbol[v] + pp[v] == fir[nodo]) dfs2(v,nodo,(cont > sec[nodo] ? cont + subarbol[nodo] - subarbol[v] : sec[nodo] + pp[nodo]),pp);
      |                                                                ^~~
traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:33:4: error: 'g' was not declared in this scope
   33 |    g.resize(N);
      |    ^
traffic.cpp:41:4: error: 'fir' was not declared in this scope
   41 |    fir.assign(N,0);
      |    ^~~
traffic.cpp:42:4: error: 'sec' was not declared in this scope
   42 |    sec.assign(N,0);
      |    ^~~
traffic.cpp:43:4: error: 'subarbol' was not declared in this scope
   43 |    subarbol.assign(N,0);
      |    ^~~~~~~~
traffic.cpp:44:4: error: 'ans' was not declared in this scope
   44 |    ans.resize(N);
      |    ^~~