【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

找到任意一个环。
然后枚举删掉其中的某一条边即可。
(因为肯定要删掉这个环的,那么方法自然就是删掉其中的某一条边
(其它环,如果都包括这条边,那么就可以,否则,某个环不包括那也没办法,自然就无解了。
这样枚举的边的数目最多是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的更多相关文章

  1. 【Educational Codeforces Round 36 C】 Permute Digits

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] //从大到小枚举第i(1..len1)位 //剩余的数字从小到大排序. //看看组成的数字是不是小于等于b //如果是的话. //说 ...

  2. 【Educational Codeforces Round 36 B】Browser

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 分类在区间里面和左边.右边三种情况. 看看l的左边有没有标签.r的右边有没有标签. 就能做完了. [代码] #include < ...

  3. 【Educational Codeforces Round 36 A】 Garden

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举用哪一个桶就好 [代码] #include <bits/stdc++.h> using namespace std; ...

  4. 【Educational Codeforces Round 37 F】SUM and REPLACE

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 那个D函数它的下降速度是很快的. 也就是说到最后他会很快的变成2或者1 而D(2)==2,D(1)=1 也就是说,几次操作过后很多数 ...

  5. 【Educational Codeforces Round 37 E】Connected Components?

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] bfs. 用一个链表来记录哪些点已经确定在某一个联通快里了. 一开始每个点都能用. 然后从第一个点开始进行bfs. 然后对于它的所有 ...

  6. 【Educational Codeforces Round 37 C】 Swap Adjacent Elements

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然l..r这一段连续的1可以把l..r+1变成有序的. 那么就把所有的连续1段变成有序的就好. 看看最后是不是升序即可. [代码] ...

  7. 【Educational Codeforces Round 37 B】 Tea Queue

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用一个队列来模拟排队就好. 队列放三元组(x,y,z) x表示人的下标,y和z分别表示进入和退出时间. 然后枚举时间从1到5000 ...

  8. 【Educational Codeforces Round 37 A】 Water The Garden

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 记录下水龙头在哪些位置. 然后每秒钟把index-i和index+i改变状态一下就好(置1 [代码] #include <bi ...

  9. 【Educational Codeforces Round 35 D】Inversion Counting

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 排列中交换任意两个数字. 排列的逆序对个数的奇偶性会发生变化. 翻转这个过程其实就是len/2对数字发生交换. 交换了偶数次的话,不 ...

随机推荐

  1. laravel5.0 自定义服务类

    一.创建加密服务类 在 app\services 目录下创建 Encrypt.php <?php namespace App\Services; class Encrypt { } 二.注册服务 ...

  2. php修改限制上传文件大小

    win下:     1.编辑 php.ini:修改在 php5 下文件大小的限制     找到:file_uploads=On  允许 HTTP 文件上传     找到:max_execution_t ...

  3. COGS——T 8. 备用交换机

    http://www.cogs.pro/cogs/problem/problem.php?pid=8 ★★   输入文件:gd.in   输出文件:gd.out   简单对比时间限制:1 s   内存 ...

  4. CKEditor高级编辑器

    是否感觉后台分类描写叙述信息.商品描写叙述信息以及文章描写叙述信息 编写时很的不方便?有时候会将word的格式也复制过来了?那这个插件就比較适合了. 本插件使用CKEditor最新版本号,复制过来的内 ...

  5. centos7 ssh免口令认证登录

    摘要:centos7, xshell, 公钥,  ssh ssh登录方式有口令认证登录和密钥认证登录 接下来本次介绍是ssh密钥登录方式 (1)产生公钥 (2)将公钥放置到centos7的(/root ...

  6. POJ - 3842 An Industrial Spy dfs(水)

    题意:给你一串数字,最少一个,最多七个,问用这里面的数字能组成多少素数,不重复. 思路:之前还遍历10000000的每一个素数,结果超时,后来发现直接dfs就可以了,只是标记一下做过的数. #prag ...

  7. 开启Windows 7远程桌面功能的做法

    作者:朱金灿 来源:http://blog.csdn.net/clever101 本设置方法同样适用用Vista和Windows Server 2008. 1.依次点击"开始"菜单 ...

  8. 打印机共享为什么老是出现“操作无法完成(错误 0X00000709)。再次检查打印机名称、并确保打印机连接网络

    这个情况应该是访问IP连接打印机才会出现的.解决办法:不使用IP访问,使用网上邻居找计算机名称再连接打印机即可. ------------------------------------------- ...

  9. C/C++(C++类型增强)

    C++类型增强 类型检查更严格 把一个const类型的指针赋给非const类型的指针.c语言中可以通的过,但是在c++中则编不过去 const int a = 10; a = 100;//const修 ...

  10. React开发实时聊天招聘工具 -第二章

    2-1 介绍React开发环境 npm install -g create-react-app xxx npm run eject   来配置webpack 2-2 ES6常用语法 其他 还有一些特性 ...