結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー yuppe19 😺yuppe19 😺
提出日時 2016-12-18 13:13:42
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,008 bytes
コンパイル時間 1,044 ms
コンパイル使用メモリ 79,648 KB
実行使用メモリ 29,440 KB
最終ジャッジ日時 2024-05-08 06:33:15
合計ジャッジ時間 6,337 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,624 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
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 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 TLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#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;
}
0