提交时间:2026-04-04 14:03:37
运行 ID: 435177
#include <iostream> using namespace std; int main() { // 把数组定义在 main 外面 = 全局自动全初始化为 0!!! int a[1000005],b[1000005]; bool u[1000005]; int ans[1000005]; int n, m; cin >> n >> m; 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; }