提交时间:2026-04-04 14:02:21
运行 ID: 435175
#include <iostream> using namespace std; int main() { int n, m,a[1000005],b[1000005]; cin >> n >> m; bool u[1000005] = {false}; int ans[1000005] = {0}; for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; } for (int i = n; i >= 1; i--) { bool o = false; if (!u[a[i]]) { u[a[i]] = true; o = true; } else if (!u[b[i]]) { u[b[i]] = true; o = true; } ans[i] = ans[i + 1] + o; } for (int i = 1; i <= n; i++) { cout << ans[i] << endl; } return 0; }