結果

問題 No.1301 Strange Graph Shortest Path
ユーザー DriceDrice
提出日時 2020-11-27 22:53:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,834 bytes
コンパイル時間 585 ms
コンパイル使用メモリ 56,496 KB
実行使用メモリ 15,008 KB
最終ジャッジ日時 2023-10-09 21:44:19
合計ジャッジ時間 6,769 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
8,280 KB
testcase_01 AC 3 ms
8,264 KB
testcase_02 WA -
testcase_03 AC 86 ms
12,924 KB
testcase_04 AC 169 ms
14,704 KB
testcase_05 AC 85 ms
12,544 KB
testcase_06 AC 145 ms
14,124 KB
testcase_07 AC 121 ms
13,644 KB
testcase_08 AC 86 ms
12,892 KB
testcase_09 AC 139 ms
14,116 KB
testcase_10 WA -
testcase_11 AC 143 ms
13,908 KB
testcase_12 AC 149 ms
14,148 KB
testcase_13 AC 113 ms
13,408 KB
testcase_14 AC 129 ms
13,644 KB
testcase_15 AC 121 ms
13,608 KB
testcase_16 AC 171 ms
14,816 KB
testcase_17 AC 124 ms
13,644 KB
testcase_18 AC 111 ms
13,436 KB
testcase_19 AC 150 ms
14,172 KB
testcase_20 AC 157 ms
14,492 KB
testcase_21 AC 123 ms
13,700 KB
testcase_22 AC 165 ms
14,684 KB
testcase_23 AC 117 ms
13,560 KB
testcase_24 AC 153 ms
14,704 KB
testcase_25 AC 155 ms
14,228 KB
testcase_26 AC 129 ms
13,772 KB
testcase_27 AC 135 ms
14,044 KB
testcase_28 AC 87 ms
12,948 KB
testcase_29 WA -
testcase_30 AC 150 ms
14,324 KB
testcase_31 AC 156 ms
14,412 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 122 ms
14,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<queue>
#include<vector>
struct Edge{
    int u,v;
    long long c,d;
    Edge(int u,int v,long long c,long long d):u(u),v(v),c(c),d(d){}
    Edge(){}
};
std::vector<int>g[100005];
Edge edge[200005];
int fix[100005];
long long dis[100005];
int inEdge[100005];
int used[200005];
struct Node{
    int u;
    long long value;
    Node(int u,long long value):u(u),value(value){}
    bool operator < (const Node& other)const{
        return value>other.value;
    }
};

long long dijkstra(int s,int t,int n){
    for(int i = 1; i <= n; i++) fix[i] = 0, dis[i] = 1e17+7;
    std::priority_queue<Node>Q;
    dis[s] = 0;
    Q.push(Node(s,0));
    while(Q.size()!=0){
        while(Q.size()!=0 && fix[Q.top().u]==1) Q.pop();
        if(Q.size()==0) break;
        Node cur = Q.top(); 
        Q.pop();
        int u = cur.u;
        fix[u] = 1;
        for(int e: g[u]){
            long long cost = edge[e].c;
            int v = edge[e].v;
            if(used[e]) cost = edge[e].d;
            if(dis[v] > dis[u]+cost){
                inEdge[v] = e;
                dis[v] = dis[u]+cost;
                Q.push(Node(v,dis[v]));
            }
        }
    }
    int cur = t;
    while(cur!=s){
        int ue = inEdge[cur];
        int ve = -1;
        if(ue%2) ve = ue+1;
        else ve = ue-1;
        used[ue] = used[ve] = 1;
        cur = edge[ue].u;
    }
    return dis[t];
}

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    int total = 0;
    for(int i = 1; i <= m; i++){
        int u,v; long long c,d;
        scanf("%d%d%lld%lld",&u,&v,&c,&d);
        edge[++total] = Edge(u,v,c,d);
        g[u].push_back(total);
        edge[++total] = Edge(v,u,c,d);
        g[v].push_back(total);
    }
    long long ans = dijkstra(1,n,n);
    ans += dijkstra(n,1,n);
    printf("%lld\n",ans);
    return 0;
}
0