记录编号 142371 评测结果 AAAAAAAAAA
题目名称 [JSOI 2008]星球大战starwar 最终得分 100
用户昵称 GravatarAsm.Def 是否通过 通过
代码语言 C++ 运行时间 0.919 s
提交时间 2014-12-07 23:05:34 内存使用 1.08 MiB
显示代码纯文本
//Asm_Def
#include <iostream>
#include <cctype>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
template<typename T>inline void getd(T &x){
    char c = getchar();
    bool minus = 0;
    while(!isdigit(c) && c != '-')c = getchar();
    if(c == '-')minus = 1, c = getchar();
    x = c - '0';
    while(isdigit(c = getchar()))x = x * 10 + c - '0';
    if(minus)x = -x;
}
/*======================================================*/
#define pb push
template<typename T>struct list{
	struct node{
		T val;
		node *next;
	}Nil;
	struct iterator{
		node *it;
		T &operator * (){return it->val;}
		bool operator == (const iterator&b){return it == b.it;}
		bool operator != (const iterator&b){return it != b.it;}
		friend iterator &operator ++ (iterator &t){
			t.it = t.it->next;
			return t;
		}
	}nil;
	iterator begin(){iterator it;it.it = Nil.next;return it;}
	iterator &end(){return nil;}
	list(){Nil.next = &Nil;nil.it = &Nil;}
	void push(T &x){
		node *t = new node;t->val = x;t->next = Nil.next;Nil.next = t;
	}
};
const int maxn = 400003;
int N, M, K, *ord, cnt;
list<int> *adj;
bool des[maxn], calc[maxn];
int *pre;
int find(int x){return pre[x] == x ? x : pre[x] = find(pre[x]);}
void link(int a, int b){pre[a] = b;}
inline void init(){
	getd(N), getd(M);
	int i, j, a, b;
	adj = new list<int>[N];
	pre = new int[N];
	for(i = 0;i < N;++i)
		pre[i] = i;
	while(M--){
		getd(i),getd(j);
		adj[i].pb(j);
		adj[j].pb(i);
	}
	getd(K);
	ord = new int[K];
	for(i = 0;i < K;++i)
		getd(ord[i]), des[ord[i]] = 1;
	cnt = N - K;
	for(i = 0;i < N;++i)if(!des[i]){
		list<int>::iterator it;
		for(it = adj[i].begin();it != adj[i].end();++it)
			if(!des[*it] && (a = find(i)) != (b = find(*it))){
				link(a, b);
				--cnt;
			}
	}
}
inline void solve(){
	list<int>::iterator it;
	int i, a, b, t, ans[maxn];
	ans[K] = cnt;
	for(i = K - 1;i >= 0;--i){
		++cnt;
		des[t = ord[i]] = 0;
		for(it = adj[t].begin();it != adj[t].end();++it)
			if(!des[*it] && (a = find(t)) != (b = find(*it))){
				link(a, b);
				--cnt;
			}
		ans[i] = cnt;
	}
	for(i = 0;i <= K;++i)
		printf("%d\n", ans[i]);
}
int main(){
    #if defined DEBUG
    freopen("test", "r", stdin);
	#else
	#ifndef ONLINE_JUDGE
	freopen("bzoj_1015.in", "r", stdin);
	freopen("bzoj_1015.out", "w", stdout);
	#endif
    #endif
	init();
	solve();
	
    #if defined DEBUG
    cout << endl << (double)clock()/CLOCKS_PER_SEC << endl;
    #endif
    return 0;
}