結果
問題 |
No.468 役に立つ競技プログラミング実践編
|
ユーザー |
|
提出日時 | 2016-12-18 09:54:27 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,420 bytes |
コンパイル時間 | 811 ms |
コンパイル使用メモリ | 78,480 KB |
実行使用メモリ | 33,700 KB |
最終ジャッジ日時 | 2024-12-14 07:53:13 |
合計ジャッジ時間 | 32,496 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 7 WA * 14 TLE * 10 |
other | AC * 6 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:15:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 15 | scanf("%d%d", &n, &m); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:19:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 19 | int a, b, c; scanf("%d%d%d", &a, &b, &c); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <iostream> #include <algorithm> #include <queue> #include <tuple> using namespace std; using i64 = long long; struct edge { int to, cost; }; int n, m; int main(void) { scanf("%d%d", &n, &m); vector<vector<edge>> G0(n, vector<edge>()); // G[n][] vector<vector<edge>> rG(n, vector<edge>()); // revG[n][] for(int i=0; i<m; ++i) { int a, b, c; scanf("%d%d%d", &a, &b, &c); G0[a].push_back(edge({b, c})); rG[b].push_back(edge({a, c})); } vector<int> cost0(n, 0); // cost[n] queue<pair<int, int>> que0; // コスト、点番号 que0.emplace(0, 0); while(!que0.empty()) { int _, v; tie(_, v) = que0.front(); que0.pop(); for(edge e : G0[v]) { if(cost0[e.to] < cost0[v] + e.cost) { cost0[e.to] = cost0[v] + e.cost; que0.emplace(cost0[e.to], e.to); } } } vector<int> rcost(n, 0); // rcost[n] queue<pair<int, int>> rq; // コスト、点番号 rq.emplace(0, n-1); while(!rq.empty()) { int _, v; tie(_, v) = rq.front(); rq.pop(); for(edge e : rG[v]) { if(rcost[e.to] < rcost[v] + e.cost) { rcost[e.to] = rcost[v] + e.cost; rq.emplace(rcost[e.to], e.to); } } } for(int i=0; i<n; ++i) { rcost[i] = cost0[n-1] - rcost[i]; } int res = cost0[n-1]; int cnt = 0; for(int i=0; i<n; ++i) { if(cost0[i] != rcost[i]) { ++cnt; } } printf("%d %d/%d\n", res, cnt, n); return 0; }