#include using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) #define rrep(i, s, t) for(ll i = (ll)(t) - 1; i >= (ll)(s); i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) #define TT template TT using vec = vector; template bool chmin(T1 &x, T2 y) { return x > y ? (x = y, true) : false; } template bool chmax(T1 &x, T2 y) { return x < y ? (x = y, true) : false; } struct io_setup { io_setup() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cout << fixed << setprecision(15); } } io_setup; #include void solve(){ int N,M; cin>>N>>M; vectorU(M),V(M); rep(i,0,M){ cin>>U[i]>>V[i]; U[i]--; V[i]--; } int Q; cin>>Q; vectorB(Q); vectorflag(M,true); rep(i,0,Q){ cin>>B[i]; B[i]--; flag[B[i]]=false; } atcoder::dsu uf(N); rep(i,0,M){ if(flag[i]){ uf.merge(U[i],V[i]); } } ll cost=(ll)N*(N-1)/2; vectorC(N); rep(i,0,N)C[uf.leader(i)]++; rep(i,0,N)cost-=(ll)C[i]*(C[i]-1)/2; vectorans; ans.push_back(cost); rrep(i,1,Q){ int u=U[B[i]],v=V[B[i]]; if(uf.same(u,v)){ ans.push_back(cost); }else{ cost-=(ll)uf.size(u)*uf.size(v); uf.merge(u,v); ans.push_back(cost); } } reverse(all(ans)); rep(i,0,Q)cout<