【題解】ZeroJudge b298: 老闆阿我要退貨

【題目敘述】https://zerojudge.tw/ShowProblem?problemid=b298

#include <iostream>
#include <queue>
#include <vector>
#include <cstring>
using namespace std;
vector <int> v[10005];
int a[10005];
queue <int> q;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m, l, Q, b, c;
    while (cin >> n >> m >> l >> Q){
        memset(a, 0, sizeof(a));
        for (int i = 1; i <= n; i++){
            v[i].clear();
        }
        for (int i = 0; i < m; i++){
            cin >> b >> c;
            v[b].push_back(c);
        }
        for (int i = 0; i < l; i++){
            cin >> b;
            a[b] = -1;
            q.push(b);
        }
        while (!q.empty()){
            b = q.front();
            q.pop();
            for (int i:v[b]){
                if (a[i] == 0){
                    a[i] = -1;
                    q.push(i);
                }
            }
        }
        for (int i = 0; i < Q; i++){
            cin >> b;
            if (a[b] == 0) cout << "YA~~\n";
            else cout << "TUIHUOOOOOO\n";
        }
    }
}
分享本文 Share with friends