Submission #497839

#TimeUsernameProblemLanguageResultExecution timeMemory
497839luanaamorimFactories (JOI14_factories)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 "factories.h" #define ll long long #define INF (1e12) #define MAXL 21 #define MAX (int) (1e6 + 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; //ini vector<par> grafo[MAX]; //lca int up[MAX][MAXL], tin[MAX], tout[MAX], t; ll nivel[MAX]; void dfs(int u, int p = 0) { up[u][0] = p; for (int i = 1; i < MAXL; i++) up[u][i] = up[up[u][i-1]][i-1]; tin[u] = ++t; for (par(v, w) : grafo[u]) { if (v==p) continue; nivel[v] = nivel[u] + w; dfs(v, u); } tout[u] = ++t; } int anc(int u, int v) { return (tin[u] <= tin[v] && tout[v] <= tout[u]); } int LCA(int u, int v) { if (anc(u, v)) return u; if (anc(v, u)) return v; for (int i = MAXL-1; i >= 0; i--) if (!anc(up[v][i], u) && up[v][i]) v = up[v][i]; return up[v][0]; } ll dist(int u, int v) { return (nivel[u] + nivel[v] - (nivel[LCA(u, v)]<<1)); } //centroid bitset<MAX> vis; int pai[MAX], sub[MAX]; int tam(int u, int p = 0) { if (vis[u]) return 0; sub[u] = 1; for (par(v, w) : grafo[u]) if (v!=p) sub[u] += tam(v, u); return sub[u]; } int centroid(int u, int p, int t) { for (par(v, w) : grafo[u]) if (!vis[v] && v!=p && sub[v]>(t<<1)) return centroid(v, u, t); return u; } void build(int u, int p = 0) { tam(u); int c = centroid(u, 0, sub[u]); vis[c] = 1, pai[c] = p; for (par(v, w) : grafo[u]) if (!vis[v]) build(v, u); } //problem ll resp[MAX]; void ini(int u) { int k = u; while (k) { resp[k] = INF; k = pai[k]; } } void update(int u) { int k = u; while (k) { resp[k] = min(resp[k], dist(u, k)); k = pai[k]; } } ll query(int u) { ll k = u, r = INF; while (k) { r = min(r, dist(u, k) + resp[k]); k = pai[k]; } return r; } void Init(int n, int a[], int b[], int d[]) { for (int i = 0; i < n-1; i++) { grafo[a[i]+1].push_back({b[i]+1, d[i]}); grafo[b[i]+1].push_back({a[i]+1, d[i]}); } dfs(1); build(1); for (int i = 0; i < MAX; i++) resp[i] = INF; } ll Query(int s, int a[], int t, int b[]) { ll r = INF; for (int i = 0; i < s; i++) { cin >> a[i]; update(a[i]+1); } for (int i = 0; i < t; i++) { cin >> b[i]; r = min(r, query(b[i]+1)); } for (int i = 0; i < s; i++) ini(a[i]+1); return r; }

Compilation message (stderr)

factories.cpp: In function 'void dfs(int, int)':
factories.cpp:45:11: error: 'v' was not declared in this scope
   45 |  for (par(v, w) : grafo[u])
      |           ^
factories.cpp:45:14: error: 'w' was not declared in this scope
   45 |  for (par(v, w) : grafo[u])
      |              ^
factories.cpp:52:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   52 |  tout[u] = ++t;
      |  ~~~~~~~~^~~~~
factories.cpp:53:1: error: expected primary-expression before '}' token
   53 | }
      | ^
factories.cpp:52:16: error: expected ')' before '}' token
   52 |  tout[u] = ++t;
      |                ^
      |                )
   53 | }
      | ~               
factories.cpp:45:6: note: to match this '('
   45 |  for (par(v, w) : grafo[u])
      |      ^
factories.cpp:53:1: error: expected primary-expression before '}' token
   53 | }
      | ^
factories.cpp: In function 'int tam(int, int)':
factories.cpp:84:11: error: 'v' was not declared in this scope
   84 |  for (par(v, w) : grafo[u])
      |           ^
factories.cpp:84:14: error: 'w' was not declared in this scope
   84 |  for (par(v, w) : grafo[u])
      |              ^
factories.cpp:86:2: error: expected primary-expression before 'return'
   86 |  return sub[u];
      |  ^~~~~~
factories.cpp:85:33: error: expected ';' before 'return'
   85 |   if (v!=p) sub[u] += tam(v, u);
      |                                 ^
      |                                 ;
   86 |  return sub[u];
      |  ~~~~~~                          
factories.cpp:86:2: error: expected primary-expression before 'return'
   86 |  return sub[u];
      |  ^~~~~~
factories.cpp:85:33: error: expected ')' before 'return'
   85 |   if (v!=p) sub[u] += tam(v, u);
      |                                 ^
      |                                 )
   86 |  return sub[u];
      |  ~~~~~~                          
factories.cpp:84:6: note: to match this '('
   84 |  for (par(v, w) : grafo[u])
      |      ^
factories.cpp: In function 'int centroid(int, int, int)':
factories.cpp:91:11: error: 'v' was not declared in this scope
   91 |  for (par(v, w) : grafo[u])
      |           ^
factories.cpp:91:14: error: 'w' was not declared in this scope
   91 |  for (par(v, w) : grafo[u])
      |              ^
factories.cpp:93:2: error: expected primary-expression before 'return'
   93 |  return u;
      |  ^~~~~~
factories.cpp:92:66: error: expected ';' before 'return'
   92 |   if (!vis[v] && v!=p && sub[v]>(t<<1)) return centroid(v, u, t);
      |                                                                  ^
      |                                                                  ;
   93 |  return u;
      |  ~~~~~~                                                           
factories.cpp:93:2: error: expected primary-expression before 'return'
   93 |  return u;
      |  ^~~~~~
factories.cpp:92:66: error: expected ')' before 'return'
   92 |   if (!vis[v] && v!=p && sub[v]>(t<<1)) return centroid(v, u, t);
      |                                                                  ^
      |                                                                  )
   93 |  return u;
      |  ~~~~~~                                                           
factories.cpp:91:6: note: to match this '('
   91 |  for (par(v, w) : grafo[u])
      |      ^
factories.cpp: In function 'void build(int, int)':
factories.cpp:102:11: error: 'v' was not declared in this scope
  102 |  for (par(v, w) : grafo[u])
      |           ^
factories.cpp:102:14: error: 'w' was not declared in this scope
  102 |  for (par(v, w) : grafo[u])
      |              ^
factories.cpp:104:1: error: expected primary-expression before '}' token
  104 | }
      | ^
factories.cpp:103:28: error: expected ';' before '}' token
  103 |   if (!vis[v]) build(v, u);
      |                            ^
      |                            ;
  104 | }
      | ~                           
factories.cpp:104:1: error: expected primary-expression before '}' token
  104 | }
      | ^
factories.cpp:103:28: error: expected ')' before '}' token
  103 |   if (!vis[v]) build(v, u);
      |                            ^
      |                            )
  104 | }
      | ~                           
factories.cpp:102:6: note: to match this '('
  102 |  for (par(v, w) : grafo[u])
      |      ^
factories.cpp:104:1: error: expected primary-expression before '}' token
  104 | }
      | ^