Author : Dipu Kumar Mohanto
CSE, Batch - 6
BRUR.
Problem Statement : Keep Moving
Source : toph.co
Category : Game Theory
Algorithm : Decision Tree
Verdict : Accepted
- #include "bits/stdc++.h"
-
- using namespace std;
-
- #define sz(a) (int)a.size()
- #define eb emplace_back
-
- static const int maxn = 1e5 + 5;
-
- int tnode, tedge, x;
- vector <int> graph[maxn];
-
- int dp[maxn];
- bool memoize[maxn];
-
- inline bool dicisionTree(int cur)
- {
- if (sz(graph[cur]) == 0) return false;
- int &ret = dp[cur];
- bool &mem = memoize[cur];
- if (mem) return ret;
- mem = 1;
- for (int nxt : graph[cur])
- {
- if (dicisionTree(nxt) == false)
- {
- return ret = true;
- }
- }
- return ret = false;
- }
-
- int main()
- {
- int tc;
- cin >> tc;
- for (int tcase = 1; tcase <= tc; tcase++)
- {
- cin >> tnode >> tedge >> x;
- for (int i = 0; i < tedge; i++)
- {
- int u, v;
- cin >> u >> v;
- graph[u].eb(v);
- }
- memset(memoize, 0, sizeof memoize);
- if (dicisionTree(x)) cout << "Case " << tcase << ": Yes\n";
- else cout << "Case " << tcase << ": No\n";
- for (int i = 0; i < maxn; i++) graph[i].clear();
- }
- }
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.