結果

問題 No.807 umg tours
ユーザー noisy_noiminnoisy_noimin
提出日時 2019-03-22 23:07:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,482 bytes
コンパイル時間 2,561 ms
コンパイル使用メモリ 115,344 KB
実行使用メモリ 31,204 KB
最終ジャッジ日時 2023-10-19 10:20:56
合計ジャッジ時間 14,437 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,688 KB
testcase_01 WA -
testcase_02 AC 5 ms
5,688 KB
testcase_03 AC 5 ms
5,688 KB
testcase_04 WA -
testcase_05 AC 4 ms
5,688 KB
testcase_06 AC 5 ms
5,688 KB
testcase_07 AC 5 ms
5,688 KB
testcase_08 AC 4 ms
5,688 KB
testcase_09 AC 4 ms
5,688 KB
testcase_10 AC 4 ms
5,688 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 618 ms
22,440 KB
testcase_21 AC 674 ms
23,124 KB
testcase_22 AC 230 ms
13,400 KB
testcase_23 AC 174 ms
11,880 KB
testcase_24 AC 576 ms
25,852 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int MAX_N = 112345;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

map<ll, ll> d[2];
vector< vector<Pll> > edges(MAX_N);

struct State {
    ll d, longest_edge;
    int node;
    State(int node, ll d, ll longest_edge): node(node), d(d), longest_edge(longest_edge) {}
    bool operator>(const State& s) const{
        return d+longest_edge > s.d+s.longest_edge;
    }
};

void dijkstra(ll start, int shortcut){
    priority_queue<State, vector<State>, greater<State> > que;

    d[shortcut][start] = 0;
    que.push(State(start, 0, 0));

    while(!que.empty()){
        State v = que.top(); que.pop();
        if(d[shortcut].find(v.node) != d[shortcut].end() && d[shortcut][v.node] < v.d) continue;

        for(Pll e: edges[v.node]){
            if(shortcut) {
                if(d[1].find(e.first) == d[1].end() || d[1][e.first] > d[1][v.node] + v.longest_edge + e.second - max(v.longest_edge, e.second)){
                    d[1][e.first] = d[1][v.node] + v.longest_edge + e.second - max(v.longest_edge, e.second);
                    que.push(State(e.first, d[1][e.first], max(v.longest_edge, e.second)));
                }
            } else {
                if(d[0].find(e.first) == d[0].end() || d[0][e.first] > d[0][v.node] + e.second){
                    d[0][e.first] = d[0][v.node] + e.second;
                    que.push(State(e.first, d[0][e.first], 0));
                }
            }
            
        }
    }
}

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n,m,a,b; ll c;
    cin >> n >> m;
    for(int i=0;i<m;++i) {
        cin >> a >> b >> c;
        edges[a].emplace_back(b, c);
        edges[b].emplace_back(a, c);
    }

    dijkstra(1LL, 0);
    dijkstra(1LL, 1);

    for(int i=1;i<=n;++i) {
        cout << d[0][i] + d[1][i] << endl;
        // cerr << i << ": " << d[0][i] << " "  << d[1][i] << " " << longest_edge[i] << endl;
    }
}
0