又是一下午的杠题,累啊~~~

  这道题第一问很简单,只需去掉一个点,判断能不能到达终点就行了;

  第二问其实仔细想想也不难,就是判断去掉一个点后是否形成两个图;首先要知道是建立在第一问的基础上的;在加边的同时预处理一个e2的双向图,分别列举第一问的点,将从0到这个点所经过的点做标记;再将这点到终点遍历一遍,看是否遇到已标记过的点就行了。

  一个160行的代码,自己看吧...

#include <bits/stdc++.h>

using namespace std;

const int MAXN = 5e5 + 100;
inline int read()
{
int x = ,ff = ;char ch = getchar();
while(!isdigit(ch))
{
if(ch == '-') ff = -;
ch = getchar();
}
while(isdigit(ch))
{
x = (x<<) + (x<<) + (ch ^ );
ch = getchar();
}
return x * ff;
} inline void write(int x)
{
if(x < ) putchar('-'),x = -x;
if(x > ) write(x / );
putchar(x % + '');
} struct node
{
int y,next;
}e[MAXN],e2[MAXN << 1];
int a,tot = ,head,tail,lin[MAXN];
int tot2 = ,lin2[MAXN],vis2[MAXN];
int q[MAXN],vis[MAXN],dis[MAXN];
int f[MAXN],top = ,F[MAXN],tom = ; void add(int xx,int yy)
{
e[++tot].y = yy;
e[tot].next = lin[xx];
lin[xx] = tot;
} void add2(int xx,int yy)
{
e2[++tot2].y = yy;
e2[tot2].next = lin2[xx];
lin2[xx] = tot2;
} void Init()
{
int flag = ;
for(int i = ;;++i)
{
int x;
for(;;)
{
x = read();
if(x == -) break;
if(x == -)
{
flag = ;
break;
}
add(i,x);
add2(i,x);
add2(x,i);
}
if(flag == )
{
a = i - ;
break;
}
}
} void check(int m)
{
memset(vis,false,sizeof(vis));
vis[] = true; vis[m] = true;
head = ,tail = ;
q[] = ;
for(head = ;head <= tail;++head)
{
int x = q[head];
for(int i = lin[x],y;i;i = e[i].next)
{
if(!vis[y = e[i].y])
{
vis[y] = true;
q[++tail] = y;
}
}
}
} bool check2(int m)
{
memset(vis,false,sizeof(vis));
memset(vis2,false,sizeof(vis2));
vis[] = true; vis[m] = true;
head = ,tail = ;
q[] = ;
for(head = ;head <= tail;++head)
{
int x = q[head];
for(int i = lin2[x],y;i;i = e2[i].next)
{
if(!vis[y = e2[i].y])
{
vis[y] = true;
q[++tail] = y;
}
}
} head = ,tail = ;
q[] = m; vis2[m] = true; vis[m] = false;
for(head = ;head <= tail;++head)
{
int x = q[head];
for(int i = lin[x],y;i;i = e[i].next)
{
if(vis[y = e[i].y]) return false;
if(!vis2[y])
{
vis2[y] = true;
q[++tail] = y;
}
}
}
return true;
} int main()
{
Init();
for(int i = ;i < a;++i)
{
check(i);
if(!vis[a]) f[++top] = i;
}
write(top); putchar(' ');
for(int i = ;i <= top;++i)
{
write(f[i]);
putchar(' ');
}
putchar('\n');
for(int i = ;i <= top;++i)
{
if(check2(f[i])) F[++tom] = f[i];
}
write(tom); putchar(' ');
for(int i = ;i <= tom;++i)
{
write(F[i]);
putchar(' ');
}
return ;
}

  

