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 筑地市场是位于日本东京都中央区筑地的公营批发市场 ...
随机推荐
- hadoop filesystem 删除文件 复制文件 重命名文件
private void moveFile(Configuration conf, String Path1, String Path2, String newname ) throws IOExce ...
- Using jQuery to add a dynamic “Back To Top” floating button with smooth scroll
Ever read a really long blog post or article and then had to scroll all the way up to the top of the ...
- 《C和指针》 读书笔记 -- 第8章 数组
1.在C中,数组名的值是一个指针常量而不是指针变量,也就是数组第一个元素的地址. 2.数组和指针的区别: 声明一个数组时,编译器将根据声明所指定的元素数量为数组保留内存空间,然后再创建数组名,它的值是 ...
- 简易记事本(演示java文件io)
演示效果: 打开txt文件 输入文字,保存 选择保存地址 生成文件 源代码: package io; import java.io.*; import java.awt.*; import ja ...
- Unix/Linux中shell调用sqlplus的方式
Unix/Linux下,shell脚本调用sqlplus的几种方式介绍: 一.最简单的shell调用sqlplus #!/bin/bash sqlplus -S /nolog > sqlplus ...
- C#网络编程简单实现通信小例子-2
1.主界面 2.源代码 Client public partial class For ...
- ubuntu find方法
通用格式:find pathname -options [-print -exec -ok]例子:find / -name filename 再根目录里面搜索文件名为filename的文件find / ...
- go语言实现的目录共享程序
其实程序很小,只不过是想写点东西了.后天晚上要回学校考试了,转眼已经出来了69天了,2个月多一点.工资加上老妈赞助的钱,不知道能不能买台电脑,作为程序员一直用着i3-3217u实在难受.回去找同学拷点 ...
- EXTJS 资料 Ext.Ajax.request 获取返回数据
下面是一个登陆页面调用的EXTJS login function,通过 url: '/UI/HttpHandlerData/Login/Login.ashx',获取返回登陆账户和密码! Ext.onR ...
- win7 提升windows服务权限使非管理员用户可以控制windows服务的开启和关闭
#include <windows.h>#include <tchar.h>#include <strsafe.h>#include <aclapi.h> ...