// fast // O(N + Q log Q) #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, q; cin >> n >> q; vector dp(n, q+1); dp[0] = -1; vector>> horyu(n); int ans = 1; for (int num=0; num> p; p--; int x, y; cin >> x >> y; x--; y--; if (dp[x] < p && dp[y] < p) { }else if (dp[x] > p && dp[y] > p) { horyu[x].insert(pair(p,y)); horyu[y].insert(pair(p,x)); }else{ if (dp[y] < p) { swap(x, y); } assert(dp[x] < p && dp[y] > p); if (dp[y] == q+1) ans++; dp[y] = p; priority_queue> mada; mada.push(pair(p,y)); while (!mada.empty()) { auto [t,i] = mada.top(); mada.pop(); if (dp[i] > t) continue; while (true) { auto itr = horyu[i].lower_bound(pair(t,0)); if (itr == horyu[i].end()) { break; } int tim = (*itr).first; int z = (*itr).second; horyu[i].erase(itr); if (dp[z] > tim) { if (dp[z] == q+1) ans++; dp[z] = tim; mada.push(pair(tim,z)); } } } } cout << ans << '\n'; } }