Submission #496077

#TimeUsernameProblemLanguageResultExecution timeMemory
496077luanaamorimRace (IOI11_race)C++17
Compilation error
0 ms0 KiB
#include <iostream> #include <queue> #include <string> #include <algorithm> #include <vector> #include <cmath> #include <iomanip> #include <map> #include <cstring> #include <set> #include <stack> #include <bitset> #include <race.h> #define ll long long #define INF (1e9) #define MAX (int) (2e2 + 5) #define MOD 1000000007 #define par pair<int, int> #define all(v) v.begin(), v.end() #define sz(x) (int) ((x).size()) #define esq(x) (x<<1) #define dir(x) ((x<<1)|1) #define lsb(x) (x & -x) #define W(x) cout << #x << ": " << x << endl #define Wii(x) cout << x.first << ' ' << x.second << endl #define _ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; int n, k, sub[MAX], vis[MAX], maior, h[MAX][2], l[MAX]; vector<par> grafo[MAX]; par f[MAX*10]; int dfs(int u, int p = 0) { if (vis[u]) return 0; sub[u] = 1; for (auto[v, w] : grafo[u]) if (v!=p) sub[u] += dfs(v, u); return sub[u]; } int centroid(int u, int p, int t) { for (auto[v, w] : grafo[u]) if (v!=p && !vis[v] && sub[v]>t/2) return centroid(v, u, t); return u; } int query(int u, int p, int h, int d) { if (vis[u] || d>k) return INF; maior = max(maior, h); int resp = INF; if (f[k-d].first) resp = f[k-d].second + h; for (auto[v, w] : grafo[u]) if (v!=p) resp = min(resp, query(v, u, h+1, d+w)); return resp; } void update(int u, int p, int h, int d) { if (vis[u] || d>k) return; if (f[d].first) f[d].second = min(f[d].second, h); else f[d].second = h; f[d].first=1; for (auto[v, w] : grafo[u]) if (v!=p) update(v, u, h+1, d+w); } int solve(int u) { // dfs(u); // int c = centroid(u, 0, sub[u]); // vis[c] = 1; // int resp = INF; // for (int i = 0; i < MAX; i++) // f[i] = {0, 0}; // f[0] = {1, 0}; // maior = 0; // for (auto[v, w] : grafo[c]) // { // resp = min(resp, query(v, 0, 1, w)); // update(v, 0, 1, w); // } // for (auto[v, w] : grafo[c]) // if (!vis[v]) resp = min(resp, solve(v)); // return resp; int resp = INF; for (int i = 1; i <= n; i++) { int tmp = INF; vis[i] = 1; for (int j = 0; j < MAX*10; j++) f[j] = {0, 0}; f[0] = {1, 0}; for (auto[v, w] : grafo[i]) { tmp = min(tmp, query(v, 0, 1, w)); update(v, 0, 1, w); } //cout << resp = min(resp, tmp); } return resp; } int best_path(int n, int k, int h[][2], int l[]) {_ for (int i = 1; i < n; i++) { grafo[h[i][0]+1].push_back({h[i][1]+1, l[i]}); grafo[h[i][1]+1].push_back({h[i][0]+1, l[i]}); } int resp = solve(1); return (resp==INF ? -1 : resp); } // int main() // { // cin >> n >> k; // for (int i = 1; i < n; i++) // { // cin >> h[i][0] >> h[i][1] >> l[i]; // } // cout << best_path(n, k, h, l) << endl; // } #include <iostream> #include <queue> #include <string> #include <algorithm> #include <vector> #include <cmath> #include <iomanip> #include <map> #include <cstring> #include <set> #include <stack> #include <bitset> #include <race.h> #define ll long long #define INF (1e9) #define MAX (int) (2e2 + 5) #define MOD 1000000007 #define par pair<int, int> #define all(v) v.begin(), v.end() #define sz(x) (int) ((x).size()) #define esq(x) (x<<1) #define dir(x) ((x<<1)|1) #define lsb(x) (x & -x) #define W(x) cout << #x << ": " << x << endl #define Wii(x) cout << x.first << ' ' << x.second << endl #define _ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; int n, k, sub[MAX], vis[MAX], maior, h[MAX][2], l[MAX]; vector<par> grafo[MAX]; par f[MAX*10]; int dfs(int u, int p = 0) { if (vis[u]) return 0; sub[u] = 1; for (auto[v, w] : grafo[u]) if (v!=p) sub[u] += dfs(v, u); return sub[u]; } int centroid(int u, int p, int t) { for (auto[v, w] : grafo[u]) if (v!=p && !vis[v] && sub[v]>t/2) return centroid(v, u, t); return u; } int query(int u, int p, int h, int d) { if (vis[u] || d>k) return INF; maior = max(maior, h); int resp = INF; if (f[k-d].first) resp = f[k-d].second + h; for (auto[v, w] : grafo[u]) if (v!=p) resp = min(resp, query(v, u, h+1, d+w)); return resp; } void update(int u, int p, int h, int d) { if (vis[u] || d>k) return; if (f[d].first) f[d].second = min(f[d].second, h); else f[d].second = h; f[d].first=1; for (auto[v, w] : grafo[u]) if (v!=p) update(v, u, h+1, d+w); } int solve(int u) { // dfs(u); // int c = centroid(u, 0, sub[u]); // vis[c] = 1; // int resp = INF; // for (int i = 0; i < MAX; i++) // f[i] = {0, 0}; // f[0] = {1, 0}; // maior = 0; // for (auto[v, w] : grafo[c]) // { // resp = min(resp, query(v, 0, 1, w)); // update(v, 0, 1, w); // } // for (auto[v, w] : grafo[c]) // if (!vis[v]) resp = min(resp, solve(v)); // return resp; int resp = INF; for (int i = 1; i <= n; i++) { int tmp = INF; vis[i] = 1; for (int j = 0; j < MAX*10; j++) f[j] = {0, 0}; f[0] = {1, 0}; for (auto[v, w] : grafo[i]) { tmp = min(tmp, query(v, 0, 1, w)); update(v, 0, 1, w); } //cout << resp = min(resp, tmp); } return resp; } int best_path(int n, int k, int h[][2], int l[]) {_ for (int i = 1; i < n; i++) { grafo[h[i][0]+1].push_back({h[i][1]+1, l[i]}); grafo[h[i][1]+1].push_back({h[i][0]+1, l[i]}); } int resp = solve(1); return (resp==INF ? -1 : resp); } // int main() // { // cin >> n >> k; // for (int i = 1; i < n; i++) // { // cin >> h[i][0] >> h[i][1] >> l[i]; // } // cout << best_path(n, k, h, l) << endl; // }

