Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <stack>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- while (cin) {
- int n, m;
- cin >> n >> m;
- vector<vector<int>> list_reversed(n, vector<int>());
- vector<int> reb_out_cnt(n, 0);
- vector<int> cur_cnt(n, 0);
- vector<int> ans(n, -1);
- for (int i = 0; i < m; i++) {
- int a, b;
- cin >> a >> b;
- --a;
- --b;
- reb_out_cnt[a]++;
- list_reversed[b].push_back(a);
- }
- stack<int> stack;
- for (int i = 0; i < n; i++) {
- if (reb_out_cnt[i] == 0) {
- ans[i] = 0;
- stack.push(i);
- }
- }
- while (!stack.empty()) {
- int v = stack.top();
- stack.pop();
- if (ans[v] == 0) {
- for (int i : list_reversed[v]) {
- ans[i] = 1;
- stack.push(i);
- }
- } else if (ans[v] == 1) {
- for (int i : list_reversed[v]) {
- cur_cnt[i]++;
- if (cur_cnt[i] == reb_out_cnt[i]) {
- ans[i] = 0;
- stack.push(i);
- }
- }
- }
- }
- for (int i : ans) {
- if (i == -1) {
- cout << "DRAW\n";
- } else if (i == 0) {
- cout << "SECOND\n";
- } else {
- cout << "FIRST\n";
- }
- }
- cout << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement