【Educational Codeforces Round 36 D】 Almost Acyclic Graph
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
找到任意一个环。
然后枚举删掉其中的某一条边即可。
(因为肯定要删掉这个环的,那么方法自然就是删掉其中的某一条边
(其它环,如果都包括这条边,那么就可以,否则,某个环不包括那也没办法,自然就无解了。
这样枚举的边的数目最多是500(环最多N条边)
然后复杂度就是500*10万了。
足够过了
【代码】
/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
8.whatch out the detail input require
*/
/*
一定在这里写完思路再敲代码!!!
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 5e2;
int n,m;
vector <int> g[N+10],path;
int bo[N+10];
bool dfs1(int x){
bo[x] = 1;
for (int y:g[x]){
if (bo[y]==0 && dfs1(y)){
path.push_back(x);
return true;
}
else
if (bo[y]==1) {
path.push_back(y);
path.push_back(x);
return true;
}
}
bo[x] = 2;
return false;
}
bool dfs2(int x,int a,int b){
bo[x] = 1;
for (int y:g[x]){
if (x==a && y==b) continue;
if (bo[y]==0 && dfs2(y,a,b)) return true;
else
if (bo[y]==1) return true;
}
bo[x] = 2;
return false;
}
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
cin >> n >> m;
for (int i = 1;i <= m;i++){
int x,y;
cin >> x >> y;
g[x].push_back(y);
}
bool loop1 = false;
for (int i = 1;i <= n;i++)
if (bo[i]==0 && dfs1(i)){
loop1 = true;
break;
}
if (!loop1) return cout<<"YES"<<endl,0;
reverse(path.begin(),path.end());
for (int i = 0;i <(int) path.size()-1;i++){
int x = path[i],y = path[i+1];
loop1 = false;
memset(bo,0,sizeof bo);
for (int j = 1;j <= n;j++)
if (bo[j]==0 && dfs2(j,x,y)){
loop1 = true;
break;
}
if (!loop1) return cout <<"YES"<<endl,0;
}
cout <<"NO"<<endl;
return 0;
}
【Educational Codeforces Round 36 D】 Almost Acyclic Graph的更多相关文章
- 【Educational Codeforces Round 36 C】 Permute Digits
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] //从大到小枚举第i(1..len1)位 //剩余的数字从小到大排序. //看看组成的数字是不是小于等于b //如果是的话. //说 ...
- 【Educational Codeforces Round 36 B】Browser
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 分类在区间里面和左边.右边三种情况. 看看l的左边有没有标签.r的右边有没有标签. 就能做完了. [代码] #include < ...
- 【Educational Codeforces Round 36 A】 Garden
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举用哪一个桶就好 [代码] #include <bits/stdc++.h> using namespace std; ...
- 【Educational Codeforces Round 37 F】SUM and REPLACE
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 那个D函数它的下降速度是很快的. 也就是说到最后他会很快的变成2或者1 而D(2)==2,D(1)=1 也就是说,几次操作过后很多数 ...
- 【Educational Codeforces Round 37 E】Connected Components?
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] bfs. 用一个链表来记录哪些点已经确定在某一个联通快里了. 一开始每个点都能用. 然后从第一个点开始进行bfs. 然后对于它的所有 ...
- 【Educational Codeforces Round 37 C】 Swap Adjacent Elements
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然l..r这一段连续的1可以把l..r+1变成有序的. 那么就把所有的连续1段变成有序的就好. 看看最后是不是升序即可. [代码] ...
- 【Educational Codeforces Round 37 B】 Tea Queue
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用一个队列来模拟排队就好. 队列放三元组(x,y,z) x表示人的下标,y和z分别表示进入和退出时间. 然后枚举时间从1到5000 ...
- 【Educational Codeforces Round 37 A】 Water The Garden
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 记录下水龙头在哪些位置. 然后每秒钟把index-i和index+i改变状态一下就好(置1 [代码] #include <bi ...
- 【Educational Codeforces Round 35 D】Inversion Counting
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 排列中交换任意两个数字. 排列的逆序对个数的奇偶性会发生变化. 翻转这个过程其实就是len/2对数字发生交换. 交换了偶数次的话,不 ...
随机推荐
- NodeJS学习笔记 (20)错误处理-error
文章地址 https://github.com/chyingp/nodejs-learning-guide
- P3514 [POI2011]LIZ-Lollipop(规律+瞎搞)
题意 给一个只有1和2的序列,每次询问有没有一个子串的和为x ( 1≤n,m≤1 000 000 )kkk ( 1≤k≤2 000 000 ) 题解 我觉得是道好题. 主要是证明一个性质:假如有一个字 ...
- [洛谷P1726][codevs1332]上白泽慧音
题目大意:求一个有向图的最大强连通分量中点的个数,并输出这些点(字典序最小). 解题思路:裸的强连通分量. 数据小,求完强连通分量后排序+vector大小比较即可(vector有小于运算符). C++ ...
- Linux 基础入门二
1.远程连接 ssh协议:secure shell ~]# ss -tnl 查看系统是否监听在tcp协议的22号接口: ~]# ip addr list 或者 ifconfig 查看ip地址 确 ...
- selenium的安装(2)
selenium的安装: 1):selenium的在线按:使用dom的cmd打开命令提示符窗口.然后敲上这个命令可以安装了==> 安装命令 pip install selenium 删除命令: ...
- [React] Make Controlled React Components with Control Props
Sometimes users of your component want to have more control over what the internal state is. In this ...
- awk技巧
1通过awk脚本执行awk程序:awk-f program_file_name input_files #!/bin/awk -f BEGIN { print "What is your n ...
- vue3事件
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- ASE加、解密
AES已经变成目前对称加密中最流行算法之一:AES可以使用128.192.和256位密钥,并且用128位分组加密和解密数据. /** * 加密 * * @param content 需要加密的内容 * ...
- BZOJ 3544 treap (set)
我只是想找个treap的练习题-- 每回找到lower_bound 就好啦 //By SiriusRen #include <cstdio> #include <cstring> ...