結果

問題 No.468 役に立つ競技プログラミング実践編
コンテスト
ユーザー yuppe19 😺
提出日時 2016-12-18 20:23:10
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 1,393 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 919 ms
コンパイル使用メモリ 97,324 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-25 02:45:54
合計ジャッジ時間 5,038 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 21 TLE * 1 -- * 9
other AC * 3 -- * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

struct edge {
  int from, to; i64 cost;
  bool operator < (const edge& other) const {
    return make_tuple(from, to, cost) < make_tuple(other.from, other.to, other.cost);
  }
};

vector<edge> G0;
vector<i64> cost0, rcost;

int main(void) {
  constexpr i64 inf = 1;
  int n, m; scanf("%d%d", &n, &m);
  
  int a, b; i64 c;
  for(int i=0; i<m; ++i) {
    scanf("%d%d%lld", &a, &b, &c);
    G0.push_back(edge({a, b, -c}));
  }
  sort(begin(G0), end(G0));

  cost0.assign(n, inf);
  cost0[0] = 0;
  while(true) {
    bool update = false;
    for(int i=0; i<m; ++i) {
      edge e = G0[i];
      if(cost0[e.from] != inf && cost0[e.to] > cost0[e.from] + e.cost) {
        cost0[e.to] = cost0[e.from] + e.cost;
        update = true;
      }
    }
    if(!update) { break; }
  }

  rcost.assign(n, inf);
  rcost[n-1] = 0;
  while(true) {
    bool update = false;
    for(int i=m-1; i>=0; --i) {
      edge e = G0[i];
      if(rcost[e.to] != inf && rcost[e.from] > rcost[e.to] + e.cost) {
        rcost[e.from] = rcost[e.to] + e.cost;
        update = true;
      }
    }
    if(!update) { break; }
  }

  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