Submission #445776

#TimeUsernameProblemLanguageResultExecution timeMemory
445776stat0r1cCommuter Pass (JOI18_commuter_pass)C++11
15 / 100
2084 ms262148 KiB
#include <bits/stdc++.h> /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> */ using namespace std; // using namespace __gnu_pbds; using ll = long long; using ull = unsigned ll; template<typename T> using vt = vector<T>; using vi = vt<int>; using vvi = vt<vi>; using ii = pair<int, int>; using vii = vt<ii>; /* template<typename T> using indexed_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; */ /* struct chash { static ull hash_f(ull x) {x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);} size_t operator()(ull x) const {static const ull RANDOM = chrono::steady_clock::now().time_since_epoch().count();return hash_f(x + RANDOM);} }; struct iihash { template <class T1, class T2> size_t operator () (const pair<T1,T2> &p) const {auto h1 = hash<T1>{}(p.first);auto h2 = hash<T2>{}(p.second);return h1 ^ h2;} }; template<class T1, class T2, class T3> using ii_umap = gp_hash_table<pair<T1,T2>,T3,iihash>; template<class T1, class T2> using f_umap = gp_hash_table<T1,T2,chash>; template<class T1, class T2> using o_umap = gp_hash_table<T1,T2>; */ #define sqr(x) (x)*(x) #define all(x) begin(x), end(x) #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)(x).size() #define debug(x) cerr << #x << " -> " << x << '\n' #define F first #define S second #define mp make_pair #define pb push_back #define eb emplace_back const int inf = 1e9 + 7; const ll infll = 1e18 + 10; template <typename T> inline T fgcd(T a, T b) {while(b) swap(b, a %= b); return a;} ll fpow(ll a, ll b) {ll o = 1; for(;b;b >>= 1) {if(b & 1) o = o * a;a = a * a;} return o;} ll fpow(ll a, ll b, ll m) {ll o = 1; a %= m; for(;b;b >>= 1) {if(b & 1) o = o * a % m;a = a * a % m;} return o;} template<class T> void uniq(vt<T> &a) {sort(all(a));a.resize(unique(all(a)) - a.begin());} const int N = 1e5; using pli = pair<ll, int>; int n,m,s,t,u,v,x,y,z; vii a[N + 1]; vi ts,ed[N + 1]; void dfs(int uu) { for(int e : ed[uu]) dfs(e); ts.pb(uu); } void dijkstra(int st, vt<ll> &d) { priority_queue<pli, vt<pli>, greater<pli>> pq; pq.push({0,st}); d.assign(n + 1, infll); d[st] = 0; while(!pq.empty()) { ll du = pq.top().F; int uu = pq.top().S; pq.pop(); if(d[uu] != du) continue; for(ii e : a[uu]) { if(d[e.S] > du + e.F) pq.push({d[e.S] = du + e.F, e.S}); } } } int main() { scanf("%d%d%d%d%d%d", &n, &m, &s, &t, &u, &v); while(m--) { scanf("%d%d%d", &x, &y, &z); a[x].eb(z,y); a[y].eb(z,x); } vt<ll> b,d,e,h; dijkstra(s, b); dijkstra(u, d); dijkstra(v, e); dijkstra(t, h); queue<int> q; q.push(s); while(!q.empty()) { int c = q.front(); q.pop(); for(ii g : a[c]) { if(b[t] == b[c] + g.F + h[g.S]) { ed[c].pb(g.S); if(g.S != t) q.push(g.S); } } } dfs(s); reverse(all(ts)); ll ans = d[v]; vt<ll> minu(n + 1, infll), minv(n + 1, infll); for(int i : ts) { minu[i] = min(minu[i], d[i]); minv[i] = min(minv[i], e[i]); for(int j : ed[i]) { minu[j] = min(minu[j], minu[i]); minv[j] = min(minv[j], minv[i]); } ans = min(ans, min(minu[i] + e[i], minv[i] + d[i])); } printf("%lld", ans); return 0; }

Compilation message (stderr)

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:67:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |     scanf("%d%d%d%d%d%d", &n, &m, &s, &t, &u, &v);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         scanf("%d%d%d", &x, &y, &z);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...