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

∙∙Input starts with an integer T (T≤120), denoting the number of test cases. 

∙∙For each case, 

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!”

Sample Input

3
5 5
1 2
2 3
2 4
3 5
4 5 3 3
1 2
2 3
3 1 5 5
1 2
2 3
3 1
3 4
4 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!

题意:给一个有向图,就是判断任意两点是否可以连通(a, b只要a可以到b 或者b到a就可以)

题解:BFS+搜素优化。其实在比赛时我就是XJB写了个BFS+优化暴力,没想到过了,Orz.

#include<bits/stdc++.h>
using namespace std;
vector<int> v[1010];
int Flag[1010][1010],vis[1010];
int ans;
void bfs(int st)
{
queue<int> q;
while(!q.empty())
q.pop();
q.push(st);
memset(vis,0,sizeof vis);
vis[st] = 1;
while(!q.empty())
{
int u = q.front();q.pop();
for(int i = 0; i < v[u].size(); i++)
{
if(!vis[v[u][i]])
{
vis[v[u][i]] = 1;
q.push(v[u][i]);
if(Flag[st][v[u][i]] == 0)
{
Flag[st][v[u][i]] = Flag[v[u][i]][st] = 1;
ans++;
}
}
}
}
} void Init()
{
for(int i=0;i<1010;i++) v[i].clear();
memset(Flag,0,sizeof Flag);
ans=0;
} int main()
{
int T,n,m;
scanf("%d",&T);
while(T--)
{
Init();
scanf("%d%d",&n,&m);
while(m--)
{
int x,y;
scanf("%d%d",&x,&y);
v[x].push_back(y);
}
for(int i = 1; i <= n; i++)
bfs(i);
if(ans == n*(n-1)/2) printf("I love you my love and our love save us!\n");
else printf("Light my fire!\n");
}
return 0;
}

(全国多校重现赛一)E-FFF at Valentine的更多相关文章

  1. (全国多校重现赛一)F-Senior Pan

    Senior Pan fails in his discrete math exam again. So he asks Master ZKC to give him graph theory pro ...

  2. (全国多校重现赛一)D Dying light

    LsF is visiting a local amusement park with his friends, and a mirror room successfully attracts his ...

  3. (全国多校重现赛一) J-Two strings

    Giving two strings and you should judge if they are matched.  The first string contains lowercase le ...

  4. (全国多校重现赛一) H Numbers

    zk has n numbers a1,a2,...,ana1,a2,...,an. For each (i,j) satisfying 1≤i<j≤n, zk generates a new ...

  5. (全国多校重现赛一)B-Ch's gifts

    Mr. Cui is working off-campus and he misses his girl friend very much. After a whole night tossing a ...

  6. (全国多校重现赛一)A-Big Binary Tree

    You are given a complete binary tree with n nodes. The root node is numbered 1, and node x's father ...

  7. 2016ACM/ICPC亚洲区沈阳站-重现赛赛题

    今天做的沈阳站重现赛,自己还是太水,只做出两道签到题,另外两道看懂题意了,但是也没能做出来. 1. Thickest Burger Time Limit: 2000/1000 MS (Java/Oth ...

  8. 2016 CCPC 东北地区重现赛

    1. 2016 CCPC 东北地区重现赛 2.总结:弱渣,只做出01.03.05水题 08   HDU5929 Basic Data Structure    模拟,双端队列 1.题意:模拟一个栈的操 ...

  9. 2016 CCPC长春重现赛

    1.2016中国大学生程序设计竞赛(长春)-重现赛 2.总结:会做的太少,应变能力也不行,或者说猜题目的能力不行 02  水 04  HDU 5914  Triangle 1.题意:1~n,n个数,问 ...

随机推荐

  1. [综合] ISE的综合结果

    1.count2 == 7‘d12,会被综合成下面这个样子, 7‘d12就是左边下面这根绿线,等于符号在中间的圆圈里. 2.什么线都不点的时候,也就什么也没被选中, 而一旦我点击了某根线,却发现图里到 ...

  2. 前后端分离,我怎么就选择了 Spring Boot + Vue 技术栈?

    前两天又有小伙伴私信松哥,问题还是职业规划,Java 技术栈路线这种,实际上对于这一类问题我经常不太敢回答,每个人的情况都不太一样,而小伙伴也很少详细介绍自己的情况,大都是一两句话就把问题抛出来了,啥 ...

  3. thinkphp6.0 开启调试模式以及Driver [Think] not supported

    thinkphp6.0 开启调试模式 首先确认自己是通过 composer 进行的下载,然后修改系统目录下的 .example.env 为 .env 文件 修改 config->app.php ...

  4. nyoj 48-小明的调查作业(set)

    48-小明的调查作业 内存限制:64MB 时间限制:1000ms Special Judge: No accepted:15 submit:29 题目描述: 小明的老师布置了一份调查作业,小明想在学校 ...

  5. ES6入门一:ES6简介及Babel转码器

    ES6简介 Babel转码器 Nodejs中使用ES6 WebPack中使用ES6及Babel转码插件 一.ES6简介与转码  1.1一个常见的问题,ECMAScript和JavaScript到底是什 ...

  6. scipy.sparse的csc_matrix、csr_matrix与coo_matrix区别与应用(思维导图)

  7. 神奇的 SQL 之 MySQL 性能分析神器 → EXPLAIN,SQL 起飞的基石!

    前言 开心一刻 某人养了一头猪,烦了想放生,可是猪认识回家的路,放生几次它都自己回来了.一日,这个人想了个狠办法,开车带着猪转了好多路进山区放生,放生后又各种打转,然后掏出电话给家里人打了个电话,问道 ...

  8. 使用python脚本执行地理处理工具

    桌面ArcGIS包含800多种可在Python脚本中运行的地理处理工具. 通过Python脚本来运行地理处理工具,可以处理复杂的工作和执行批处理任务. 案例一:使用脚本执行地理处理工具(以裁剪为例) ...

  9. SpringSecurity环境下配置CORS跨站资源共享规则

    一.CORS简述 要说明CORS(Cross Origin Resourse-Sharing) 跨站资源共享,就必须先说同源策略.长话短说,同源策略就是向服务端发起请求的时候,以下三项必须与当前浏览器 ...

  10. Linux下用Docker部署接口安全的运行环境

    背景:MySQL数据库运行在宿主机上(Linux) 需求:Redis.服务.页面分别运行在独立的docker中,并处于同一网络,容器内部重要目录要挂载在物理目录,保证数据安全 方法: 一.设置网络环境 ...