제출 #1098247

#제출 시각아이디문제언어결과실행 시간메모리
1098247vjudge1Evacuation plan (IZhO18_plan)C++17
54 / 100
4026 ms64084 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, d[N], l, r, used[N], res, mx; map <pair <ll, ll>, ll> mp; set <pair <ll, ll>> s; vector <pair <ll, ll>> g[N]; void dfs (ll v, ll md){ if (d[v] < md){ return; } if (c){ return; } if (v == b){ c = 1; return; } used[v] = 1; for (int i = 0; i < g[v].size(); i++){ if (used[g[v][i].F] == 0 && d[g[v][i].F] >= md){ dfs (g[v][i].F, md); } } } 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}); } } } cin >> k; while (k--){ cin >> a >> b; if (mp[{a, b}] != 0 || mp[{b, a}] != 0){ cout << min (d[a], d[b]) << '\n'; continue; } l = 0, r = mx * n, res = 0; while (l <= r){ ll md = (l + r) / 2; c = 0; for (int i = 1; i <= n; i++){ used[i] = 0; } dfs (a, md); if (c){ 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 */

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

plan.cpp: In function 'void dfs(int, int)':
plan.cpp:43:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |  for (int i = 0; i < g[v].size(); i++){
      |                  ~~^~~~~~~~~~~~~
plan.cpp: In function 'int main()':
plan.cpp:76: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]
   76 |   for (int i = 0; i < g[v].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...