Submission #348765

#TimeUsernameProblemLanguageResultExecution timeMemory
348765soroushRace (IOI11_race)C++14
Compilation error
0 ms0 KiB
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include "race.h" using namespace std; typedef long long int ll; typedef pair<int, int> pii; #define SZ(x) (int) x.size() #define F first #define S second const int N = 2e5 + 10; int S[N], M[N], n, k, ret = 1e9; vector<pii> adj[N]; unordered_map<int, int> mp; void preDFS(int v, int p = -1) { S[v] = 1; for (pii &u : adj[v]) { if (u.F != p && !M[u.F]) preDFS(u.F, v), S[v] += S[u.F]; } } int centroid(int v, int n , int p = -1 , bool found = 0) { while(!found){ found = 1; for(pii &u : adj[v]) if(!M[u.F] && u.F != p && 2 * S[u.F] > s) p = v , v = u , found = 0; } return v; } void add(int v, int iw, int p, int h = 1) { if (mp.count(iw)) mp[iw] = min(mp[iw], h); else mp[iw] = h; for (pii &u : adj[v]) { if (!M[u.F] && u.F != p) add(u.F, iw + u.S, v, h + 1); } } void calc(int v, int iw, int p, int h = 1) { if (iw > k) return; if (iw == k) ret = min(ret, h); else if (mp.count(k - iw)) ret = min(ret, h + mp[k - iw]); for (pii &u : adj[v]) { if (!M[u.F] && u.F != p) calc(u.F, iw + u.S, v, h + 1); } } void solve(int v) { for (pii &u : adj[v]) { if (M[u.F]) continue; calc(u.F, u.S, v); add(u.F, u.S, v); } } void decompose(int v) { preDFS(v); v = centroid(v, S[v]); // solve M[v] = 1; solve(v); mp.clear(); mp.max_load_factor(0.25); for (pii &u : adj[v]) if (!M[u.F]) decompose(u.F); } int best_path(int _n, int _k, int h[][2], int l[]) { n = _n, k = _k; for (int i = 0; i < n - 1; i++) { int u = h[i][0] + 1, v = h[i][1] + 1; adj[u].push_back({v, l[i]}); adj[v].push_back({u, l[i]}); } decompose(1); return ret == 1e9 ? -1 : ret; }

Compilation message (stderr)

race.cpp: In function 'int centroid(int, int, int, bool)':
race.cpp:28:51: error: 's' was not declared in this scope
   28 |            if(!M[u.F] && u.F != p && 2 * S[u.F] > s)
      |                                                   ^
race.cpp:29:26: error: cannot convert 'pii' {aka 'std::pair<int, int>'} to 'int' in assignment
   29 |              p = v , v = u , found = 0;
      |                          ^
      |                          |
      |                          pii {aka std::pair<int, int>}