Submission #645840

#TimeUsernameProblemLanguageResultExecution timeMemory
645840VectorizedRace (IOI11_race)C++17
Compilation error
0 ms0 KiB
#define ll long long #define maxN 2000005 using namespace std; #include <iostream> #include <iostream> #include<vector> #include<set> #include<map> int n, k; //first = node, second = weight vector<pair<int ,int>> adj[maxN]; map<int, int> sets[maxN]; vector<int> ord; int p[maxN], lzW[maxN], lzN[maxN]; void dfs(int node, int parent){ p[node] = parent; for(pair<int, int> j: adj[node]){ if(j.first != parent){ dfs(j.first, node); ord.push_back(j.first); } } } int main() { cin >> n >> k; for (int i = 0; i < n - 1; ++i) { int a, b, w; cin >> a >> b >> w; adj[a].push_back(make_pair(b, w)); adj[b].push_back(make_pair(a, w)); } dfs(0, -1); p[0] = -1; ord.push_back(0); int ans = INT_MAX; for (int i = 0; i < n; ++i) { int node = ord[i]; if(adj[node].size() == 1 && node != 0){ lzW[node] = 0; lzN[node] = 0; continue; } int bn = -1, bz = -1, bw; for(pair<int, int> j : adj[node]){ if(j.first == p[node]) continue; if((int)sets[j.first].size() > bz){ bz = (int)sets[j.first].size(); bn = j.first; bw = j.second; } } swap(sets[bn], sets[node]); lzW[node] = lzW[bn] + bw; lzN[node] = lzN[bn] + 1; sets[node][bw - lzW[node]] = 1 - lzN[node]; for(pair<int, int> j: adj[node]){ if(j.first == p[node] || j.first == bn) continue; for (auto const& a : sets[j.first]){ int f = k - (a.first + lzW[j.first] + j.second) - lzW[node]; if(sets[node].find(f) != sets[node].end()){ ans = min(ans, a.second + lzN[j.first] + 1 + sets[node][f] + lzN[node]); } } for (auto const& a : sets[j.first]){ int f = (a.first + lzW[j.first] + j.second) - lzW[node]; if(sets[node].find(f) != sets[node].end()){ sets[node][f] = min(sets[node][f], a.second + lzN[j.first] + 1 - lzN[node]); }else{ sets[node][f] = a.second + lzN[j.first] + 1 - lzN[node]; } } int f = k - j.second; if(sets[node].find(f) != sets[node].end()){ ans = min(ans, sets[node][f] + lzN[node] + 1); } sets[node][j.second - lzW[node]] = 1 - lzN[node]; } if(sets[node].find(k - lzW[node]) != sets[node].end()){ ans = min(ans, sets[node][k - lzW[node]] + lzN[node]); } } cout << ans << "\n"; }

Compilation message (stderr)

race.cpp: In function 'int main()':
race.cpp:37:15: error: 'INT_MAX' was not declared in this scope
   37 |     int ans = INT_MAX;
      |               ^~~~~~~
race.cpp:9:1: note: 'INT_MAX' is defined in header '<climits>'; did you forget to '#include <climits>'?
    8 | #include<map>
  +++ |+#include <climits>
    9 | int n, k;