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. IDEA中WEB项目本地调试和发布的配置分开配置

    一个Web项目,开发的时候设置了一些本地内容,比如IP地址,还有本地目录等.开发完成后,要发布到服务器上时,这些本地相关的配置,就需要配置成服务器上IP或目录. 原先的做法就是部署打包的时候,把相关的 ...

  2. AngularJS: Error reports on $injector:modulerr

    Angular JS最常见的问题是,程序启动失败,error为$injector:modulerr 错误是因为加载对应的Module失败,但很难找到需要修改的Module. 一个简单的小技巧是,不要使 ...

  3. C#winfrom文件下载到本地

    string remoteUri = System.IO.Path.GetDirectoryName(url); string fileName = System.IO.Path.GetFileNam ...

  4. python:类4——魔法方法(定制序列、迭代)、生成器、推导式

    一.定制序列(容器类型) http://bbs.fishc.com/forum.php?mod=viewthread&tid=48793&extra=page%3D1%26filter ...

  5. 推荐算法之用矩阵分解做协调过滤——LFM模型

    隐语义模型(Latent factor model,以下简称LFM),是推荐系统领域上广泛使用的算法.它将矩阵分解应用于推荐算法推到了新的高度,在推荐算法历史上留下了光辉灿烂的一笔.本文将对 LFM ...

  6. js-程序结构

    程序结构: 1.顺序结构(主体结构):自上而下,逐行实行: 2.分支(选择)结构:if语句,if…else, if…else if…else,switch;     3.循环结构:重复某些代码: 分支 ...

  7. 部署k8s集群监控Heapster

    git clone https://github.com/kubernetes/heapster.gitkubectl apply -f heapster/deploy/kube-config/inf ...

  8. 扛把子组20191121-10 Scrum立会报告+燃尽图 06

    此作业的要求参见http://edu.cnblogs.com/campus/nenu/2019fall/homework/10070 一.小组情况: 队名:扛把子 组长:孙晓宇 组员:刘信鹏 韩昊 宋 ...

  9. Matlab生成Word--xdd

    摘自<MATLAB统计分析与应用:40个案例分析>(谢中华老师著)P452页function CreatWord %利用Matlab生成word filespec_user = [pwd ...

  10. word2vec:CBOW和skip-gram模型

    1.CBOW模型 之前已经解释过,无论是CBOW模型还是skip-gram模型,都是以Huffman树作为基础的.值得注意的是,Huffman树中非叶节点存储的中间向量的初始化值是零向量,而叶节点对应 ...