제출 #366579

#제출 시각아이디문제언어결과실행 시간메모리
366579habohSleepy game (innopolis2018_final_D)C++14
100 / 100
126 ms10892 KiB
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

vector<int>g[100100];

bool dest[100100][2];
int p[100100][2];

bool used[100100];

void dfs(int v) {
    used[v] = true;
    for (int u:g[v]){
        if(used[u]) {
            cout << "Draw";
            exit(0);
        }
        dfs(u);
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    for (int v = 1; v <= n; v++) {
        int c;
        cin >> c;
        for (;c;c--) {
            int u;
            cin >> u;
            g[v].push_back(u);
        }
    }
    int s;
    cin >> s;
    dest[s][0] = true;
    queue<pair<int,int>>q;
    q.push({s,0});
    p[s][0] = -1;
    while(q.size()){
        int v = q.front().first;
        int odd = q.front().second;
        q.pop();
        for (int u : g[v]) {
            if(!dest[u][odd ^ 1]){
                dest[u][odd ^ 1] = true;
                p[u][odd ^ 1] = v;
                q.push({u, odd ^ 1});
            }
        }
    }
    
    for(int v=1;v<=n;v++){
        if(dest[v][1]==true && g[v].size() == 0) {
            cout << "Win\n";
            int odd = 1;
            vector<int>ans;
            while (v != -1) {
                ans.push_back(v);
                v = p[v][odd];
                odd ^= 1;
            }
            reverse(ans.begin(),ans.end());
            for (int x : ans) {
                cout << x << " ";
            }

            return 0;
        }
    }

    dfs(s);

    cout << "Lose";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...