結果

問題 No.1301 Strange Graph Shortest Path
ユーザー ゆきのんゆきのん
提出日時 2020-12-01 06:37:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,421 bytes
コンパイル時間 2,108 ms
コンパイル使用メモリ 182,192 KB
実行使用メモリ 29,140 KB
最終ジャッジ日時 2023-10-11 03:20:04
合計ジャッジ時間 10,776 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
12,420 KB
testcase_01 AC 6 ms
12,408 KB
testcase_02 WA -
testcase_03 AC 156 ms
18,856 KB
testcase_04 AC 225 ms
20,344 KB
testcase_05 AC 168 ms
19,528 KB
testcase_06 AC 200 ms
19,632 KB
testcase_07 AC 194 ms
19,860 KB
testcase_08 AC 163 ms
18,988 KB
testcase_09 AC 191 ms
19,264 KB
testcase_10 WA -
testcase_11 AC 203 ms
19,972 KB
testcase_12 AC 208 ms
20,028 KB
testcase_13 AC 191 ms
19,996 KB
testcase_14 AC 189 ms
19,136 KB
testcase_15 AC 180 ms
19,180 KB
testcase_16 AC 230 ms
20,424 KB
testcase_17 AC 203 ms
20,448 KB
testcase_18 AC 179 ms
19,248 KB
testcase_19 AC 198 ms
19,648 KB
testcase_20 AC 200 ms
19,376 KB
testcase_21 AC 193 ms
20,036 KB
testcase_22 AC 221 ms
19,876 KB
testcase_23 AC 206 ms
20,028 KB
testcase_24 AC 213 ms
19,712 KB
testcase_25 AC 228 ms
20,144 KB
testcase_26 AC 206 ms
19,572 KB
testcase_27 AC 212 ms
19,756 KB
testcase_28 AC 173 ms
21,528 KB
testcase_29 WA -
testcase_30 AC 221 ms
20,060 KB
testcase_31 AC 227 ms
20,308 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 266 ms
29,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const ll mod=998244353;
const ll LINF=1ll<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};



struct edge {int to;ll cost;};

const int M_N=300000;
vector<edge> G[M_N+1];

struct Dijkstra{

    ll d[M_N+1];
    ll b[M_N+1];
    void init(int n){
        fill(d,d+n,LINF);
        fill(b,b+n,0);
    }

    void dijkstra(int s){
        priority_queue<P,vector<P>,greater<P>> que;
        que.push(P(0, s));
        d[s] = 0;
        while(!que.empty()){
            P p=que.top();
            que.pop();
            int v=p.second;
            if(d[v]<p.first) continue;
            for(int i=0;i<G[v].size();i++){
                edge e=G[v][i];
                if(d[e.to]>d[v]+e.cost){
                    d[e.to]=d[v]+e.cost;
                    que.push(P(d[e.to],e.to));
                    b[e.to]=v;
                }
            }
        }
    }

};

int main(){
    int n,m;cin >> n >> m;
    vector<int> a(m);
    auto b = a;
    auto c = a;
    auto d = a;
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--,b[i]--;
        G[a[i]].pb({b[i], c[i]});
        G[b[i]].pb({a[i], c[i]});
    }
    Dijkstra ds;
    ds.init(n);
    ds.dijkstra(0);
    ll ans = ds.d[n-1];
    for (int i = 0; i < n; i++) {
        G[i].clear();
    }
    int now = n - 1;
    set<P> st;
    while(now != 0){
        int to = ds.b[now];
        st.insert({now, to});
        st.insert({to, now});
        now = to;
    }
    for (int i = 0; i < m; i++) {
        if(st.find({a[i], b[i]}) != st.end()){
            G[a[i]].pb({b[i], d[i]});
            G[b[i]].pb({a[i], d[i]});
        }
        else{
            G[a[i]].pb({b[i], c[i]});
            G[b[i]].pb({a[i], c[i]});
        }
    }
    ds.init(n);
    ds.dijkstra(0);
    ans += ds.d[n-1];
    cout << ans << endl;
    return 0;
}
0