然後第二筆測資對 9ms 1.1MB
想法:向上游找,然後把下游都塗成有問題的
vector mp[10005]; int tag[10005]; bool flag = false; void dfs(int curr) { if (tag[curr]) { flag = true; return; } for (int e : mp[curr]) { dfs(e); } if (flag) { tag[curr] = 1; } } int main() { cin.tie(0); ios::sync_with_stdio(false); int N, M, L, Q; cin >> N >> M >> L >> Q; for (int i = 0; i < M; i++) { int a, b; cin >> a >> b; mp[b].push_back(a); } for (int i = 0; i < L; i++) { int x; cin >> x; tag[x] = 1; } for (int i = 0; i < Q; i++) { int y; cin >> y; flag = false; dfs(y); if (flag) { cout << "TUIHUOOOOOO"; } else { cout << "YA~~"; } cout << "\n"; } }