제출 #1021220

#제출 시각아이디문제언어결과실행 시간메모리
1021220EkinOnalCommuter Pass (JOI18_commuter_pass)C++17
31 / 100
294 ms22544 KiB
//#pragma GCC optimize("O3,unroll-loops,Ofast") //#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt") #include <bits/stdc++.h> //#include <cstdio> //#include <iostream> using namespace std; #define MAX 100007 #define pb push_back //#define mp make_pair #define int long long #define f first #define s second #define vi vector<int> #define pii pair<int,int> #define si set<int> #define vpii vector<pair<int,int>> const int mod = 1e9+7; const int INF = 1e18; // myMap.begin()->first : key // myMap.begin()->second : value int epow(int a,int b){int ans=1;while(b){if(b&1) ans*=a;a*=a;ans%=mod;a%=mod;b>>=1;}return ans%mod;} int gcd(int a,int b) {if(a<b)swap(a,b);while(b){int tmp=b;b=a%b;a=tmp;}return a;} int mul(int a,int b){return ((a%mod)*(b%mod))%mod;} int dx[] = {-1, 0, 1, 0}; int dy[] = {0, -1, 0, 1}; #define N 50 vector<pii> adj[MAX]; int n,m,s,t,u,v; void dijkstra(vi &dist,int start,int finish) { priority_queue<pii,vector<pii>,greater<pii>> pq; pq.push({0,start}); dist[start]=0; while(pq.size()) { int node = pq.top().s, cost=pq.top().f; pq.pop(); if(cost != dist[node]) continue; for(auto u : adj[node]) { int nxt = u.f, len=u.s; if(dist[nxt] > cost+len) { dist[nxt] = cost+len; pq.push({dist[nxt],nxt}); } } } } void solve() { cin >> n >> m; cin >> s >> t; cin >> u >> v; for(int i=0;i<m;i++) { int a,b,c; cin>>a>>b>>c; adj[a].pb({b,c}); adj[b].pb({a,c}); } vi dist(n+2,INF),dist1(n+2,INF),dist2(n+2,INF); dijkstra(dist,s,t); int mn = dist[t]; dijkstra(dist2,t,s); priority_queue<pii,vector<pii>,greater<pii>> pq; pq.push({0,u}); dist1[u]=0; while(pq.size()) { int node = pq.top().s, cost=pq.top().f; pq.pop(); if(cost != dist1[node]) continue; for(auto u : adj[node]) { int nxt = u.f, len=u.s; if(dist[node]+dist2[nxt]+len==mn || dist[nxt]+dist2[node]+len==mn /*dist[nxt]==dist[node]+len || dist[node]==dist[nxt]+len*/) { if(dist1[nxt] > dist1[node]) { dist1[nxt]=dist1[node]; pq.push({dist1[nxt],nxt}); } } else if(dist1[nxt] > cost+len) { dist1[nxt] = cost+len; pq.push({dist1[nxt],nxt}); } } } cout << dist1[v] << endl; // for(int i=1;i<=n;i++) cout << dist[i] << " ";cout<<endl; // for(int i=1;i<=n;i++) cout << dist1[i] << " ";cout<<endl; return; } int32_t main() { int t=1; // cin >> t; while(t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...