1098: [POI2007]办公楼biu
Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 737 Solved: 306
[ Submit][ Status]
Description
FGD开办了一家电话公司。他雇用了N个职员,给了每个职员一部手机。每个职员的手机里都存储有一些同事的电话号码。由于FGD的公司规模不断扩大,旧的办公楼已经显得十分狭窄,FGD决定将公司迁至一些新的办公楼。 FGD希望职员被安置在尽量多的办公楼当中,这样对于每个职员来说都会有一个相对更好的工作环境。但是,为了联系方便起见,如果两个职员被安置在两个不同的办公楼之内,他们必须拥有彼此的电话号码。
Input
第一行包含两个整数N(2<=N<=100000)和M(1<=M<=2000000)。职员被依次编号为1,2,……,N. 以下M行,每行包含两个正数A和B(1<=A
Output
包含两行。第一行包含一个数S,表示FGD最多可以将职员安置进的办公楼数。第二行包含S个从小到大排列的数,每个数后面接一个空格,表示每个办公楼里安排的职员数。
Sample Input
7 16
1 3
1 4
1 5
2 3
3 4
4 5
4 7
4 6
5 6
6 7
2 4
2 7
2 5
3 5
3 7
1 7
1 3
1 4
1 5
2 3
3 4
4 5
4 7
4 6
5 6
6 7
2 4
2 7
2 5
3 5
3 7
1 7
Sample Output
3
1 2 4
1 2 4
HINT
FGD可以将职员4安排进一号办公楼,职员5和职员7安排进2号办公楼,其他人进3号办公楼。
Source
考虑两个点 X Y 如果 X Y没有边,那X与Y必定分在同一组,所以求出原图的补图,再求出联通分量的个数就行了。 需要用链表优化。
var
n,m,i,j,k,x,y,tot,s,p,now:longint;
a,ans,pd,pre,suc,z:array [0..100001] of longint;
jud:array [0..100001] of boolean;
b:array [1..4000000,1..2] of longint;
procedure insert(x,y:longint);
begin
inc(tot);
b[tot,1]:=y;
b[tot,2]:=a[x];
a[x]:=tot;
end;
procedure sort(l,r:longint);
var
i,j,x,t:longint;
begin
i:=l;
j:=r;
x:=ans[(l+r) shr 1];
repeat
while ans[i]<x do
inc(i);
while ans[j]>x do
dec(j);
if i<=j then
begin
t:=ans[i];
ans[i]:=ans[j];
ans[j]:=t;
inc(i);
dec(j);
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
procedure delt(now:longint);
begin
suc[pre[now]]:=suc[now];
pre[suc[now]]:=pre[now];
if now=s then s:=suc[now];
end;
begin
read (n,m);
for i:=1 to m do
begin
read (x,y);
insert(x,y);
insert(y,x);
end;
for i:=1 to n do
begin
pre[i]:=i-1;
suc[i]:=i+1;
end;
s:=1;
tot:=0;
for k:=1 to n do
if not jud[k] then
begin
i:=1;
j:=2;
z[1]:=k;
jud[k]:=true;
delt(k);
while i<>j do
begin
p:=a[z[i]];
while p<>0 do
begin
pd[b[p,1]]:=i;
p:=b[p,2];
end;
now:=s;
while now<>n+1 do
begin
if pd[now]<>i then
begin
jud[now]:=true;
z[j]:=now;
inc(j);
delt(now);
end;
now:=suc[now];
end;
now:=s;
while now<>n+1 do
begin
pd[now]:=0;
now:=suc[now];
end;
inc(i);
end;
inc(tot);
ans[tot]:=i-1;
end;
writeln(tot);
sort(1,tot);
for i:=1 to tot-1 do
write(ans[i],' ');
write(ans[tot]);
end.
var
n,m,i,j,k,x,y,tot,s,p,now:longint;
a,ans,pd,pre,suc,z:array [0..100001] of longint;
jud:array [0..100001] of boolean;
b:array [1..4000000,1..2] of longint;
procedure insert(x,y:longint);
begin
inc(tot);
b[tot,1]:=y;
b[tot,2]:=a[x];
a[x]:=tot;
end;
procedure sort(l,r:longint);
var
i,j,x,t:longint;
begin
i:=l;
j:=r;
x:=ans[(l+r) shr 1];
repeat
while ans[i]<x do
inc(i);
while ans[j]>x do
dec(j);
if i<=j then
begin
t:=ans[i];
ans[i]:=ans[j];
ans[j]:=t;
inc(i);
dec(j);
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
procedure delt(now:longint);
begin
suc[pre[now]]:=suc[now];
pre[suc[now]]:=pre[now];
if now=s then s:=suc[now];
end;
begin
read (n,m);
for i:=1 to m do
begin
read (x,y);
insert(x,y);
insert(y,x);
end;
for i:=1 to n do
begin
pre[i]:=i-1;
suc[i]:=i+1;
end;
s:=1;
tot:=0;
for k:=1 to n do
if not jud[k] then
begin
i:=1;
j:=2;
z[1]:=k;
jud[k]:=true;
delt(k);
while i<>j do
begin
p:=a[z[i]];
while p<>0 do
begin
pd[b[p,1]]:=i;
p:=b[p,2];
end;
now:=s;
while now<>n+1 do
begin
if pd[now]<>i then
begin
jud[now]:=true;
z[j]:=now;
inc(j);
delt(now);
end;
now:=suc[now];
end;
now:=s;
while now<>n+1 do
begin
pd[now]:=0;
now:=suc[now];
end;
inc(i);
end;
inc(tot);
ans[tot]:=i-1;
end;
writeln(tot);
sort(1,tot);
for i:=1 to tot-1 do
write(ans[i],' ');
write(ans[tot]);
end.