結果
問題 | No.468 役に立つ競技プログラミング実践編 |
ユーザー |
|
提出日時 | 2016-12-18 13:13:42 |
言語 | C++11 (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,008 bytes |
コンパイル時間 | 831 ms |
コンパイル使用メモリ | 80,092 KB |
実行使用メモリ | 31,140 KB |
最終ジャッジ日時 | 2024-12-14 08:15:15 |
合計ジャッジ時間 | 33,715 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 21 TLE * 10 |
other | AC * 6 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:41:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 41 | int n, m; scanf("%d%d", &n, &m); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:46:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 46 | scanf("%d%d%lld", &a, &b, &c); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <iostream> #include <algorithm> #include <queue> #include <tuple> using namespace std; using i64 = long long; #ifdef DEBUG #define debug1(x1) cerr << #x1 "=" << (x1) << '\n'; #define debug2(x1, x2) cerr << #x1 "=" << (x1) << ", " << #x2 "=" << (x2) << '\n'; #define debug3(x1, x2, x3) cerr << #x1 "=" << (x1) << ", " << #x2 "=" << (x2) << ", " << #x3 "=" << (x3) << '\n'; #define debug4(x1, x2, x3, x4) cerr << #x1 "=" << (x1) << ", " << #x2 "=" << (x2) << ", " << #x3 "=" << (x3) << ", " << #x4 "=" << (x4) << '\n'; #define debug5(x1, x2, x3, x4, x5) cerr << #x1 "=" << (x1) << ", " << #x2 "=" << (x2) << ", " << #x3 "=" << (x3) << ", " << #x4 "=" << (x4) << ", " << #x5 "=" << (x5) << '\n'; #define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME #define debug(...) GET_MACRO(__VA_ARGS__, debug5, debug4, debug3, debug2, debug1)(__VA_ARGS__) template<class T> void debugv(vector<T> v, string sep) { const int n = v.size(); cerr << "'"; for(int i=0; i<n; ++i) { if(i!=0) { cerr << sep; } cerr << v[i]; } cerr << "'\n"; } template<class T> void debugv(vector<T> v) { debugv(v, " "); } template<class T> void debugv(vector<vector<T>> v) { int n = v.size(); for(int i=0; i<n; ++i) { debugv(v[i]); } } template<class T> void debugv(vector<vector<vector<T>>> v) { int n = v.size(); for(int i=0; i<n; ++i) { debugv(v[i]); } } template<class T> void debugv(vector<vector<vector<vector<T>>>> v) { int n = v.size(); for(int i=0; i<n; ++i) { debugv(v[i]); } } template<class T> void debugv(vector<vector<vector<vector<vector<T>>>>> v) { int n = v.size(); for(int i=0; i<n; ++i) { debugv(v[i]); } } #else #define debug(...) ((void)0) #define debugv(...) ((void)0) #endif struct edge { int to; i64 cost; }; int main(void) { int n, m; scanf("%d%d", &n, &m); vector<vector<edge>> G0(n, vector<edge>()); // G[n][] vector<vector<edge>> rG(n, vector<edge>()); // revG[n][] int a, b; i64 c; for(int i=0; i<m; ++i) { scanf("%d%d%lld", &a, &b, &c); G0[a].push_back(edge({b, c})); rG[b].push_back(edge({a, c})); } vector<i64> cost0(n, -1); // cost[n] cost0[0] = 0; priority_queue<pair<i64, int>, vector<pair<i64, int>>> que0; // コスト、点番号 que0.emplace(0, 0); while(!que0.empty()) { i64 cc; int v; tie(cc, v) = que0.top(); que0.pop(); cost0[v] = cc; for(edge& e : G0[v]) { if(cost0[e.to] < cc + e.cost) { que0.emplace(cc + e.cost, e.to); } } } vector<i64> rcost(n, -1); // rcost[n] rcost[n-1] = 0; priority_queue<pair<i64, int>, vector<pair<i64, int>>> rq; // コスト、点番号 rq.emplace(0, -(n-1)); while(!rq.empty()) { i64 cc; int v; tie(cc, v) = rq.top(); rq.pop(); v *= -1; rcost[v] = cc; for(edge& e : rG[v]) { if(rcost[e.to] < cc + e.cost) { rq.emplace(cc + e.cost, -e.to); } } } i64 days = cost0[n-1]; int cnt = 0; for(int i=0; i<n; ++i) { if(cost0[i] != days - rcost[i]) { ++cnt; } } printf("%lld %d/%d\n", days, cnt, n); return 0; }