POJ 1172 DFS
(感谢wzc学长的幻灯片)
单组数据 注意从必经点能到标记过的点则此点不是分裂点。
//By: Sirius_Ren
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
int tot=1,first[51],cnt,v[101],nxt[101],n,vis[51],ansx=0,ansy=0,j,k;
queue<int> p,q,r;
void add(int x,int y){v[tot]=y,nxt[tot]=first[x],first[x]=tot++;}
int main()
{
memset(first,-1,sizeof(first));
for(cnt=0;~n;cnt++)
while(scanf("%d",&n)&&n>=0)add(cnt,n);
cnt--;
for(int i=1;i<cnt;i++){
memset(vis,0,sizeof(vis));
q.push(0);vis[i]=1;
while(!q.empty()){
int t=q.front();q.pop();
vis[t]=1;
for(int l=first[t];~l;l=nxt[l])
if(!vis[v[l]])q.push(v[l]);
}
if(!vis[cnt]){
ansx++,p.push(i);
for(j=0;j<=cnt;j++)
if(!vis[j]||j==i)
for(k=first[j];~k;k=nxt[k])
if(vis[v[k]]&&v[k]!=i)goto end;
ansy++,r.push(i);
end:;
}
}
printf("%d",ansx);
while(!p.empty())printf(" %d",p.front()),p.pop();
printf("\n");
printf("%d",ansy);
while(!r.empty())printf(" %d",r.front()),r.pop();
}
POJ 1172 DFS的更多相关文章
- POJ 1321 DFS
题意:POJ少见的中文题,福利啊. 思路: 一开始也没有思路呃呃呃 . 裸搜,连样例都过不去...参照了网上的题解:一行一行DFS 茅塞顿开啊. #include <cstdio> #in ...
- POJ 1979 dfs和bfs两种解法
fengyun@fengyun-server:~/learn/acm/poj$ cat 1979.cpp #include<cstdio> #include<iostream&g ...
- poj 1190 DFS 不等式放缩进行剪枝
F - (例题)不等式放缩 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Submi ...
- poj 1562 dfs
http://poj.org/problem?id=1562 #include<iostream> using namespace std; ,m=,sum=; ][]; ][]={-,, ...
- POJ 1979 DFS
题目链接:http://poj.org/problem?id=1979 #include<cstring> #include<iostream> using namespace ...
- poj 1088 (dfs+记忆化) 滑雪
题目;http://poj.org/problem?id=1088 感觉对深搜还不太熟练,所以练习一下,类似于连连看的那题,注意的是所求的是最大达长度,并不是从最大的或者最小的点出发得到的就是最长的路 ...
- Oil Deposits(poj 1526 DFS入门题)
http://poj.org/problem?id=1562 ...
- POJ 3414 dfs 回溯
题目链接:http://poj.org/problem?id=3414 题意:三个值A, B, C, A和B是两个杯子的容量,问最短操作数使A或者B里的水量是C.有三种操作. 思路:dfs.暴力 很简 ...
- poj 2531(dfs)
题目链接:http://poj.org/problem?id=2531 思路:由于N才20,可以dfs爆搞,枚举所有的情况,复杂度为2^(n). #include<iostream> #i ...
随机推荐
- Vova and Trophies CodeForces - 1082B(思维题)
Vova has won nn trophies in different competitions. Each trophy is either golden or silver. The trop ...
- Silverlight之我见——DataGrid数据验证
<UserControl x:Class="DataValidationSample.MainPage" xmlns="http://schemas.microso ...
- python运算符及优先级
计算机可以进行的运算有很多种,可不只加减乘除这么简单,运算按种类可分为算数运算.比较运算.逻辑运算.赋值运算.成员运算.身份运算.位运算. 一.算数运算 以下假设变量:a=10,b=20 二.比较运算 ...
- 8.1.1 Connection 对象
Connect是sqllite3模块中最基本的也是最重要的一个类,其主要方法如下表所示: 方法 说明 execute(sql[,parameters]) 执行一条SQL语句 executemany(s ...
- 【Codeforces 118B】Caesar's Legions
[链接] 我是链接,点我呀:) [题意] 序列中不能连续出现k1个以上的1以及不能连续出现k2个以上的2,然后一共有n1个1以及n2和2,要求这n1+n2个数字都出现. 问序列有多少种可能. [题解] ...
- 【codeforces 796D】Police Stations
[题目链接]:http://codeforces.com/contest/796/problem/D [题意] 在一棵树上,保证每个点在距离d之内都有一个警察局; 让你删掉最多的边,使得剩下的森林仍然 ...
- BUPT2017 springtraining(16) #4 ——基础数论
题目在这里 A.手动打表找规律得组合数 n -= 2, m -= 2, ans = C(n, m) #include <bits/stdc++.h> using namespace std ...
- Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method fail
SpringBoot 单元测试报错 @RunWith(SpringRunner.class) @SpringBootTest public class ProductCategoryRepositor ...
- MINSUB - Largest Submatrix
MINSUB - Largest Submatrix no tags You are given an matrix M (consisting of nonnegative integers) a ...
- 2.3. Configuring sudo Access-RedHat
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux_OpenStack_Platform/2/html/Get ...