제출 #1075007

#제출 시각아이디문제언어결과실행 시간메모리
107500742kangaroo통행료 (IOI18_highway)C++17
100 / 100
212 ms24268 KiB
// // Created by 42kangaroo on 25/08/2024. // #include "bits/stdc++.h" #include "highway.h" using ll = long long; using namespace std; struct Ed { int to, i; }; using g_t = vector<vector<Ed>>; struct BfsVal { int to, i, d; }; bool operator<(const BfsVal &l, const BfsVal &r) { return l.d < r.d; } void addDfs(int n, int p, g_t &g, vector<int> &dis, vector<BfsVal> &out) { for (auto e: g[n]) { if (e.to == p) continue; out.push_back({e.to, e.i, dis[e.to]}); addDfs(e.to, n, g, dis, out); } } void wDfs(int n, int p, g_t &g, vector<int> &w) { for (auto e: g[n]) { if (e.to == p) continue; w[e.i] = 0; wDfs(e.to, n, g, w); } } void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) { vector<int> w(U.size(), 0); ll le = ask(w) / (ll) A; vector<bool> vis(N, false); g_t g(N); for (int i = 0; i < U.size(); ++i) { g[U[i]].push_back({V[i], i}); g[V[i]].push_back({U[i], i}); } int l = 0, r = U.size(); while (l + 1 < r) { int m = (l + r) / 2; std::fill(w.begin(), w.end(), 1); for (int i = 0; i < m; ++i) { w[i] = 0; } if (ask(w) > le * A) l = m; else r = m; } vector<int> dis(N, -1); g_t gBfs(N); queue<BfsVal> q; q.push({U[l], -1, 0}); q.push({V[l], -1, 0}); while (!q.empty()) { auto bfV = q.front(); q.pop(); if (dis[bfV.to] != -1) continue; if (bfV.i >= 0) { gBfs[U[bfV.i]].push_back({V[bfV.i], bfV.i}); gBfs[V[bfV.i]].push_back({U[bfV.i], bfV.i}); } dis[bfV.to] = bfV.d; for (auto e: g[bfV.to]) { q.push({e.to, e.i, bfV.d + 1}); } } vector<BfsVal> out; int x = U[l], y = V[l]; addDfs(U[l], V[l], gBfs, dis, out); out.push_back({U[l], l, 0}); std::sort(out.begin(), out.end()); int ll = 0, rr = out.size(); while (ll + 1 < rr) { int m = (ll + rr) / 2; std::fill(w.begin(), w.end(), 1); for (int i = 0; i < m; ++i) { w[out[i].i] = 0; } w[l] = 0; wDfs(V[l], U[l], gBfs, w); if (ask(w) > A * le) ll = m; else rr = m; } x = out[ll].to; out.clear(); addDfs(V[l], U[l], gBfs, dis, out); out.push_back({V[l], l, 0}); std::sort(out.begin(), out.end()); ll = 0, rr = out.size(); while (ll + 1 < rr) { int m = (ll + rr) / 2; std::fill(w.begin(), w.end(), 1); for (int i = 0; i < m; ++i) { w[out[i].i] = 0; } w[l] = 0; wDfs(U[l], V[l], gBfs, w); if (ask(w) > A * le) ll = m; else rr = m; } y = out[ll].to; answer(x, y); }

컴파일 시 표준 에러 (stderr) 메시지

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:44:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |  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...