Compilation message (stderr)

race.cpp:169:5: error: redefinition of 'int n'
  169 | int n, k, sub[MAX], vis[MAX], maior, h[MAX][2], l[MAX];
      |     ^
race.cpp:30:5: note: 'int n' previously declared here
   30 | int n, k, sub[MAX], vis[MAX], maior, h[MAX][2], l[MAX];
      |     ^
race.cpp:169:8: error: redefinition of 'int k'
  169 | int n, k, sub[MAX], vis[MAX], maior, h[MAX][2], l[MAX];
      |        ^
race.cpp:30:8: note: 'int k' previously declared here
   30 | int n, k, sub[MAX], vis[MAX], maior, h[MAX][2], l[MAX];
      |        ^
race.cpp:169:11: error: redefinition of 'int sub [205]'
  169 | int n, k, sub[MAX], vis[MAX], maior, h[MAX][2], l[MAX];
      |           ^~~
race.cpp:30:11: note: 'int sub [205]' previously declared here
   30 | int n, k, sub[MAX], vis[MAX], maior, h[MAX][2], l[MAX];
      |           ^~~
race.cpp:169:21: error: redefinition of 'int vis [205]'
  169 | int n, k, sub[MAX], vis[MAX], maior, h[MAX][2], l[MAX];
      |                     ^~~
