結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー yuppe19 😺yuppe19 😺
提出日時 2016-12-18 11:59:43
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,557 bytes
コンパイル時間 1,079 ms
コンパイル使用メモリ 80,076 KB
実行使用メモリ 31,264 KB
最終ジャッジ日時 2024-05-08 06:29:37
合計ジャッジ時間 5,977 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,764 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,812 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 76 ms
6,944 KB
testcase_15 AC 101 ms
6,944 KB
testcase_16 AC 102 ms
6,940 KB
testcase_17 AC 72 ms
6,940 KB
testcase_18 AC 75 ms
6,940 KB
testcase_19 AC 71 ms
6,944 KB
testcase_20 AC 82 ms
6,940 KB
testcase_21 AC 98 ms
6,940 KB
testcase_22 AC 72 ms
6,940 KB
testcase_23 AC 109 ms
6,944 KB
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:13:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |   int n, m; scanf("%d%d", &n, &m);
      |             ~~~~~^~~~~~~~~~~~~~~~
main.cpp:18:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |     scanf("%d%d%lld", &a, &b, &c);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <queue>
#include <tuple>
using namespace std;
using i64 = long long;

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();
    if(cc < cost0[v]) { continue; }
    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<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();
    if(cc < rcost[v]) { continue; }
    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);
      }
    }
  }

  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