HDU6165 FFF at Valentine(爆搜)

来源:互联网 发布:share.js用法 编辑:程序博客网 时间:2024/06/02 00:56

FFF at Valentine

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 425    Accepted Submission(s): 212


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
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
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!
没想到爆搜都能A
#include<bits/stdc++.h>#define mem(a,b) memset(a,b,sizeof(a))using namespace std;const int N=1e3+10;const int M=6e3+10;int n,m;bool vis[N],e[N][N];vector<int>v[N];void dfs(int x,int fa){    vis[x]=true;    e[fa][x]=true;    for(int i=0;i<v[x].size();i++)    {        if(vis[v[x][i]])continue;        dfs(v[x][i],fa);    }}int main(){    int t,x,y;    scanf("%d",&t);    while(t--)    {        scanf("%d%d",&n,&m);        for(int i=1;i<=n;i++)        {            v[i].clear();            for(int j=1;j<=n;j++)            e[i][j]=false;        }        for(int i=0; i<m; i++)        {            scanf("%d%d",&x,&y);            v[x].push_back(y);        }        for(int i=1;i<=n;i++)        {            mem(vis,false);            dfs(i,i);        }        bool flag=true;       for(int i=1;i<=n;i++)       {           for(int j=i+1;j<=n;j++)           {               if(e[i][j]==false&&e[j][i]==false)               {                   flag=false;                   break;               }           }       }       if(flag)        printf("I love you my love and our love save us!\n");       else        printf("Light my fire!\n");    }    return 0;}


 
原创粉丝点击