This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "werewolf.h"
#include <vector>
#include <set>
using namespace std;
const int maxn = 2e5 + 5;
int pa[maxn], siz[maxn], query_size[maxn], tin[maxn], query_l[maxn], query_r[maxn], time = 0;
vector<int> g[maxn], dsu_g[maxn], e1[maxn], e2[maxn];
set<int> node[maxn];
int root(int u) { return u == pa[u] ? u : root(pa[u]); }
void merge(int u, int v, bool type)
{
u = root(u), v = root(v);
if (u == v) return;
if (siz[u] < siz[v]) swap(u, v);
pa[v] = u, siz[u] += siz[v];
if (!type) dsu_g[u].push_back(v);
else for (int i : node[v]) node[u].insert(i);
}
void dfs(int u)
{
tin[u] = time++;
for (int v : dsu_g[u]) dfs(v);
}
vector<int> check_validity(int n, vector<int> x, vector<int> y, vector<int> s, vector<int> e, vector<int> l, vector<int> r)
{
for (int i = 0; i < x.size(); i++) g[x[i]].push_back(y[i]), g[y[i]].push_back(x[i]);
int q = s.size();
vector<int> ans(q, 0);
for (int i = 0; i < q; i++) e1[l[i]].push_back(i), e2[r[i]].push_back(i);
for (int i = 0; i < n; i++) pa[i] = i, siz[i] = 1;
for (int i = n - 1; i >= 0; i--)
{
for (int j : g[i]) if (j > i) merge(i, j, false);
for (int j : e1[i])
{
query_l[j] = root(s[j]);
query_size[j] = siz[query_l[j]];
}
}
for (int i = 0; i < n; i++) if (pa[i] == i) dfs(i);
for (int i = 0; i < q; i++) query_l[i] = tin[query_l[i]], query_r[i] = query_l[i] + query_size[i] - 1;
for (int i = 0; i < n; i++) pa[i] = i, siz[i] = 1, node[i].insert(tin[i]);
for (int i = 0; i < n; i++)
{
for (int j : g[i]) if (j < i) merge(i, j, true);
for (int j : e2[i])
{
int u = root(e[j]);
auto it = node[u].lower_bound(query_l[j]);
if (it != node[u].end() && *it <= query_r[j]) ans[j] = true;
}
}
return ans;
}
Compilation message (stderr)
werewolf.cpp: In function 'std::vector<int> check_validity(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:27:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for (int i = 0; i < x.size(); i++) g[x[i]].push_back(y[i]), g[y[i]].push_back(x[i]);
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |