Submission #97114

#TimeUsernameProblemLanguageResultExecution timeMemory
97114tincamateiHighway Tolls (IOI18_highway)C++14
100 / 100
324 ms10892 KiB
#include "highway.h" #include <bits/stdc++.h> using namespace std; const int MAX_N = 90000; const int MAX_M = 130000; struct Edge { int a, b; int other(int x) { return a ^ b ^ x; } } edge[MAX_M]; vector<int> graph[MAX_N]; vector<pair<int, int> > tree[2]; bool viz[MAX_N]; void buildSmallTrees(int eid, const std::vector<int> &U, const std::vector<int> &V) { int X, Y; for(int i = 0; i < U.size(); ++i) { edge[i] = {U[i], V[i]}; graph[U[i]].push_back(i); graph[V[i]].push_back(i); } X = edge[eid].a, Y = edge[eid].b; deque<pair<int, int> > q; q.push_back(make_pair(X, 0)); q.push_back(make_pair(Y, 1)); tree[0].push_back(make_pair(X, eid)); tree[1].push_back(make_pair(Y, eid)); viz[X] = viz[Y] = true; while(!q.empty()) { int nod, t; nod = q.front().first; t = q.front().second; q.pop_front(); for(auto it: graph[nod]) { int son = edge[it].other(nod); if(!viz[son]) { viz[son] = true; tree[t].push_back(make_pair(son, it)); q.push_back(make_pair(son, t)); } } } } int searchTree(int t, int M, long long refpath) { int st = -1, dr = tree[t].size(); vector<int> w(M, 0); reverse(tree[t].begin(), tree[t].end()); while(dr - st > 1) { int mid = (st + dr) / 2; for(int i = 0; i < M; ++i) w[i] = 1; for(int i = 0; i < 2; ++i) for(auto it: tree[i]) w[it.second] = 0; for(int i = 0; i <= mid; ++i) w[tree[t][i].second] = 1; if(ask(w) > refpath) dr = mid; else st = mid; } return tree[t][dr].first; } void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) { int M = U.size(); int st, dr; long long refPath; vector<int> w(M, 0); refPath = ask(w); st = -1, dr = M; while(dr - st > 1) { int mid = (st + dr) / 2; for(int i = 0; i <= mid; ++i) w[i] = 1; for(int i = mid + 1; i < M; ++i) w[i] = 0; if(ask(w) > refPath) dr = mid; else st = mid; } // Muchia (U[dr], V[dr]) face parte dintr-un drum sigur buildSmallTrees(dr, U, V); answer(searchTree(0, M, refPath), searchTree(1, M, refPath)); }

Compilation message (stderr)

highway.cpp: In function 'void buildSmallTrees(int, const std::vector<int>&, const std::vector<int>&)':
highway.cpp:23:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < U.size(); ++i) {
                 ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...