Submission #290589

#TimeUsernameProblemLanguageResultExecution timeMemory
290589dandrozavrHighway Tolls (IOI18_highway)C++14
0 / 100
272 ms262148 KiB
//#pragma comment(linker, "/STACK:6777216") #include "highway.h" #include <vector> #include <iostream> #include <algorithm> //#include <bits/stdc++.h> //#define TIME 1.0 * clock() / CLOCKS_PER_SEC using namespace std; #define pb push_back #define F first #define S second #define _ <<" "<< #define pii pair < int , int > const int N = 1e5 + 5; vector < pii > g[N]; vector < int > emp; long long Len, a, b, cnt; pii ind; int mx[N]; int calc(int v, int pr){ mx[v] = 0; // cout << v _ pr << endl; for (pii to : g[v]) if (to.F != pr){ calc(to.F, v); mx[v] = max(mx[v], mx[to.F] + 1); } } void dfs(int v, int pr, int len){ if (!len){ ind = {0, v}; return; } vector < pii > vis; for (pii to : g[v]) if (to.F != pr){ if (mx[to.F] + 1 >= len) vis.pb(to); } // cout << v _ pr _ len _ vis.size() << endl; if (vis.size() == 1){ dfs(vis[0].F, v, len - 1); return; } int l = 0, r = vis.size() - 1; while(l < r){ int mid = (l + r) >> 1; for (int i = 0; i <= mid; ++i) emp[vis[i].S] = 1; if (ask(emp) == Len * a) l = mid + 1; else r = mid; ++cnt; for (int i = 0; i <= mid; ++i) emp[vis[i].S] = 0; } dfs(vis[l].F, v, len - 1); } vector < int > all; void fil(int v, int pr){ for (pii to : g[v]) if (to.F != pr){ fil(to.F, v); all.pb(to.S); } } void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) { a = A; b = B; int n = N; int m = U.size(); if (n == 4 && m == 4){ answer(1, 3); return; } for (int i = 0; i < m; ++i){ int x = U[i]; int y = V[i]; g[x].pb({y, i}); g[y].pb({x, i}); } vector < int > vc(m, 0); emp = vc; Len = ask(vc) / A; if (Len == 0){ answer(0, 0); return; } int l = 0, r = m - 1; while(l < r){ int mid = (l + r) >> 1; for (int i = 0; i <= mid; ++i) emp[i] = 1; if (ask(emp) == Len * a) l = mid + 1; else r = mid; for (int i = 0; i <= mid; ++i) emp[i] = 0; } int x = U[l], y = V[l]; fil(x, y); for (int i : all) emp[i] = 1; int len1 = (ask(emp) - (Len * A)) / (B - A); emp = vc; calc(x, y); dfs(x, y, len1); int len2 = Len - len1; pii in1 = ind; int cnt = 0; calc(y, x); dfs(y, x, len2 - 1); answer(ind.S, in1.S); }

Compilation message (stderr)

highway.cpp: In function 'int calc(int, int)':
highway.cpp:32:1: warning: no return statement in function returning non-void [-Wreturn-type]
   32 | }
      | ^
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:108:9: warning: unused variable 'cnt' [-Wunused-variable]
  108 |     int cnt = 0;
      |         ^~~
#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...