# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
446536 | 2021-07-22T10:47:39 Z | MilosMilutinovic | Werewolf (IOI18_werewolf) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; #define pb push_back const int MX = 2e5 + 5; int n, m, q; vector<int> adj[MX]; bool was[MX][2]; void dfs1(int u, int l) { was[u][0] = true; for (int v : adj[u]) { if (!was[v][0] && v >= l) { dfs1(v, l); } } } void dfs2(int u, int r) { was[u][1] = true; for (int v : adj[u]) { if (!was[v][1] && v <= r) { dfs2(v, r); } } } void cl() { for (int i = 0; i < n; i++) { was[i][0] = false; was[i][1] = false; } } vector<int> check_validaty(int N, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R) { n = N; m = (int) X.size(); q = (int) L.size(); for (int i = 0; i < m; i++) { adj[X[i]].pb(Y[i]); adj[Y[i]].pb(X[i]); } if (n <= 3000 && m <= 6000 && q <= 3000) { vector<int> ans(q); for (int i = 0; i < q; i++) { cl(); dfs1(S[i], L[i]); dfs2(E[i], R[i]); for (int j = 0; j < n; j++) if (was[j][0] && was[j][1]) ans[i] = 1; } return ans; } vector<int> ans(1, -1); return ans; }