結果
問題 | No.1393 Median of Walk |
ユーザー |
👑 |
提出日時 | 2021-02-12 22:06:22 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 60 ms / 2,000 ms |
コード長 | 2,495 bytes |
コンパイル時間 | 1,080 ms |
コンパイル使用メモリ | 106,688 KB |
実行使用メモリ | 13,312 KB |
最終ジャッジ日時 | 2024-07-19 22:53:02 |
合計ジャッジ時間 | 3,112 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 39 |
ソースコード
#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;bool 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 + M, [&](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;}