Submission #335868

#TimeUsernameProblemLanguageResultExecution timeMemory
335868saarang123Dreaming (IOI13_dreaming)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> //#include "dreaming.h" using namespace std; const int N = 1e5 + 2; vector<array<int, 2>> g[N]; bool vis[N]; array<int, 2> par[N]; array<int, 2> dfs(int v, int p, int d) { vis[v] = true; par[v] = {p, d}; array<int, 2> ret = {d, v}; for(auto tx : g[v]) { int u = tx[0], w = tx[1]; if(u == p) continue; ret = max(ret, dfs(u, v, d + w)); } return ret; } int travelTime(int N,int M,int L, int A[],int B[],int T[]) { g.resize(N); vis.resize(N); par.resize(N); for(int i = 0; i < M; i++) { g[A[i]].push_back({B[i], T[i]}); g[B[i]].push_back({A[i], T[i]}); } for(int i = 0; i < N; i++) { if(vis[i]) continue; array<int, 2> x = dfs(i, -1, 0); array<int, 2> d = dfs(x[1], -1, 0); array<int, 2> v = {d[1], d[0]}; array<int, 4> ans = {d[0], d[0], 0, d[1]}; while(v[0] != -1) { array<int, 2> x = {v[0], par[v[0]][1]}; ans = min(ans, {abs(d[0] - 2 * x[1]), d[0] - x[1], x[1], x[0]}); v = par[v[0]]; } //cout << ans[1] << ' ' << ans[2] << ' ' << ans[3] << '\n'; cost.push_back({d[0], ans[3]}); } sort(cost.rbegin(), cost.rend()); for(int i = 1; i < cost.size(); i++) { g[cost[0][1]].push_back({cost[i][1], L}); g[cost[i][1]].push_back({cost[0][1], L}); } array<int, 2> x = dfs(1, -1, 0); int answer = dfs(x[1], -1, 0)[0]; return answer; }

Compilation message (stderr)

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:23:7: error: request for member 'resize' in 'g', which is of non-class type 'std::vector<std::array<int, 2> > [100002]'
   23 |     g.resize(N);
      |       ^~~~~~
dreaming.cpp:24:9: error: request for member 'resize' in 'vis', which is of non-class type 'bool [100002]'
   24 |     vis.resize(N);
      |         ^~~~~~
dreaming.cpp:25:9: error: request for member 'resize' in 'par', which is of non-class type 'std::array<int, 2> [100002]'
   25 |     par.resize(N);
      |         ^~~~~~
dreaming.cpp:42:9: error: 'cost' was not declared in this scope; did you mean 'cosl'?
   42 |         cost.push_back({d[0], ans[3]});
      |         ^~~~
      |         cosl
dreaming.cpp:44:10: error: 'cost' was not declared in this scope; did you mean 'cosl'?
   44 |     sort(cost.rbegin(), cost.rend());
      |          ^~~~
      |          cosl