結果
問題 | No.807 umg tours |
ユーザー | koyopro |
提出日時 | 2019-12-15 23:29:34 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,452 bytes |
コンパイル時間 | 2,346 ms |
コンパイル使用メモリ | 153,528 KB |
実行使用メモリ | 44,152 KB |
最終ジャッジ日時 | 2023-09-15 15:51:16 |
合計ジャッジ時間 | 9,848 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 3 ms
4,376 KB |
testcase_07 | AC | 2 ms
4,376 KB |
testcase_08 | AC | 2 ms
4,380 KB |
testcase_09 | AC | 2 ms
4,380 KB |
testcase_10 | AC | 1 ms
4,376 KB |
testcase_11 | AC | 364 ms
32,624 KB |
testcase_12 | AC | 345 ms
27,648 KB |
testcase_13 | AC | 470 ms
35,264 KB |
testcase_14 | AC | 188 ms
18,220 KB |
testcase_15 | AC | 153 ms
15,320 KB |
testcase_16 | AC | 501 ms
37,732 KB |
testcase_17 | AC | 589 ms
41,208 KB |
testcase_18 | AC | 590 ms
41,612 KB |
testcase_19 | AC | 639 ms
44,152 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 335 ms
33,680 KB |
testcase_25 | AC | 574 ms
40,976 KB |
ソースコード
#include "bits/stdc++.h" using namespace std; #define int long long #define FOR(i, a, b) for(int i=(a);i<(b);i++) #define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--) #define REP(i, n) for(int i=0; i<(n); i++) #define RREP(i, n) for(int i=(n-1); i>=0; i--) #define ALL(a) (a).begin(),(a).end() #define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end()); #define CONTAIN(a, b) find(ALL(a), (b)) != (a).end() #define array2(type, x, y) array<array<type, y>, x> #define vector2(type) vector<vector<type> > #define out(...) //printf(__VA_ARGS__) typedef pair<int, int> pos; int pos::*x = &pos::first; int pos::*y = &pos::second; int dxy[] = {0, 1, 0, -1, 0}; /*================================*/ int N, M, a, b, c; int A[20], B[20]; signed main() { #if DEBUG std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf()); #endif cin >> N >> M; vector< vector<pos> > R(N); REP(i, M) { cin >> a >> b >> c; a--; b--; R[a].push_back(*new pos(b, c)); R[b].push_back(*new pos(a, c)); } // without skip, with skip vector<pos> DP(N); REP(i, N) DP[i].first = DP[i].second = INT_MAX; DP[0].first = DP[0].second = 0; auto c = [](pos l, pos r) { return l.second > r.second; }; priority_queue<pos, std::vector<pos>, decltype(c)> q(c); q.push(*new pos(0, 0)); while(!q.empty()) { pos item = q.top(); q.pop(); int index = item.first; for (auto route: R[index]) { int ni = route.first; { // without skip int newCost = DP[index].first + route.second; if (newCost < DP[ni].first) { DP[ni].first = newCost; q.push(*new pos(ni, newCost)); } } { // with current skip int newCost = DP[index].first; if (newCost < DP[ni].second) { DP[ni].second = newCost; q.push(*new pos(ni, newCost)); } } { // with prev skip int newCost = DP[index].second + route.second; if (newCost < DP[ni].second) { DP[ni].second = newCost; q.push(*new pos(ni, newCost)); } } } } REP(i, N) cout << DP[i].first + DP[i].second << endl; return 0; }