結果
| 問題 | No.3103 Butterfly Effect |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-11 23:55:12 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,468 bytes |
| 記録 | |
| コンパイル時間 | 4,408 ms |
| コンパイル使用メモリ | 260,312 KB |
| 実行使用メモリ | 62,788 KB |
| 最終ジャッジ日時 | 2025-04-11 23:55:35 |
| 合計ジャッジ時間 | 23,272 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 30 WA * 11 RE * 9 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
#include <cassert>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)
#define all(x) begin(x), end(x)
template <typename T> bool chmin(T& x, T y) {
return x > y ? (x = y, true) : false;
}
template <typename T> bool chmax(T& x, T y) {
return x < y ? (x = y, true) : false;
}
struct IOST {
IOST() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(20);
}
} IOST;
void solve() {
int n, q;
cin >> n >> q;
vector<set<pair<int, int>>> g(n);
vector<int> tm(n, 1e9);
vector<int> st(n, -1);
tm[0] = 0;
int ans = 1;
rep(Qi, 0, q) {
int p, x, y;
cin >> p >> x >> y;
x--, y--;
if (tm[x] > p && tm[y] > p) {
g[x].insert({p, y});
g[y].insert({p, x});
cout << ans << "\n";
continue;
}
if (tm[x] < p && tm[y] < p) {
cout << ans << "\n";
continue;
}
if (tm[x] < p) swap(x, y);
assert(tm[x] > p && tm[y] < p);
if (tm[x] == 1e9) ans++;
tm[x] = p;
queue<int> que;
que.push(x);
while (!que.empty()) {
int nw = que.front();
que.pop();
if (!chmax(st[nw], (int)Qi)) continue;
while (1) {
auto itr = g[nw].lower_bound({tm[x], -1});
if (itr == g[nw].end()) break;
auto [nt, nx] = *itr;
if (tm[nx] == 1e9) ans++;
if (chmin(tm[nx], nt)) que.push(nt);
g[nw].erase(itr);
}
}
cout << ans << "\n";
}
}
int main() {
int t = 1;
// cin >> t;
rep(i, 0, t) solve();
}