2017 Multi-University Training Contest - Team 9 E - FFF at Valentine
2017-08-22 18:12
726 查看
FFF at ValentineTime Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 86 Accepted Submission(s): 37 [align=left]Problem Description[/align] 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. [align=left]Input[/align] ∙ 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. [align=left]Output[/align] If the couple can survive, print “I love you my love and our love save us!” Otherwise, print “Light my fire!” [align=left]Sample Input[/align] 35 51 22 42 33 53 34 51 25 52 33 11 24 52 33 13 4 [align=left]Sample Output[/align] Light my fire!I love you my love and our love save us!I love you my love and our love save us! [align=left]Source[/align] 2017 Multi-University Training Contest - Team 9 [align=left]Recommend[/align] liuyiding | We have carefully selected several similar problems for you: 6170 6169 6168 6167 6166 题目大意:每组有n个点和m个边组成的有向图,现在让你判断这个图是否能够对于任意两个点来说,他们都能到达 解题思路:一开始比赛的时候把题读错了,然后就走进了度的死胡同了,这道题枚举每个点能够从他开始到达得点,然后暴力check任意两点是否能够到达 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <cmath> #include <cstdlib> #include <ctime> using namespace std; typedef long long LL; bool check[1005][1005],vis[1005]; vector<int> tu[1005]; int n,m,T; void dfs(int son,int fa) { int k; vis[son]=1; for(int i=0;i<tu[son].size();i++) { k=tu[son][i]; if(vis[k]==1) continue; dfs(k,son); } } int main() { cin>>T; while(T--) { int i,j,x,flag,y; cin>>n>>m; memset(tu,0,sizeof(tu)); memset(check,0,sizeof(check)); for(i=1;i<=m;i++) { cin>>x>>y; check[x][y]=1; tu[x].push_back(y); } for(i=1;i<=n;i++) { memset(vis,0,sizeof(vis)); vis[i]=1; dfs(i,0); for(j=1;j<=n;j++) { if(j!=i&&vis[j]==1) check[i][j]=1; } } flag=0; for(i=1;i<=n;i++) { for(j=i+1;j<=n;j++) { if(check[i][j]==0&&check[j][i]==0) { flag=1; break; } } } if(!flag) cout<<"I love you my love and our love save us!"<<endl; else cout<<"Light my fire!"<<endl; } return 0; } |
相关文章推荐
- 2017 Multi-University Training Contest - Team 9:FFF at Valentine
- 2017 Multi-University Training Contest - Team 9 1005&&HDU 6165 FFF at Valentine【强联通缩点+拓扑排序】
- HDU 6165 - FFF at Valentine DFS暴力 2017 Multi-University Training Contest - Team 9
- 【2017 Multi-University Training Contest - Team 9】FFF at Valentine
- HDU-6165 FFF at Valentine - 2017 Multi-University Training Contest - Team 9(强连通分量缩点+拓扑)
- 2017 Multi-University Training Contest - Team 9 1005 FFF at Valentine
- 2017 Multi-University Training Contest - Team 9
- 2017 Multi-University Training Contest - Team 1 1002 Balala Power!
- 2017 Multi-University Training Contest - Team 1 KazaQ's Socks
- hdu 6034 Balala Power!(贪心)( 2017 Multi-University Training Contest - Team 1 )(无耻之sort)
- 2017 Multi-University Training Contest - Team 1 - 1001
- hdu 6034 Balala Power! (2017 Multi-University Training Contest - Team 1)
- hdu 6047 Maximum Sequence(2017 Multi-University Training Contest - Team 2)
- hdu 6045 Is Derek lying?(2017 Multi-University Training Contest - Team 2)
- hdu 6053 TrickGCD [2017 Multi-University Training Contest - Team 2] [莫比乌斯函数]
- hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest - Team 2)
- 2017 Multi-University Training Contest - Team 2 1006
- 2017 Multi-University Training Contest - Team 3(补题系列)
- hdu 6058 Kanade's sum(链表)(2017 Multi-University Training Contest - Team 3 )
- hdoj 6033(2017 Multi-University Training Contest - Team 1) Add More Zero