hdu 6165 FFF at Valentine(传递闭包)
来源:互联网 发布:终极算法 txt 编辑:程序博客网 时间:2024/05/27 03:28
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6165
FFF at Valentine
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 682 Accepted Submission(s): 334
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
Recommend
liuyiding | We have carefully selected several similar problems for you: 6170 6169 6168 6167 6166
解析:
代码:
#include<bits/stdc++.h>using namespace std;typedef long long LL;const int N = 1000+9;const int INF = 0x3f3f3f3f;vector<int> mp[N];int g[N][N];int n, m;bool judge(){ for(int i = 1; i <= n; i++) { for(int j = i + 1; j <= n; j++) if(!(g[i][j] || g[j][i])) return false; } return true;}void bfs(int s){ queue<int> q; q.push(s); g[s][s] = 1; while(!q.empty()) { int u = q.front(); q.pop(); for(int i = 0; i < mp[u].size(); i++) { int v = mp[u][i]; if(!g[s][v]) q.push(v); g[s][v] = 1; } }}void solve(){ memset(g, 0, sizeof(g)); for(int i = 1; i <= n; i++) bfs(i);}int main(){ int t, u, v; scanf("%d", &t); while(t--) { scanf("%d%d", &n, &m); for(int i = 1; i <= n; i++) mp[i].clear(); while(m--) { scanf("%d%d", &u, &v); mp[u].push_back(v); } solve(); if(judge()) puts("I love you my love and our love save us!"); else puts("Light my fire!"); } return 0;}
阅读全文
0 0
- hdu 6165 FFF at Valentine(传递闭包)
- HDU 6165 FFF at Valentine
- HDU-6165 FFF at Valentine
- HDU 6165 FFF at Valentine
- HDU 6165 FFF at Valentine
- hdu--6165--FFF at Valentine
- HDU 6165 FFF at Valentine
- hdu 6165 FFF at Valentine
- hdu-6165 FFF at Valentine
- [HDU 6165]FFF at Valentine
- HDU-6165-FFF at Valentine
- FFF at Valentine HDU
- FFF at Valentine HDU
- hdu 6165 FFF at Valentine (Tarjan算法,scc+dp)
- HDU 6165 FFF at Valentine(强连通缩点)
- Hdu 6165 FFF at Valentine【Tarjan强连通+暴搜】
- hdu 6165 FFF at Valentine (数学思想 || 缩点)
- 【多校训练】hdu 6165 FFF at Valentine
- WEB服务器为什么取不到用户的MAC地址
- Hybris安装和各个Extention简单介绍
- 第二章 2.2归并排序
- MySQL下bin-log的三种模式(ROW、Statement、Mixed)
- python 使用eclipse编码运行出现SyntaxError: Non-UTF-8 code starting 解决方法
- hdu 6165 FFF at Valentine(传递闭包)
- Python基础入门1--基础语法
- Android模拟器打不开或者模拟器找不到
- 3G 脚本
- 一个学渣的成长
- springMVC记录(一)
- [USACO06NOV] 路障 Roadblocks(次短路)
- hust 1010 最小循环节
- D-BUS基础编程