結果

問題 No.1393 Median of Walk
ユーザー 👑 hos.lyrichos.lyric
提出日時 2021-02-12 22:04:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,494 bytes
コンパイル時間 1,062 ms
コンパイル使用メモリ 103,768 KB
実行使用メモリ 14,068 KB
最終ジャッジ日時 2023-09-27 04:57:13
合計ジャッジ時間 3,158 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,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 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 2 ms
4,376 KB
testcase_29 WA -
testcase_30 AC 15 ms
5,744 KB
testcase_31 AC 14 ms
5,516 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 11 ms
7,664 KB
testcase_39 AC 13 ms
7,716 KB
testcase_40 AC 10 ms
4,420 KB
testcase_41 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }

constexpr int MAX_N = 1010;
constexpr int MAX_M = 2510;

struct Edge {
  int a, b, c;
};

int N, M;
Edge E[MAX_M];

vector<int> G[MAX_N];

int S[MAX_M];
int dist[MAX_N];
int que[10'000'010], *qb, *qe;
int on[MAX_N];

void shortest(int src, int c0) {
  if (chmin(dist[src], c0)) {
    qb = qe = que;
    *qe++ = src;
    on[src] = true;
    for (; qb != qe; ) {
      const int u = *qb++;
      on[u] = false;
      for (const int i : G[u]) {
        const int v = E[i].b;
        const int cc = max(dist[u] + S[i], -(M + 1));
        if (chmin(dist[v], cc)) {
          if (!on[v]) {
            *qe++ = v;
            on[v] = true;
          }
        }
      }
    }
  }
}

int ans[MAX_N];

int main() {
  for (; ~scanf("%d%d", &N, &M); ) {
    for (int i = 0; i < M; ++i) {
      scanf("%d%d%d", &E[i].a, &E[i].b, &E[i].c);
      --E[i].a;
      --E[i].b;
    }
    sort(E, E + N, [&](const Edge &e0, const Edge &e1) {
      return (e0.c < e1.c);
    });
    
    fill(G, G + N, vector<int>{});
    for (int i = 0; i < M; ++i) {
      G[E[i].a].push_back(i);
    }
    fill(S, S + M, +1);
    fill(dist, dist + N, M + 1);
    shortest(0, 0);
    
    fill(ans, ans + N, -1);
    for (int i = 0; i < M; ++i) {
      S[i] = -1;
      shortest(E[i].b, dist[E[i].a] - 1);
// cerr<<"dist = ";pv(dist,dist+N);
      for (int u = 1; u < N; ++u) {
        if (dist[u] <= 0) {
          if (ans[u] == -1) {
            ans[u] = E[i].c;
          }
        }
      }
    }
    for (int u = 1; u < N; ++u) {
      printf("%d\n", ans[u]);
    }
cerr<<"========"<<endl;
  }
  return 0;
}
0