結果

問題 No.807 umg tours
ユーザー betrue12
提出日時 2019-03-22 22:02:45
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 450 ms / 4,000 ms
コード長 1,165 bytes
コンパイル時間 2,240 ms
コンパイル使用メモリ 199,732 KB
最終ジャッジ日時 2025-01-06 23:50:26
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:45:20: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘int64_t’ {aka ‘long int’} [-Wformat=]
   45 |         printf("%lld\n", ans);
      |                 ~~~^     ~~~
      |                    |     |
      |                    |     int64_t {aka long int}
      |                    long long int
      |                 %ld
main.cpp:13:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |         scanf("%d %d %d", &a, &b, &c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef pair<int64_t, int64_t> P;

vector<P> edges[200000];

int main(){
    int N, M;
    cin >> N >> M;
    for(int i=0; i<M; i++){
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        a--; b--;
        edges[a].push_back({b, c});
        edges[b].push_back({a, c});
        edges[a+N].push_back({b+N, c});
        edges[b+N].push_back({a+N, c});
        edges[a].push_back({b+N, 0});
        edges[b].push_back({a+N, 0});
    }

    int64_t dist[200000];
    for(int i=0; i<2*N; i++) dist[i] = 1e18;
    dist[0] = dist[N] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, 0});
    while(que.size()){
        auto p = que.top(); que.pop();
        int64_t d = p.first;
        int i = p.second;
        if(d > dist[i]) continue;
        for(auto& e : edges[i]){
            int j = e.first;
            int64_t d2 = d + e.second;
            if(d2 < dist[j]){
                dist[j] = d2;
                que.push({d2, j});
            }
        }
    }

    for(int i=0; i<N; i++){
        int64_t ans = dist[i] + dist[i+N];
        printf("%lld\n", ans);
    }
    return 0;
}
0