Submission #1098325

#TimeUsernameProblemLanguageResultExecution timeMemory
1098325vjudge1Evacuation plan (IZhO18_plan)C++17
100 / 100
845 ms65876 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define ll int #define F first #define S second #define ull unsigned long long #define db double #define ldb long double #define pb push_back #define pf push_front #define ppb pop_back #define ppf pop_front #define yes cout<<"YES\n" #define no cout<<"NO\n" #define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> #define all(x) x.begin(), x.end() const int mod = 1e9 + 7; const int N = 1e5 + 7; using namespace std; using namespace __gnu_pbds; ll n, m, k, p[N], a, b, c, ans, gv[N], d[N], l, r, used[N], res, mx, pr[N], dep[N], t[N]; vector <ll> st; map <pair <ll, ll>, ll> mp; set <pair <ll, ll>> s; vector <pair <ll, ll>> q, g[N]; ll get (ll a, ll time){ if (a == pr[a] || t[a] < time){ return a; } return get (pr[a], time); } void un (ll a, ll b, ll time){ a = get (a, time); b = get (b, time); if (a == b){ return; } if (dep[a] > dep[b]){ swap (a, b); } pr[a] = b; t[a] = time; dep[b] = max (dep[b], dep[a] + 1); } signed main (){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 1; i <= m; i++){ cin >> a >> b >> c; mp[{a, b}] = 1; mx = max (mx, c); g[a].pb({b, c}); g[b].pb ({a, c}); } for (int i = 1; i <= n; i++){ d[i] = 1e9; } cin >> k; for (int i = 1; i <= k; i++){ cin >> p[i]; d[p[i]] = 0; } for (int i = 1; i <= n; i++){ s.insert({d[i], i}); } while (s.size()){ pair <ll, ll> opa = *s.begin(); s.erase (opa); ll v = opa.second, w = opa.F; for (int i = 0; i < g[v].size(); i++){ if (d[g[v][i].F] > w + g[v][i].S){ s.erase ({d[g[v][i].F], g[v][i].F}); d[g[v][i].F] = w + g[v][i].S; s.insert ({d[g[v][i].F], g[v][i].F}); } } } for (int i = 1; i <= n; i++){ // cout << d[i] << ' '; pr[i] = i; dep[i] = 1; q.pb ({d[i], i}); st.pb(d[i]); } // cout << '\n'; sort (all (q)); sort (all (st)); a = q.size() - 1; for (int i = st.size() - 1; i >= 0; i--){ while (a >= 0 && q[a].F >= st[i]){ for (int y = 0; y < g[q[a].S].size(); y++){ if (d[g[q[a].S][y].F] >= st[i])un (q[a].S, g[q[a].S][y].F, st[i]); } a--; } } cin >> k; while (k--){ cin >> a >> b; l = 0, r = 1e8, res = 0; while (l <= r){ ll md = (l + r) / 2; // cout << md << ' ' << get (a, md) << ' ' << get (b, md) << '\n'; if (get (a, md) == get (b, md)){ l = md + 1; res = md; } else{ r = md - 1; } } cout << res << '\n'; } } /* 9 12 1 9 4 1 2 5 2 3 7 2 4 3 4 3 6 3 6 4 8 7 10 6 7 5 5 8 1 9 5 7 5 4 12 6 8 2 2 4 7 5 1 6 5 3 4 8 5 8 1 5 */

Compilation message (stderr)

plan.cpp: In function 'int main()':
plan.cpp:79:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |   for (int i = 0; i < g[v].size(); i++){
      |                   ~~^~~~~~~~~~~~~
plan.cpp:100:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |    for (int y = 0; y < g[q[a].S].size(); y++){
      |                    ~~^~~~~~~~~~~~~~~~~~
#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...