HDU6165 FFF at Valentine(深搜dfs,2017 HDU多校联赛 第9场)
来源:互联网 发布:c stl源码剖析 pdf 编辑:程序博客网 时间:2024/06/08 09:45
题目:
FFF at Valentine
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 456 Accepted Submission(s): 224
Problem Description
At Valentine's eve, Shylock and Lucar were enjoying their time as any other couples. Suddenly, LSH, Boss of FFF Group caught both of them, and locked them into two separate cells of the jail randomly. But as the saying goes: There is always a way out , the lovers made a bet with LSH: if either of them can reach the cell of the other one, then LSH has to let them go.
The jail is formed of several cells and each cell has some special portals connect to a specific cell. One can be transported to the connected cell by the portal, but be transported back is impossible. There will not be a portal connecting a cell and itself, and since the cost of a portal is pretty expensive, LSH would not tolerate the fact that two portals connect exactly the same two cells.
As an enthusiastic person of the FFF group, YOU are quit curious about whether the lovers can survive or not. So you get a map of the jail and decide to figure it out.
Input
First line is two number n and m, the total number of cells and portals in the jail.(2≤n≤1000,m≤6000)
Then next m lines each contains two integer u and v, which indicates a portal from u to v.
Output
If the couple can survive, print “I love you my love and our love save us!”
Otherwise, print “Light my fire!”
Otherwise, print “Light my fire!”
Sample Input
35 51 22 32 43 54 53 31 22 33 15 51 22 33 13 44 5
Sample Output
Light my fire!I love you my love and our love save us!I love you my love and our love save us!
Source
2017 Multi-University Training Contest - Team 9
思路:题目给了有向图n个点m条边,问任意两个点能否从一方到达另一方(从a到b或者从b到a都行),做法就是用vector存边暴搜。。
代码:
#include <cstdio>#include <cstring>#include <cctype>#include <string>#include <set>#include <iostream>#include <stack>#include <cmath>#include <queue>#include <vector>#include <algorithm>#define mem(a,b) memset(a,b,sizeof(a))#define inf 0x3f3f3f3f#define mod 1000007#define ll long longusing namespace std;const int N=1e3+5;vector<int>f[N];int vis[N],dis[N][N];int n,m,pos;void dfs(int u){vis[u]=1;dis[pos][u]=1;for(int i=0; i<f[u].size(); i++){int v=f[u][i];if(!vis[v])dfs(v);}}int main(){int t;scanf("%d",&t);while(t--){scanf("%d%d",&n,&m);for(int i=1; i<=n; i++)f[i].clear();int a,b;for(int i=1; i<=m; i++){scanf("%d%d",&a,&b);f[a].push_back(b);}mem(dis,0);int flag=1;for(int i=1; i<=n; i++){mem(vis,0);pos=i;dfs(i);}for(int i=1; i<=n; i++)for(int j=i+1; j<=n; j++)if(!dis[i][j]&&!dis[j][i]){flag=0;break;}if(flag)puts("I love you my love and our love save us!");elseputs("Light my fire!");}return 0;}
阅读全文
1 0
- HDU6165 FFF at Valentine(深搜dfs,2017 HDU多校联赛 第9场)
- HDU6165 FFF at Valentine(深搜dfs,2017 HDU多校联赛 第9场)
- hdu6165 FFF at Valentine 2017多校第九场1005 dfs
- HDU6165-FFF at Valentine
- HDU6165-FFF at Valentine
- HDU6165 FFF at Valentine【BFS】
- HDU6165 FFF at Valentine(爆搜)
- HDU --- 6165 FFF at Valentine 多校第九场 【强联通缩点 + 维护拓扑序】
- HDU 6165 FFF at Valentine(强连通 缩点 17多校第九场)
- FFF at Valentine HDU
- FFF at Valentine HDU
- HDU_6165 FFF at Valentine 【DFS】
- hdu6165-tarjan&&多校9&&模板修正|XJB暴力-FFF at Valentine
- hdu6165 FFF at Valentine【强联通缩点+拓扑排序】
- hdu6165 FFF at Valentine 强联通分量+拓扑排序
- hdu6165 FFF at Valentine 强联通缩点
- HDU-2017 多校训练赛9-1005-FFF at Valentine
- HDU 6165 FFF at Valentine
- html dom小案例
- 性能优化——异步加载js文件
- 冒泡排序
- 优先队列详解
- 搭建服务器环境编译源码
- HDU6165 FFF at Valentine(深搜dfs,2017 HDU多校联赛 第9场)
- HTTP 缓存机制详解
- SpringData 自动创建表设置配置
- java 高并发
- C语言(Head First C)-5_2:使用多个源文件:共享函数和共享变量
- Spring boot PUT、DELETE 请求无法定位方法及获取参数解决方案
- 2017 Multi-University Training Contest
- getDrawable过时的替代方法
- 台风眼(eye of storm) = 台风中心