(全国多校重现赛一)E-FFF at Valentine
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的更多相关文章
- (全国多校重现赛一)F-Senior Pan
Senior Pan fails in his discrete math exam again. So he asks Master ZKC to give him graph theory pro ...
- (全国多校重现赛一)D Dying light
LsF is visiting a local amusement park with his friends, and a mirror room successfully attracts his ...
- (全国多校重现赛一) J-Two strings
Giving two strings and you should judge if they are matched. The first string contains lowercase le ...
- (全国多校重现赛一) H Numbers
zk has n numbers a1,a2,...,ana1,a2,...,an. For each (i,j) satisfying 1≤i<j≤n, zk generates a new ...
- (全国多校重现赛一)B-Ch's gifts
Mr. Cui is working off-campus and he misses his girl friend very much. After a whole night tossing a ...
- (全国多校重现赛一)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 ...
- 2016ACM/ICPC亚洲区沈阳站-重现赛赛题
今天做的沈阳站重现赛,自己还是太水,只做出两道签到题,另外两道看懂题意了,但是也没能做出来. 1. Thickest Burger Time Limit: 2000/1000 MS (Java/Oth ...
- 2016 CCPC 东北地区重现赛
1. 2016 CCPC 东北地区重现赛 2.总结:弱渣,只做出01.03.05水题 08 HDU5929 Basic Data Structure 模拟,双端队列 1.题意:模拟一个栈的操 ...
- 2016 CCPC长春重现赛
1.2016中国大学生程序设计竞赛(长春)-重现赛 2.总结:会做的太少,应变能力也不行,或者说猜题目的能力不行 02 水 04 HDU 5914 Triangle 1.题意:1~n,n个数,问 ...
随机推荐
- Java传参-基本数据类型和引用数据类型作为参数的区别(值传递)
java中的方法可以传递参数,参数的传递方法就是值传递. 参数有形参和实参,定义方法时写的参数叫形参,真正调用方法时,传递的参数叫实参. 调用方法时,会把实参传递给形参,方法内部其实是在使用形参. 所 ...
- Apache安装问题:APR not found
资料来源:Apache遇到的问题:APR not found 安装apache时出现arp错误问题 按照以上文章试验之后整理如下: #./configure --prefix……检查编辑环境时出现: ...
- Java枚举——枚举的作用、使用方法、使用场景
枚举的定义 枚举关键字enum 枚举类是一种特殊类,它和普通类一样可以使用构造器.定义成员变量和方法,也可以实现多个接口,但不能继承类. 枚举的使用 enum Color { RED, BLUE, G ...
- 插入订单并且输出订单号的sql存储过程
--插入订单-- create proc InsertOrders ( @OrderNumber varchar(300), @OrderState varchar(30), @OrderType v ...
- [ch02-00] 反向传播与梯度下降的通俗解释
系列博客,原文在笔者所维护的github上:https://aka.ms/beginnerAI, 点击star加星不要吝啬,星越多笔者越努力. 第2章 神经网络中的三个基本概念 2.0 通俗地理解三大 ...
- 安装win7和ubuntu16.04双系统
硬件:2012年本子 话硕A55V Service 准备: 首先通过一键还原备份win7系统!不清楚某些失误会不会备份也不能拯救! 清出100g硬盘空间,ubuntu会安装在这里 查看当前win7启 ...
- Robot Framework自动化测试环境搭建
robotFramework是一个通用的自动化测试框架来进行验收测试和验收测试驱动开发模式,它具有易于使用的表格的测试数据和关键字测试驱动方法,其测试功能可通过实现与python或java的测试库进行 ...
- Video的自我学习
直播原理 视频协议 HLS协议 [主要是直播方面(好用,但延时)] HTTP Live Streaming(缩写是HLS)是一个由苹果公司提出的基于HTTP的流媒体网络传输协议. 是苹果公司Quic ...
- AE ArcEngine10.4+vs2012安装配置
准备内容 安装环境:win10*64位专业版,ArcGIS_Desktop_1041_151727,C#语言环境,visual studio2012 安装文件:ArcGIS_Engine_1041_1 ...
- 2019-9-16:渗透测试,基础学习,Linux下软件安装,环境搭建,笔记
Centos linux下软件安装yum 通过分析rpm包头数据后,自动解决依赖关系,直接云端下载软件,根据不同版本系统获取不同软件信息,按顺序下载rpm包,安装软件yum search 软件名:搜索 ...