P1211 街道赛跑的更多相关文章

  1. USACO Section 4

    前言 好久没更新这个系列了,最近闲的无聊写一下.有两题搜索懒得写了. P2737 [USACO4.1]麦香牛块Beef McNuggets https://www.luogu.com.cn/probl ...

  2. struts-hibernate-ajax完成区县和街道级联下拉框功能(二补充使用json解析list结果集,ajax循环json层级处理)

    针对<struts-hibernate-ajax完成区县和街道级联下拉框功能>进行补充,上一篇中,要在action中拼接JSON格式字符串,很容易手抖.直接用json处理一下转成json格 ...

  3. struts-hibernate-ajax完成区县和街道级联下拉框功能

    前言:这次dao用的是hibernate,控制层和显示层用的是struts,页面用的是ajax... 啰嗦:我做这个用了很久,用了2周,难点没破解的地方,hibernate的多对一关系生成实体类中属性 ...

  4. 数据分析 - 开放街道地图(OpenStreetMap)

    数据分析 - 开放街道地图(OpenStreetMap) Reinhard使用OpenStreetMap的开放地图数据作为本次数据分析的数据源,使用Python进行数据清洗,使用MongoDB进行数据 ...

  5. (转) C#多线程赛跑实例

    专于:http://blog.csdn.net/lidatgb/article/details/8363035 结合上篇<多线程的基础>,这次我们写一个多线程的赛跑实例,内容很简单:超人和 ...

  6. 洛谷P1211 [USACO1.3]牛式 Prime Cryptarithm

    P1211 [USACO1.3]牛式 Prime Cryptarithm 187通过 234提交 题目提供者该用户不存在 标签USACO 难度普及- 提交  讨论  题解 最新讨论 题面错误 题目描述 ...

  7. python 三级菜单 while循环三次,湖北省市-县-街道的选择,3个while的循环 -day2

    python编写一个三级while的循环菜单 1.定义字典,字典里面嵌套字典,内嵌字典的值为列表. 思路: 湖北省的市:字典中的定义3个字典,用于存储{序列-键:市名} shiqu_dir = {} ...

  8. Java多线程之赛跑游戏

    在JavaSE中,多线程是一个重要的内容. 我们要了解多线程的概念,就要先了解进程的概念:要了解进程的概念,就离不开操作系统的概念. 在一台正常运行的电脑中,计算机硬件(如CPU.内存.硬盘.网卡.显 ...

  9. C#编写街道管理系统

    项目需求: 一.语言和环境 A.实现语言 C# B.环境要求 Visual Studio 2012 二.功能要求 现使用.NET WinForms技术为居委会开发一个街道管理软件,其中街道管理窗体界面 ...

随机推荐

  1. leetcode第一刷_Best Time to Buy and Sell Stock III

    这道题还是挺难的,属于我前面提到的,给个数组,线性时间找出个什么东西,尽管上面的两个买卖股票也是这类.只是相比之下稚嫩多了.有关至少至多的问题比較烦人,不好想,等再做一些题,可能会发现什么规律.这道题 ...

  2. Intel graphics processing units

    http://en.wikipedia.org/wiki/Comparison_of_Intel_graphics_processing_units Comparison of Intel graph ...

  3. xcode编译 debug版或release 版

    编译debug版本或release 版本 在Run和Stop按钮的右边有一个工程名 点击工程名,选择Manage Schemes 选择Edit... 左侧选择Run ProjectName.app 右 ...

  4. 嵌入式开发之davinci---8148/8127/8168 中dsp c674的浮点和定点兼容

    c674: 是c67(浮点)+c64(定点) 兼容的 http://processors.wiki.ti.com/index.php/-mv_option_to_use_with_the_C674x ...

  5. [Android]Android5.0实现静默接听电话功能

    原因: android曾经能够通过AIDL进行静默接听.可是5.0以后就被谷歌给屏蔽了.这时候我们仅仅能通过其它方式实现了. 解决方式: try { Runtime.getRuntime().exec ...

  6. 【读书笔记】iOS-GCD-用法

    代码: -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { dispatch_async(dispatch_get_gl ...

  7. 文件管理中心iOS APP (国外市场:File Center) 技术支持

    文件管理中心iOS APP (国外市场:File Center) 技术支持网址:http://www.cnblogs.com/flychen/邮箱:592802944@qq.com

  8. 2017ACM/ICPC广西邀请赛 K- Query on A Tree trie树合并

    Query on A Tree Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Othe ...

  9. Codeforces Round #426 (Div. 2) D. The Bakery 线段树优化DP

    D. The Bakery   Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought req ...

  10. GET和POST解析

    Http定义了与服务器交互的不同方法,最基本的方法有4种,分别是GET,POST,PUT,DELETE.URL全称是资源描述符,我们可以这样认为:一个URL地址,它用于描述一个网络上的资源,而HTTP ...