#include <bits/stdc++.h>
using namespace std;
const int N=4e5+5;
int n,m,q,par[N],sz[N],l[N],st[N],en[N],now[N],nsz[N];
vector<int>adj[N],g[N],event[N];
set<int>node[N];
int Find(int u)
{
if(par[u]==u) return u;
return par[u]=Find(par[u]);
}
void Union(int u,int v,bool type)
{
u=Find(u);
v=Find(v);
if(u==v) return;
if(sz[u]<sz[v]) swap(u,v);
if(!type) g[u].push_back(v);
else for(auto&it:node[v]) node[u].insert(it);
par[v]=u;
sz[u]+=sz[v];
}
void dfs(int u)
{
static int nTime=0;
l[u]=++nTime;
for(auto &v: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)
{
n=_n;
m=X.size();
q=S.size();
vector<int>res(q,0);
iota(par,par+n,0);
fill(sz,sz+n,1);
for(int i=0;i<m;i++)
{
adj[X[i]].push_back(Y[i]);
adj[Y[i]].push_back(X[i]);
}
for(int i=0;i<q;i++) event[L[i]].push_back(i);
for(int i=n-1;i>=0;i--)
{
for(auto&e:adj[i]) if(e>i) Union(e,i,0);
for(auto&id:event[i])
{
int u=Find(S[id]);
now[id]=u;
nsz[id]=sz[u];
}
event[i].clear();
}
for(int i=0;i<n;i++)
{
if(par[i]==i)
{
dfs(i);
break;
}
}
for(int i=0;i<q;i++)
{
st[i]=l[now[i]];
en[i]=l[now[i]]+nsz[i]-1;
event[R[i]].push_back(i);
}
for(int i=0;i<n;i++) node[i].insert(l[i]);
iota(par,par+n,0);
fill(sz,sz+n,1);
for(int i=0;i<n;i++)
{
for(auto&j:adj[i]) if(j<i) Union(i,j,1);
for(auto&id:event[i])
{
int u=Find(E[id]);
auto it=node[u].lower_bound(st[id]);
if(it!=node[u].end()&&*(it)<=en[id]) res[id]=1;
}
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
47412 KB |
Output is correct |
2 |
Correct |
33 ms |
47404 KB |
Output is correct |
3 |
Correct |
35 ms |
47352 KB |
Output is correct |
4 |
Correct |
33 ms |
47352 KB |
Output is correct |
5 |
Correct |
34 ms |
47336 KB |
Output is correct |
6 |
Correct |
35 ms |
47360 KB |
Output is correct |
7 |
Correct |
32 ms |
47408 KB |
Output is correct |
8 |
Correct |
33 ms |
47360 KB |
Output is correct |
9 |
Correct |
33 ms |
47360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
47412 KB |
Output is correct |
2 |
Correct |
33 ms |
47404 KB |
Output is correct |
3 |
Correct |
35 ms |
47352 KB |
Output is correct |
4 |
Correct |
33 ms |
47352 KB |
Output is correct |
5 |
Correct |
34 ms |
47336 KB |
Output is correct |
6 |
Correct |
35 ms |
47360 KB |
Output is correct |
7 |
Correct |
32 ms |
47408 KB |
Output is correct |
8 |
Correct |
33 ms |
47360 KB |
Output is correct |
9 |
Correct |
33 ms |
47360 KB |
Output is correct |
10 |
Correct |
39 ms |
48256 KB |
Output is correct |
11 |
Correct |
40 ms |
48352 KB |
Output is correct |
12 |
Correct |
44 ms |
48632 KB |
Output is correct |
13 |
Correct |
39 ms |
48256 KB |
Output is correct |
14 |
Correct |
40 ms |
48120 KB |
Output is correct |
15 |
Correct |
41 ms |
48376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1060 ms |
151460 KB |
Output is correct |
2 |
Correct |
648 ms |
108912 KB |
Output is correct |
3 |
Correct |
692 ms |
114552 KB |
Output is correct |
4 |
Correct |
829 ms |
122680 KB |
Output is correct |
5 |
Correct |
841 ms |
124236 KB |
Output is correct |
6 |
Correct |
965 ms |
130584 KB |
Output is correct |
7 |
Correct |
990 ms |
151548 KB |
Output is correct |
8 |
Correct |
626 ms |
108868 KB |
Output is correct |
9 |
Correct |
651 ms |
113880 KB |
Output is correct |
10 |
Correct |
773 ms |
122488 KB |
Output is correct |
11 |
Correct |
688 ms |
123896 KB |
Output is correct |
12 |
Correct |
811 ms |
131524 KB |
Output is correct |
13 |
Correct |
630 ms |
107544 KB |
Output is correct |
14 |
Correct |
646 ms |
107372 KB |
Output is correct |
15 |
Correct |
647 ms |
107308 KB |
Output is correct |
16 |
Correct |
649 ms |
107408 KB |
Output is correct |
17 |
Correct |
956 ms |
150776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
47412 KB |
Output is correct |
2 |
Correct |
33 ms |
47404 KB |
Output is correct |
3 |
Correct |
35 ms |
47352 KB |
Output is correct |
4 |
Correct |
33 ms |
47352 KB |
Output is correct |
5 |
Correct |
34 ms |
47336 KB |
Output is correct |
6 |
Correct |
35 ms |
47360 KB |
Output is correct |
7 |
Correct |
32 ms |
47408 KB |
Output is correct |
8 |
Correct |
33 ms |
47360 KB |
Output is correct |
9 |
Correct |
33 ms |
47360 KB |
Output is correct |
10 |
Correct |
39 ms |
48256 KB |
Output is correct |
11 |
Correct |
40 ms |
48352 KB |
Output is correct |
12 |
Correct |
44 ms |
48632 KB |
Output is correct |
13 |
Correct |
39 ms |
48256 KB |
Output is correct |
14 |
Correct |
40 ms |
48120 KB |
Output is correct |
15 |
Correct |
41 ms |
48376 KB |
Output is correct |
16 |
Correct |
1060 ms |
151460 KB |
Output is correct |
17 |
Correct |
648 ms |
108912 KB |
Output is correct |
18 |
Correct |
692 ms |
114552 KB |
Output is correct |
19 |
Correct |
829 ms |
122680 KB |
Output is correct |
20 |
Correct |
841 ms |
124236 KB |
Output is correct |
21 |
Correct |
965 ms |
130584 KB |
Output is correct |
22 |
Correct |
990 ms |
151548 KB |
Output is correct |
23 |
Correct |
626 ms |
108868 KB |
Output is correct |
24 |
Correct |
651 ms |
113880 KB |
Output is correct |
25 |
Correct |
773 ms |
122488 KB |
Output is correct |
26 |
Correct |
688 ms |
123896 KB |
Output is correct |
27 |
Correct |
811 ms |
131524 KB |
Output is correct |
28 |
Correct |
630 ms |
107544 KB |
Output is correct |
29 |
Correct |
646 ms |
107372 KB |
Output is correct |
30 |
Correct |
647 ms |
107308 KB |
Output is correct |
31 |
Correct |
649 ms |
107408 KB |
Output is correct |
32 |
Correct |
956 ms |
150776 KB |
Output is correct |
33 |
Correct |
933 ms |
120568 KB |
Output is correct |
34 |
Correct |
404 ms |
83192 KB |
Output is correct |
35 |
Correct |
877 ms |
112504 KB |
Output is correct |
36 |
Correct |
934 ms |
124100 KB |
Output is correct |
37 |
Correct |
859 ms |
113392 KB |
Output is correct |
38 |
Correct |
934 ms |
120292 KB |
Output is correct |
39 |
Correct |
887 ms |
104520 KB |
Output is correct |
40 |
Correct |
908 ms |
119276 KB |
Output is correct |
41 |
Correct |
805 ms |
114320 KB |
Output is correct |
42 |
Correct |
855 ms |
122872 KB |
Output is correct |
43 |
Correct |
920 ms |
113520 KB |
Output is correct |
44 |
Correct |
829 ms |
113776 KB |
Output is correct |
45 |
Correct |
790 ms |
104312 KB |
Output is correct |
46 |
Correct |
734 ms |
104312 KB |
Output is correct |
47 |
Correct |
607 ms |
107628 KB |
Output is correct |
48 |
Correct |
609 ms |
107384 KB |
Output is correct |
49 |
Correct |
620 ms |
107628 KB |
Output is correct |
50 |
Correct |
587 ms |
107412 KB |
Output is correct |
51 |
Correct |
862 ms |
117632 KB |
Output is correct |
52 |
Correct |
854 ms |
117376 KB |
Output is correct |