#include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N,Q; cin >> N >> Q; vector>> Hold(N); int answer = 1; vector T(N,Q+1); T.at(0) = 0; for(int t=0; t> p >> x >> y; p--; x--; y--; int xt = T.at(x),yt = T.at(y); if(xt < p && yt < p){} else if(xt > p && yt > p) Hold.at(x)[p] = y,Hold.at(y)[p] = x; else{ if(xt > p) swap(x,y),swap(xt,yt); if(T.at(y) == Q+1) answer++; T.at(y) = p; priority_queue,vector>,greater<>> PQ; PQ.push({p,y}); while(PQ.size()){ auto [ti,pos] = PQ.top(); PQ.pop(); if(T.at(pos) != ti) continue; vector era; for(auto [k,to] : Hold.at(pos)){ if(k < ti) break; if(T.at(to) > k){ if(T.at(to) == Q+1) answer++; T.at(to) = k; PQ.push({k,to}); } era.push_back(k); } for(auto e : era) Hold.at(pos).erase(e); } } cout << answer << "\n"; } }