Submission #673531

#TimeUsernameProblemLanguageResultExecution timeMemory
673531YENGOYANEvacuation plan (IZhO18_plan)C++17
0 / 100
202 ms24832 KiB
// eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee // // 271828___182845__904523__53602__ // // 87___47____13______52____66__24_ // // 97___75____72______47____09___36 // // 999595_____74______96____69___67 // // 62___77____24______07____66__30_ // // 35___35____47______59____45713__ // // eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee // #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <vector> #include <set> #include <map> #include <unordered_map> #include <unordered_map> #include <cmath> #include <climits> #include <algorithm> #include <random> #include <queue> #include <deque> #include <iomanip> #include <string> #include <tuple> #include <bitset> #include <chrono> #include <ctime> #include <fstream> #include <stack> #include <cstdio> using namespace std; using ll = long long; const int N = 1e5 + 5; const ll mod = 1e9 + 7, inf = 1e18; int n, m, k, q; vector<vector<pair<int, ll>>> gp; vector<vector<int>> tree; vector<ll> g, mind, par, sizes, d, isok; vector<pair<ll, int>> vp; vector<pair<pair<int, int>, pair<int, int>>> vp_; int get(int u) { if (u == par[u]) return u; return par[u] = get(par[u]); } void union_sets(int u, int v) { int a = get(u), b = get(v); if (a == b) return; if (sizes[a] < sizes[b]) swap(a, b), swap(u, v); par[b] = a; sizes[a] += sizes[b]; isok[b] = mind[u]; } void build_tree() { for (int i = 0; i < vp_.size(); ++i) { int u = vp_[i].second.first, v = vp_[i].second.second; if (get(u) == get(v)) continue; tree[u].push_back(v); tree[v].push_back(u); union_sets(u, v); } } bool check(ll mnd, int x, int y) { if (mind[x] < mnd || mind[y] < mnd) return 0; int p1 = x, p2 = y; while (isok[x] >= mnd && x != par[x]) x = par[x]; while (isok[y] >= mnd && y != par[y]) y = par[y]; return x == y; } void solve() { scanf("%d%d", &n, &m); gp = vector<vector<pair<int, ll>>>(n); mind = vector<ll>(n, 1e18); for (int i = 0; i < m; ++i) { int u, v, w; scanf("%d%d%d", &u, &v, &w); gp[--u].push_back({ --v, w }); gp[v].push_back({ u, w }); vp_.push_back({ {0, 0}, {u, v} }); } //return; scanf("%d", &k); g = vector<ll>(k); priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq; for (int i = 0; i < k; ++i) scanf("%d", &g[i]), --g[i], pq.push({0, g[i]}), mind[g[i]] = 0; while (pq.size()) { pair<ll, int> p = pq.top(); pq.pop(); ll d = p.first, u = p.second; if (mind[u] < d) continue; for (pair<int, ll> v : gp[u]) { if (mind[v.first] > mind[u] + v.second) { mind[v.first] = mind[u] + v.second; pq.push({ mind[v.first], v.first }); } } } for (int i = 0; i < vp_.size(); ++i) { int u = vp_[i].second.first, v = vp_[i].second.second; if (mind[u] > mind[v]) swap(u, v); vp_[i] = { {mind[u], mind[v]}, {u, v} }; } sort(vp_.rbegin(), vp_.rend()); tree = vector<vector<int>>(n); isok = par = sizes = vector <ll>(n, 1); for (int i = 0; i < n; ++i) par[i] = i; build_tree(); scanf("%d", &q); while (q--) { int s, t; scanf("%d%d", &s, &t), --s, --t; ll l = 0, r = 1e15 + 5; while (l + 1 < r) { ll m = (l + r) / 2; if (!check(m, s, t)) r = m; else l = m; } printf("%d\n", l); } } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); //int _; scanf("%d", &_); while (_--) solve(); }

Compilation message (stderr)

plan.cpp: In function 'void build_tree()':
plan.cpp:58:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for (int i = 0; i < vp_.size(); ++i) {
      |                     ~~^~~~~~~~~~~~
plan.cpp: In function 'bool check(ll, int, int)':
plan.cpp:70:9: warning: unused variable 'p1' [-Wunused-variable]
   70 |     int p1 = x, p2 = y;
      |         ^~
plan.cpp:70:17: warning: unused variable 'p2' [-Wunused-variable]
   70 |     int p1 = x, p2 = y;
      |                 ^~
plan.cpp: In function 'void solve()':
plan.cpp:91:41: warning: format '%d' expects argument of type 'int*', but argument 2 has type '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type*' {aka 'long long int*'} [-Wformat=]
   91 |     for (int i = 0; i < k; ++i) scanf("%d", &g[i]), --g[i], pq.push({0, g[i]}), mind[g[i]] = 0;
      |                                        ~^
      |                                         |
      |                                         int*
      |                                        %lld
plan.cpp:104:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |     for (int i = 0; i < vp_.size(); ++i) {
      |                     ~~^~~~~~~~~~~~
plan.cpp:123:18: warning: format '%d' expects argument of type 'int', but argument 2 has type 'll' {aka 'long long int'} [-Wformat=]
  123 |         printf("%d\n", l);
      |                 ~^     ~
      |                  |     |
      |                  int   ll {aka long long int}
      |                 %lld
plan.cpp:78:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
plan.cpp:82:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         int u, v, w; scanf("%d%d%d", &u, &v, &w);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~
plan.cpp:88:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |     scanf("%d", &k);
      |     ~~~~~^~~~~~~~~~
plan.cpp:91:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |     for (int i = 0; i < k; ++i) scanf("%d", &g[i]), --g[i], pq.push({0, g[i]}), mind[g[i]] = 0;
      |                                 ~~~~~^~~~~~~~~~~~~
plan.cpp:114:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  114 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
plan.cpp:116:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  116 |         int s, t; scanf("%d%d", &s, &t), --s, --t;
      |                   ~~~~~^~~~~~~~~~~~~~~~
#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...