제출 #1293194

#제출 시각아이디문제언어결과실행 시간메모리
1293194trandaihao5555Commuter Pass (JOI18_commuter_pass)C++20
31 / 100
180 ms60416 KiB
#include <bits/stdc++.h> #define int long long #define debug cout << "ok\n"; #define SQR(x) (1LL * ((x) * (x))) #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1) #define fi first #define se second #define pb push_back #define mp make_pair #define pii pair<int,int> #define pli pair<ll,int> #define vi vector<int> #define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef unsigned int ui; using namespace std; const int M = 1e9 + 7; const int INF = 1e9 + 7; const ll INFLL = (ll)2e18 + 7LL; const ld PI = acos(-1); const int dx[] = {1, -1, 0, 0, -1, 1, 1, -1}; const int dy[] = {0, 0, 1, -1, -1, -1, 1, 1}; template<class _, class __> bool minimize(_ &x, const __ y){ if(x > y){ x = y; return true; } else return false; } template<class _, class __> bool maximize(_ &x, const __ y){ if(x < y){ x = y; return true; } else return false; } template<class _,class __> void Add(_ &x, const __ y) { x += y; if (x >= M) { x -= M; } return; } template<class _,class __> void Diff(_ &x, const __ y) { x -= y; if (x < 0) { x += M; } return; } //-------------------------------------------------------------- const int MaxN = 1e6+7; int n,m,Dist[3][MaxN],s,t,x,y,f[MaxN][3]; vector<pii> a[MaxN]; bool ch[MaxN]; void dijkstra(int root,int r) { memset(Dist[r],0x3f,sizeof(Dist[r])); Dist[r][root] = 0; priority_queue<pii,vector<pii>,greater<pii>> pq; pq.push(mp(0,root)); while (!pq.empty()) { int u = pq.top().se; int du = pq.top().fi; pq.pop(); if (du != Dist[r][u]) continue; for (pii e : a[u]) { int v = e.fi; int w = e.se; if (minimize(Dist[r][v],du + w)) { pq.push(mp(Dist[r][v],v)); } } } } void sol() { cin >> n >> m; cin >> s >> t; cin >> x >> y; for (int i=1;i<=m;i++) { int u,v,w; cin >> u >> v >> w; a[u].pb(mp(v,w)); a[v].pb(mp(u,w)); } dijkstra(s,0); dijkstra(x,1); dijkstra(y,2); priority_queue<pii> pq; pq.push(mp(Dist[0][t],t)); ch[t] = true; memset(f,0x3f,sizeof(f)); int res = Dist[1][y]; while (!pq.empty()) { int u = pq.top().se; pq.pop(); for (int i=1;i<=2;i++) minimize(f[u][i],Dist[i][u]); minimize(res,f[u][1] + f[u][2]); for (pii e : a[u]) { int v = e.fi; int w = e.se; if (Dist[0][v] + w == Dist[0][u]) { for (int i=1;i<=2;i++) minimize(f[v][i],f[u][i]); if (!ch[v]) pq.push(mp(Dist[0][v],v)),ch[v] = true; } } } cout << res; } signed main() { // freopen("test.inp","r",stdin); // freopen("test.out","w",stdout); FAST int t=1; // cin >> t; while (t--) sol(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...