bzoj1098 1301
这两题很类似,都是在补图上搜索
但是由于补图太大我们不能建出来
考虑先从一个点搜,每次搜可以搜的点,
然后维护一个链表,记录当前还没有搜过的点,搜过之后从链表中删除即可
type node=record
po,next:longint;
end; var e:array[..] of node;
l:array[..] of node;
p,q,ans:array[..] of longint;
can,v:array[..] of boolean;
s,i,n,m,len,x,y:longint; procedure add(x,y:longint);
begin
inc(len);
e[len].po:=y;
e[len].next:=p[x];
p[x]:=len;
end; procedure swap(var a,b:longint);
var c:longint;
begin
c:=a;
a:=b;
b:=c;
end; procedure sort(l,r:longint);
var i,j,x:longint;
begin
i:=l;
j:=r;
x:=ans[(l+r) shr ];
repeat
while ans[i]<x do inc(i);
while x<ans[j] do dec(j);
if not(i>j) then
begin
swap(ans[i],ans[j]);
inc(i);
dec(j);
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end; procedure del(i:longint);
begin
l[l[i].po].next:=l[i].next;
if l[i].next<>- then l[l[i].next].po:=l[i].po;
end; procedure bfs;
var f,r,i,t:longint;
begin
while l[].next<>- do
begin
f:=;
r:=;
v[l[].next]:=true;
q[]:=l[].next;
del(l[].next);
t:=;
while f<=r do
begin
x:=q[f];
i:=p[x];
while i<> do
begin
can[e[i].po]:=true;
i:=e[i].next;
end;
i:=l[].next;
while i>- do
begin
if not v[i] and not can[i] then
begin
inc(r);
q[r]:=i;
del(i);
inc(t);
v[i]:=true;
end;
i:=l[i].next;
end;
i:=p[x];
while i<> do
begin
can[e[i].po]:=false;
i:=e[i].next;
end;
inc(f);
end;
inc(s);
ans[s]:=t;
end;
end; begin
readln(n,m);
for i:= to m do
begin
readln(x,y);
add(x,y);
add(y,x);
end;
for i:= to n do
begin
l[i].po:=i-;
l[i-].next:=i;
end;
l[n].next:=-;
bfs;
sort(,s);
writeln(s);
for i:= to s do
write(ans[i],' ');
writeln;
end.
1098
type node=record
po,next:longint;
end; var e:array[..] of node;
l:array[..] of node;
p:array[..] of longint;
can:array[..] of boolean;
i,n,m,x,y,len:longint; procedure add(x,y:longint);
begin
inc(len);
e[len].po:=y;
e[len].next:=p[x];
p[x]:=len;
end; procedure del(i:longint);
begin
l[l[i].po].next:=l[i].next;
if l[i].next<>- then l[l[i].next].po:=l[i].po;
end; procedure dfs(x:longint);
var i,j:longint;
begin
writeln(x);
del(x);
i:=p[x];
while i<> do
begin
can[e[i].po]:=true;
i:=e[i].next;
end;
i:=l[].next;
while i>- do
begin
if not can[i] then
begin
j:=p[x];
while j<> do
begin
can[e[j].po]:=false;
j:=e[j].next;
end;
dfs(i);
exit;
end;
i:=l[i].next;
end;
end; begin
readln(n,m);
for i:= to m do
begin
readln(x,y);
add(x,y);
add(y,x);
end;
for i:= to n do
begin
l[i-].next:=i;
l[i].po:=i-;
end;
l[n].next:=-;
dfs();
end.
1301
bzoj1098 1301的更多相关文章
- 【bzoj1098】办公楼
[bzoj1098]办公楼 题意 FGD开办了一家电话公司.他雇用了N个职员,给了每个职员一部手机.每个职员的手机里都存储有一些同事的电话号码.由于FGD的公司规模不断扩大,旧的办公楼已经显得十分狭窄 ...
- HDOJ 1301
9852303 2013-12-18 11:47:01 Accepted 1301 0MS 264K 1117 B C++ 泽泽 Jungle Roads Time Limit: 2000/1000 ...
- hdu 1301 Jungle Roads 最小生成树
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1301 The Head Elder of the tropical island of Lagrish ...
- HDOJ 1301 Jungle Roads
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1301 //HDOJ1301 #include<iostream>#include<c ...
- hihocoder #1301 : 筑地市场 数位dp+二分
题目链接: http://hihocoder.com/problemset/problem/1301?sid=804672 题解: 二分答案,每次判断用数位dp做. #include<iostr ...
- hdu 1301 Jungle Roads
http://acm.hdu.edu.cn/showproblem.php?pid=1301 #include <cstdio> #include <cstring> #inc ...
- Hdu 1301 Jungle Roads (最小生成树)
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1301 很明显,这是一道“赤裸裸”的最小生成树的问题: 我这里采用了Kruskal算法,当然用Prim算法也 ...
- (最小生成树)Jungle Roads -- HDU --1301
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1301 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- hihocoder #1301 : 筑地市场 二分+数位dp
#1301 : 筑地市场 题目连接: http://hihocoder.com/problemset/problem/1301 Description 筑地市场是位于日本东京都中央区筑地的公营批发市场 ...
随机推荐
- 符合web标准的网页下拉菜单
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN"> <head> < ...
- ECSHOP如何解决购物车中商品自动消失问题
最近有客户反映关于ECShop购物车的问题:需要加入多个商品到购物车时,发现之前加入到购物车的商品都自动消失了,只有最后一次加入购物车的商品在里面.那么,这是什么原因呢? 因为ECShop的SESSI ...
- java 中的equal和"=="
先看一段代码 String str1 = new String("str"); String str2 = new String("str"); System. ...
- Pandas之容易让人混淆的行选择和列选择
在刚学Pandas时,行选择和列选择非常容易混淆,在这里进行一下讨论和归纳 本文的数据来源:https://github.com/fivethirtyeight/data/tree/master/fa ...
- 以a为变量名,给出下列描述的定义
a)一个整型数(An integer) b) 一个指向整型数的指针(A pointer to an integer) c) 一个指向指针的的指针,它指向的指针是指向一个整型数(A pointer to ...
- (转)Mac OS X内核编程,MAC驱动开发资源汇总
一.Mac OS X内核编程开发官方文档: I/O Kit Fundamentals: I/O Kit基础 - Mac OS X系统内核编程 https://developer.apple.com ...
- The method of type must override a superclass method
导入android项目时,报The method of type must override asuperclass method 一堆错误, 解决方法: 将编译的jdk与使用的jdk版本一致即可.
- asp.net 运行时, 报控件不存在
Asp.net 运行时,报控件不存在,但系统中确实加入了控件z, 但是生成网站的时候,报控件不存在,输入代码的时候,this.edtxx.Text 确实可以输入 原因: 系统修改的时候,作了一个备份, ...
- Excel与SqlServer的导入导出问题总结
1.Excel导入到SqlServer中,如果Excel里面的某一列,即有文本,又有数字,导入SqlServer中这一列的类型将会是float,Excel里面对应的文本值将导不进来,为null. 解决 ...
- OO之观察者模式
以下为观察者模式详解: 引子: 假设有这样一个问题,有一条河经过一个山谷,山谷下有一个村庄,人们在山谷处修建了一个水库,并安排专人管理,当水库的水位过高时要通知下游居民注意水库的开闸放水,当水库的水温 ...