CodeForces 164A Variable, or There and Back Again(搜索)
来源:互联网 发布:笑声软件 编辑:程序博客网 时间:2024/06/07 01:06
题意:
给你n和m,表示有n个状态和m条单向边
快乐路径表示从1开始,2结束的路径,这个路径中间没有1就可以
问你这些状态哪些是快乐路径上的,哪些不是
思路:两次BFS
#include<bits/stdc++.h>using namespace std;const int maxn = 1e6+10;vector<int>e1[maxn];vector<int>e2[maxn];int vis1[maxn];int vis2[maxn];int a[maxn];queue<int>q;int main(){ int n,m;scanf("%d%d",&n,&m);for (int i = 1;i<=n;i++)scanf("%d",&a[i]);for (int i = 1;i<=m;i++){int u,v;scanf("%d%d",&u,&v);e1[u].push_back(v);e2[v].push_back(u);}for (int i = 1;i<=n;i++)if (a[i]==1){vis1[i]=1;q.push(i);}while (!q.empty()){int now = q.front();q.pop();for (int i = 0;i<e1[now].size();i++){int v = e1[now][i];if (a[v]==1)continue;if (vis1[v])continue;vis1[v]=1;q.push(v);}}while (!q.empty())q.pop();for (int i = 1;i<=n;i++) if (a[i]==2){vis2[i]=1;q.push(i);}while (!q.empty()){int now = q.front();q.pop();for (int i = 0;i<e2[now].size();i++){int v = e2[now][i];if (a[v]==1)vis2[v]=1;;if (vis2[v])continue;vis2[v]=1;q.push(v);}}for (int i = 1;i<=n;i++)if (vis1[i]&&vis2[i])printf("1\n");elseprintf("0\n");}
0 0
- CodeForces 164A Variable, or There and Back Again(搜索)
- Codeforces VK Cup 2012 Round 3 A. Variable, or There and Back Again(dfs)
- CVS错误:cvs commit: "..." should be removed and is still there (or is back again)
- Yandex 2013Q(Atoms: There and Back Again-贪心+模拟+List)
- White, Black and White Again )(CodeForces
- codeforces 788-A. Functions again(dp)
- CodeForces 668C Little Artem and Random Variable(数学)
- CodeForces 630 A. Again Twenty Five!(水~)
- Codeforces--630A--Again Twenty Five!(水题)
- CodeForces - 7A Kalevitch and Chess(搜索?!模拟!)
- 警告: Could not find action or result There is no Action mapped for namespace [/] and action name [] a
- HDU 1848 Fibonacci again and again && HDU 1851 A Simple Game (基础sg函数)
- Codeforces 377 A. Maze(搜索技巧)
- Codeforces 754A(搜索)
- POJ 3517 And Then There Was One(约瑟夫环-递推or模拟)
- Codeforces 630A Again Twenty Five!
- CodeForces - 630A Again Twenty Five! (水)
- Codeforces A. Again Twenty Five!【水】
- git diff
- Retrofit使用教程(二)
- mysql 查询的时候处理中文汉字按照字母排序问题
- android fragment生命周期应用
- Java动态代理
- CodeForces 164A Variable, or There and Back Again(搜索)
- 【OpenGL】Shader实例分析(二)- Heart
- 递归——LeetCode46. Permutation
- React.render和reactDom.render的区别
- webkit内核的图像绘制
- VS2010调用Opencv2.4.10中dll问题的解决
- Android:shape设置corners(圆角)不能正常显示问题
- opencv的canny函数检测边缘的效果和matlab的不同
- 【OpenGL】Shader实例分析(三)- 等待标识