結果

問題 No.1301 Strange Graph Shortest Path
ユーザー auauaauaua
提出日時 2020-11-28 16:35:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,254 bytes
コンパイル時間 1,703 ms
コンパイル使用メモリ 180,416 KB
実行使用メモリ 21,372 KB
最終ジャッジ日時 2023-10-10 00:41:17
合計ジャッジ時間 10,164 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 WA -
testcase_03 AC 151 ms
11,896 KB
testcase_04 AC 207 ms
15,368 KB
testcase_05 AC 159 ms
12,332 KB
testcase_06 AC 218 ms
14,416 KB
testcase_07 AC 197 ms
13,924 KB
testcase_08 AC 156 ms
12,328 KB
testcase_09 AC 193 ms
13,988 KB
testcase_10 WA -
testcase_11 AC 190 ms
14,396 KB
testcase_12 AC 189 ms
14,744 KB
testcase_13 AC 172 ms
13,664 KB
testcase_14 AC 174 ms
13,840 KB
testcase_15 AC 173 ms
13,400 KB
testcase_16 AC 210 ms
15,600 KB
testcase_17 AC 191 ms
14,140 KB
testcase_18 AC 174 ms
13,080 KB
testcase_19 AC 191 ms
14,356 KB
testcase_20 AC 194 ms
14,240 KB
testcase_21 AC 188 ms
14,200 KB
testcase_22 AC 206 ms
14,796 KB
testcase_23 AC 191 ms
14,028 KB
testcase_24 AC 195 ms
14,672 KB
testcase_25 AC 200 ms
15,208 KB
testcase_26 AC 182 ms
14,076 KB
testcase_27 AC 194 ms
14,164 KB
testcase_28 AC 153 ms
12,720 KB
testcase_29 WA -
testcase_30 AC 205 ms
15,016 KB
testcase_31 AC 201 ms
15,184 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 253 ms
21,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll INF=1e9+7;
const ll inf=INF*INF;
const ll MOD=998244353;
const ll mod=MOD;
const ll MAX=200010;
const double PI=acos(-1.0);

//dijkstra(O(ElogV))
//0-indexed
void dijkstra(ll n,ll s,vector<vector<pll> >&G,vector<ll> &d,vector<ll>&prev){
    priority_queue<pll,vector<pll>,greater<pll> >pq;
    rep(i,n){
        d[i]=inf;
    }
    d[s]=0;
    pq.push(mp(0,s));
    while(!pq.empty()){
        pll k=pq.top();pq.pop();
        ll v=k.second;
        if(d[v]<k.first)continue;
        for(auto e:G[v]){
            if(d[e.first]>d[v]+e.second){
                d[e.first]=d[v]+e.second;
                prev[e.fi]=v;
                pq.push(mp(d[e.first],e.first));
            }
        }
    }
}
signed main(){
    ll n,m;cin>>n>>m;
    vector<ll>u(m),v(m),c(m),d(m);
    rep(i,m){
        cin>>u[i]>>v[i]>>c[i]>>d[i];
        u[i]--;v[i]--;
    }
    
    ll len1,len2;
    vector<ll>prev(n);
    set<pll>st;
    {
        vector<vector<pll> >G(n);
        vector<ll>dist(n);
        rep(i,m){
            G[u[i]].pb(mp(v[i],c[i]));
            G[v[i]].pb(mp(u[i],c[i]));
        }
        dijkstra(n,0,G,dist,prev);
        len1=dist[n-1];
        ll now=n-1;
        while(now!=0){
            st.insert(mp(prev[now],now));
            st.insert(mp(now,prev[now]));
            now=prev[now];
        }
    }
    {
        vector<vector<pll> >G(n);
        vector<ll>dist(n);
        rep(i,m){
            if(!st.count(mp(u[i],v[i]))){
                G[u[i]].pb(mp(v[i],c[i]));
                G[v[i]].pb(mp(u[i],c[i]));
            }else{
                G[u[i]].pb(mp(v[i],d[i]));
                G[v[i]].pb(mp(u[i],d[i]));
            }
        }
        dijkstra(n,0,G,dist,prev);
        len2=dist[n-1];
    }
    cout<<len2+len1<<endl;
}
0