提交时间:2026-04-04 14:01:44
运行 ID: 435174
#include <iostream> using namespace std; int main() { int n, m,a[100005],b[100005]; cin >> n >> m; bool u[100005] = {false}; // 这里必须全局初始化! int ans[100005] = {0}; for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; // 删掉错误的 u[i] = false; // 删掉错误的 ans[i] = 0; } // 删掉错误的 u[n+1] = false; // 删掉错误的 ans[n+1] = 0; 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; }