#include #include #include 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 bool chmin(T& x, T y) { return x > y ? (x = y, true) : false; } template 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>> g(n); vector tm(n, 1e9); vector 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 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(); }