hdu 6165

虽然题解上说缩点然后判断入度就可以了,然后比赛的时候瞎暴力过了。

#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#define N 1010
#define LL __int64
#define inf 0x3f3f3f3f
#define lson l,mid,ans<<1
#define rson mid+1,r,ans<<1|1
#define getMid (l+r)>>1
#define movel ans<<1
#define mover ans<<1|1
using namespace std;
const LL mod = 1000000007;
int n, m;
bool flag[N][N];
int cnt;
vector<int> mapp[N];
bool vis[N];
void dfs(int u) {
    for (int i = 0; i < mapp[u].size(); i++) {
        int v = mapp[u][i];
        if (!vis[v]) {
            flag[cnt][v] = true;
            flag[v][cnt] = true;
            vis[v] = true;
            dfs(v);
        }
    }
}
void solve(int u) {
    memset(vis, false, sizeof(vis));
    vis[u] = true;
    cnt = u;
    dfs(u);
    flag[u][u] = 1;
}
void init() {
    for (int i = 0; i <= n; i++) {
        mapp[i].clear();
    }
    memset(flag, false, sizeof(flag));
}
int main() {
    cin.sync_with_stdio(false);
    int T;
    int a, b;
    cin >> T;
    while (T--) {
        cin >> n >> m;
        init();
        for (int i = 0; i < m; i++) {
            cin >> a >> b;
            mapp[a].push_back(b);
        }
        for (int i = 1; i <= n; i++) {
            solve(i);
        }
        cnt = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (flag[i][j] == false) {
                    cnt = 1;
                }
            }
        }
        if (!cnt) {
            cout << "I love you my love and our love save us!" << endl;
        }
        else {
            cout << "Light my fire!" << endl;
        }
    }
    return 0;
}

 

posted @ 2017-08-23 09:17  猪突猛进!!!  阅读(149)  评论(0编辑  收藏  举报