race.cpp:30:21: note: 'int vis [205]' previously declared here
   30 | int n, k, sub[MAX], vis[MAX], maior, h[MAX][2], l[MAX];
      |                     ^~~
race.cpp:169:31: error: redefinition of 'int maior'
  169 | int n, k, sub[MAX], vis[MAX], maior, h[MAX][2], l[MAX];
      |                               ^~~~~
race.cpp:30:31: note: 'int maior' previously declared here
   30 | int n, k, sub[MAX], vis[MAX], maior, h[MAX][2], l[MAX];
      |                               ^~~~~
race.cpp:169:38: error: redefinition of 'int h [205][2]'
  169 | int n, k, sub[MAX], vis[MAX], maior, h[MAX][2], l[MAX];
      |                                      ^
race.cpp:30:38: note: 'int h [205][2]' previously declared here
   30 | int n, k, sub[MAX], vis[MAX], maior, h[MAX][2], l[MAX];
      |                                      ^
race.cpp:169:49: error: redefinition of 'int l [205]'
  169 | int n, k, sub[MAX], vis[MAX], maior, h[MAX][2], l[MAX];
      |                                                 ^
race.cpp:30:49: note: 'int l [205]' previously declared here
   30 | int n, k, sub[MAX], vis[MAX], maior, h[MAX][2], l[MAX];
      |                                                 ^
race.cpp:170:13: error: redefinition of 'std::vector<std::pair<int, int> > grafo [205]'
  170 | vector<par> grafo[MAX];
      |             ^~~~~
race.cpp:31:13: note: 'std::vector<std::pair<int, int> > grafo [205]' previously declared here
   31 | vector<par> grafo[MAX];
      |             ^~~~~
race.cpp:171:5: error: redefinition of 'std::pair<int, int> f [2050]'
  171 | par f[MAX*10];
      |     ^
race.cpp:32:5: note: 'std::pair<int, int> f [2050]' previously defined here
   32 | par f[MAX*10];
      |     ^
race.cpp:173:5: error: redefinition of 'int dfs(int, int)'
  173 | int dfs(int u, int p = 0)
      |     ^~~
race.cpp:34:5: note: 'int dfs(int, int)' previously defined here
   34 | int dfs(int u, int p = 0)
      |     ^~~
race.cpp:182:5: error: redefinition of 'int centroid(int, int, int)'
  182 | int centroid(int u, int p, int t)
      |     ^~~~~~~~
race.cpp:43:5: note: 'int centroid(int, int, int)' previously defined here
   43 | int centroid(int u, int p, int t)
      |     ^~~~~~~~
race.cpp:189:5: error: redefinition of 'int query(int, int, int, int)'
  189 | int query(int u, int p, int h, int d)
      |     ^~~~~
race.cpp:50:5: note: 'int query(int, int, int, int)' previously defined here
   50 | int query(int u, int p, int h, int d)
      |     ^~~~~
race.cpp:201:6: error: redefinition of 'void update(int, int, int, int)'
  201 | void update(int u, int p, int h, int d)
      |      ^~~~~~
race.cpp:62:6: note: 'void update(int, int, int, int)' previously defined here
   62 | void update(int u, int p, int h, int d)
      |      ^~~~~~
race.cpp:212:5: error: redefinition of 'int solve(int)'
  212 | int solve(int u)
      |     ^~~~~
race.cpp:73:5: note: 'int solve(int)' previously defined here
   73 | int solve(int u)
      |     ^~~~~
race.cpp:255:5: error: redefinition of 'int best_path(int, int, int (*)[2], int*)'
  255 | int best_path(int n, int k, int h[][2], int l[])
      |     ^~~~~~~~~
race.cpp:116:5: note: 'int best_path(int, int, int (*)[2], int*)' previously defined here
  116 | int best_path(int n, int k, int h[][2], int l[])
      |     ^~~~~~~~~