【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对数字发生交换. 交换了偶数次的话,不 ...
随机推荐
- CSU 1510 Happy Robot
1510: Happy Robot Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 19 Solved: 7 Description Input The ...
- 洛谷 P3419 [POI2005]SAM-Toy Cars
P3419 [POI2005]SAM-Toy Cars 题目描述 Johnny is a little boy - he is only three years old and enjoys play ...
- C++里面关于虚函数的一些注意点
最后,总结一下关于虚函数的一些常见问题: 1) 虚函数是动态绑定的,也就是说,使用虚函数的指针和引用能够正确找到实际类的对应函数,而不是执行定义类的函数.这是虚函数的基本功能,就不再解释了. 2) 构 ...
- [Python] Normalize the data with Pandas
import os import pandas as pd import matplotlib.pyplot as plt def test_run(): start_date='2017-01-01 ...
- 【AHOI2013】【BZOJ3238】差异
Description Input 一行,一个字符串S Output 一行.一个整数.表示所求值 Sample Input cacao Sample Output 54 HINT 2<=N< ...
- POJ 1152 An Easy Problem! (取模运算性质)
题目链接:POJ 1152 An Easy Problem! 题意:求一个N进制的数R.保证R能被(N-1)整除时最小的N. 第一反应是暴力.N的大小0到62.发现当中将N进制话成10进制时,数据会溢 ...
- Git的日常处理流程
前提 本地有2个分支,一个是master,还有一个是local master 默认追踪origin/master local 通过git branch -u origin/master来映射 开发的时 ...
- 理解Linq查询
using System; using System.Linq; static class Program { static double Square(double n) { Console.Wri ...
- Android TextureView简易教程
如果你想显示一段在线视频或者任意的数据流比如视频或者OpenGL 场景,你可以用android中的TextureView做到. TextureView的兄弟SurfaceView 应用程序的视频或者o ...
- BZOJ 1598 第k短路
思路: 先反向建图 Dijkstra一遍 求出h数组 再正向建图 A_star一遍 搞定 //By SiriusRen #include <queue> #include <cstd ...