제출 #540611

#제출 시각아이디문제언어결과실행 시간메모리
540611browntoadCommuter Pass (JOI18_commuter_pass)C++14
0 / 100
3 ms1404 KiB
#include <bits/stdc++.h> #pragma GCC optimize ("Ofast", "unroll-loops") using namespace std; #define ll long long #define int ll #define FOR(i,a,b) for (int i = (a); i<(b); i++) #define REP(i,n) FOR(i,0,n) #define REP1(i,n) FOR(i,1,n+1) #define RREP(i,n) for (int i=(n)-1; i>=0; i--) #define RREP1(i,n) for (int i=(n); i>=1; i--) #define f first #define s second #define pb push_back #define ALL(x) x.begin(),x.end() #define SZ(x) (int)(x.size()) #define SQ(x) (x)*(x) #define pii pair<int, int> #define pdd pair<double ,double> #define pcc pair<char, char> #define endl '\n' //#define TOAD #ifdef TOAD #define bug(x) cerr<<__LINE__<<": "<<#x<<" is "<<x<<endl #define IOS() #else #define bug(...) #define IOS() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) #endif const ll inf = 1ll<<60; const int iinf=2147483647; const ll mod = 1e9+7; const ll maxn=305; const double PI=acos(-1); ll pw(ll x, ll p, ll m=mod){ ll ret=1; while (p>0){ if (p&1){ ret*=x; ret%=m; } x*=x; x%=m; p>>=1; } return ret; } ll inv(ll a, ll m=mod){ return pw(a,m-2); } //======================================================================================= int n, m, s, t, u, v; struct edge{ int st, en; int w; }; vector<edge> ing[maxn], graph[maxn]; vector<edge> E(2*maxn); vector<int> dis(maxn), rdis(maxn); vector<bool> ds1(maxn), ds2(maxn), ds3(maxn); void dij1(){ priority_queue<pii, vector<pii>, greater<pii> > pq; pq.push({0, s}); //dis[s]=0; //ds1[s]=1; while(pq.size()){ pii x=pq.top(); pq.pop(); if (ds1[x.s]) continue; ds1[x.s]=1; dis[x.s]=x.f; REP(i,SZ(ing[x.s])){ pq.push({x.f+ing[x.s][i].w, ing[x.s][i].en}); } } } void dij2(){ priority_queue<pii, vector<pii>, greater<pii> > pq; pq.push({0, t}); //rdis[t]=0; //ds2[t]=1; while(pq.size()){ pii x=pq.top(); pq.pop(); if (ds2[x.s]) continue; ds2[x.s]=1; rdis[x.s]=x.f; REP(i,SZ(ing[x.s])){ pq.push({x.f+ing[x.s][i].w, ing[x.s][i].en}); } } } int dij3(){ int res=0; priority_queue<pii, vector<pii>, greater<pii> > pq; pq.push({0, u}); //ds3[u]=1; fill(ALL(ds3), 0); while(pq.size()){ pii x=pq.top(); pq.pop(); if (x.s==v){ res=x.f; break; } if (ds3[x.s]) continue; ds3[x.s]=1; REP(i,SZ(graph[x.s])){ pq.push({x.f+graph[x.s][i].w, graph[x.s][i].en}); } } return res; } signed main (){ IOS(); cin>>n>>m>>s>>t>>u>>v; REP(i,m){ cin>>E[i].st>>E[i].en>>E[i].w; ing[E[i].st].pb({E[i].st, E[i].en, E[i].w}); ing[E[i].en].pb({E[i].en, E[i].st, E[i].w}); } dij1(); dij2(); REP(i,m){ if (dis[E[i].st]+rdis[E[i].en]+E[i].w==dis[t]){ //cout<<i<<endl; graph[E[i].st].pb({E[i].st, E[i].en, 0}); } else { graph[E[i].st].pb({E[i].st, E[i].en, E[i].w}); } if (dis[E[i].en]+rdis[E[i].st]+E[i].w==dis[t]){ //cout<<i<<endl; graph[E[i].en].pb({E[i].en, E[i].st, 0}); } else { graph[E[i].en].pb({E[i].en, E[i].st, E[i].w}); } } /*REP1(i,n){ REP(j,SZ(graph[i])){ cout<<graph[i][j].st<<' '<<graph[i][j].en<<endl; } } */ int a=dij3(); REP1(i, n){ graph[i].clear(); } REP(i,m){ if (dis[E[i].st]+rdis[E[i].en]+E[i].w==dis[t]){ //cout<<i<<endl; graph[E[i].en].pb({E[i].en, E[i].st, 0}); } else { graph[E[i].en].pb({E[i].en, E[i].st, E[i].w}); } if (dis[E[i].en]+rdis[E[i].st]+E[i].w==dis[t]){ //cout<<i<<endl; graph[E[i].st].pb({E[i].st, E[i].en, 0}); } else { graph[E[i].st].pb({E[i].st, E[i].en, E[i].w}); } } int b=dij3(); cout<<min(a, b)<<endl; } /* 8 9 1 5 4 7 1 2 5 2 3 5 3 4 10 4 5 5 1 6 10 6 7 5 7 8 5 8 5 5 3 6 1 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...