Submission #671544

#TimeUsernameProblemLanguageResultExecution timeMemory
671544Alihan_8Evacuation plan (IZhO18_plan)C++17
41 / 100
4082 ms46688 KiB
#include <bits/stdc++.h> // include <ext/pb_ds/assoc_container.hpp> // include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; #define all(x) x.begin(), x.end() #define pb push_back // define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> #define mpr make_pair #define ln '\n' void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);} #define int long long const int N = 1e5+1; vector <pair<int,int>> g[N]; int val[N], n; bool ok(int x, int y, int Mx){ vector <int> used(n+1); queue <int> q; q.push(x); if ( min(val[x], val[y]) < Mx ) return false; while ( !q.empty() ){ int cur = q.front(); q.pop(); used[cur] = 1; for ( auto [to, w]: g[cur] ){ if ( val[to] < Mx or used[to] ) continue; q.push(to); } } return used[y]; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int m; cin >> n >> m; for ( int i = 1; i <= m; i++ ){ int x, y, w; cin >> x >> y >> w; g[x].pb({y, w}); g[y].pb({x, w}); } int k; cin >> k; priority_queue <pair<int,int>> q; const int inf = 1e12+1; vector <int> dis(n+1, inf); for ( int i = 1; i <= k; i++ ){ int x; cin >> x; q.push({0, x}); dis[x] = 0; } while ( !q.empty() ){ int cur = q.top().second; q.pop(); for ( auto [to, w]: g[cur] ){ int new_dis = dis[cur]+w; if ( new_dis < dis[to] ){ dis[to] = new_dis; q.push({-dis[to], to}); } } } for ( int i = 1; i <= n; i++ ) val[i] = dis[i]; int Q; cin >> Q; while ( Q-- ){ int x, y; cin >> x >> y; int l = 0, r = inf; while ( l+1 < r ){ int md = (l+r)>>1; if ( ok(x, y, md) ) l = md; else r = md; } cout << l << ln; } /* 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 */ cout << '\n'; }

Compilation message (stderr)

plan.cpp: In function 'void IO(std::string)':
plan.cpp:11:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
plan.cpp:11:70: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...