結果
問題 | No.1024 Children in a Row |
ユーザー |
👑 ![]() |
提出日時 | 2020-04-14 23:46:42 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,711 bytes |
コンパイル時間 | 3,982 ms |
コンパイル使用メモリ | 213,444 KB |
最終ジャッジ日時 | 2025-01-09 19:12:28 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 2 WA * 25 |
ソースコード
#define _USE_MATH_DEFINES#include <bits/stdc++.h>using namespace std;#define FOR(i,m,n) for(int i=(m);i<(n);++i)#define REP(i,n) FOR(i,0,n)#define ALL(v) (v).begin(),(v).end()using ll = long long;const int INF = 0x3f3f3f3f;const ll LINF = 0x3f3f3f3f3f3f3f3fLL;const double EPS = 1e-8;const int MOD = 1000000007;// const int MOD = 998244353;const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }struct IOSetup {IOSetup() {cin.tie(nullptr);ios_base::sync_with_stdio(false);cout << fixed << setprecision(20);}} iosetup;int main() {int n, m; cin >> n >> m;vector<int> a(m), b(m), k(m); REP(i, m) cin >> a[i] >> b[i] >> k[i], --a[i], --b[i];vector<vector<vector<pair<int, int>>>> graph(n, vector<vector<pair<int, int>>>(1));vector<int> dst(m);REP(i, m) {dst[i] = graph[a[i]].size();graph[a[i]].emplace_back();graph[b[i]].back().emplace_back(a[i], dst[i]);}// REP(i, m) cout << dst[i] << " \n"[i + 1 == m];vector<vector<int>> l(n), r(n);REP(i, n) {l[i].resize(graph[i].size());r[i].resize(graph[i].size());}vector<int> children;function<void(int, int)> dfs = [&](int src1, int src2) {l[src1][src2] = children.size();children.emplace_back(src1);reverse(ALL(graph[src1][src2]));for (auto [dst1, dst2] : graph[src1][src2]) dfs(dst1, dst2);r[src1][src2] = children.size();};REP(i, n) dfs(i, 0);// REP(i, n + m) cout << children[i] << " \n"[i + 1 == n + m];// REP(i, n) REP(j, graph[i].size()) cout << i << ' ' << j << " : " << l[i][j] << ' ' << r[i][j] << '\n';vector<int> latest(n);REP(i, n) latest[i] = l[i][graph[i].size() - 1];sort(ALL(latest));// REP(i, n) cout << latest[i] << " \n"[i + 1 == n];function<bool(int, int, int&)> solve = [&](int left, int right, int &k) {// cout << left << ' ' << right << '\n';int cnt = upper_bound(ALL(latest), right) - lower_bound(ALL(latest), left);if (cnt < k) {k -= cnt;return false;}int idx = lower_bound(ALL(latest), left) - latest.begin();cout << children[latest[idx + k - 1]] + 1 << '\n';return true;};REP(i, m) {int prev = l[a[i]][dst[i] - 1];assert(solve(0, prev, k[i])|| solve(l[a[i]][dst[i]], r[a[i]][dst[i]] - 1, k[i])|| solve(prev + 1, l[a[i]][dst[i]] - 1, k[i])|| solve(r[a[i]][dst[i]], n + m - 1, k[i]));}return 0;}