#include <bits/stdc++.h>
#define fo(i,a,b) for(ll i=a;i<b;i++)
#define vc vector
#define us unordered_set
#define pb push_back
#define in(x) ll x;cin>>x;
//#define DEBUG
#ifdef DEBUG
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#else
#define dbg(x)
#endif
using namespace std;
using ll = long long;
const ll M = 1e9+7;
int main(){
in(n);
//in(m);
vc<us<ll>> g(n);
/*fo(i,0,m){
in(a);in(b);a--;b--;
#define ad(x,y) g[x].insert(y);
ad(a,b);ad(b,a);
}*/
fo(i,0,n){
in(de);
fo(j,0,de){
in(v);v--;
g[i].insert(v);
}
}
vc<ll> t(n);
vc<us<ll>> q(3);
fo(i,0,n){q[0].insert(i);}
#define set(v,tp) if(t[v]==0){dbg(v);dbg(tp);q[0].erase(v);ch=true;t[v] = tp;q[tp].insert(v);}
bool ch = false;
while(!q[0].empty()){
fo(i,0,3){dbg(i);dbg(q[i].size());}
ll x = *q[0].begin();
set(x,1);
while(ch){
ch = false;
for(ll v:q[1]){ for(ll u:g[v]){ set(u,2);}}
q[1].clear();
for(ll v:q[2]){ fo(u,0,n){ if(!g[v].count(u)){ set(u,1);}}}
q[2].clear();
}
}
fo(i,0,n){q[t[i]].insert(i);}//;cerr<<t[i]<<" ";}
//cerr<<endl;
vc<vc<us<ll>>> h(n,vc<us<ll>>(3));
fo(i,0,n){
for(ll v:g[i]){
#define adz(x,y) h[x][t[y]].insert(y);
adz(i,v);
adz(v,i);
}
}
bool ok = true;
for(ll v:q[1]){
if(!(h[v][1].size() == 0)){
ok = false;
}
}
for(ll v:q[2]){
if(!(h[v][2].size() == q[2].size()-1)){
ok = false;
}
}
if(!ok){
cout<<0<<endl;
return 0;
}
//cerr<<endl;
//fo(i,0,n){cerr<<"i: "<<g[i].size()<<endl;}
#define g errro
ll a1=0,b1=0,a2=0,b2=0;
for(ll v:q[1]){ if(h[v][2].size() == q[2].size()){ a1++;}}
for(ll v:q[2]){ if(h[v][1].size() == 0){ a2++;}}
for(ll v:q[1]){
if(h[v][2].size()==q[2].size()-1){
for(ll x:q[2]){
if(h[v][2].count(x)==0){
if(h[x][1].size()==0){b1++;}
}
}
}
}
for(ll v:q[2]){
if(h[v][1].size() == 1){
ll x = *h[v][1].begin();
if(h[x][2].size()==q[2].size()){b2++;}
}
}
//cerr<<c[1]<<endl;cerr<<c[2]<<endl;cerr<<c[3]<<endl;
//ll ans = (1*1+c[1]+c[2]+c[1]*c[3])%M;
ll ans = 1+a1+a2+b1+b2;
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
432 KB |
Output is correct |
2 |
Correct |
4 ms |
620 KB |
Output is correct |
3 |
Incorrect |
3 ms |
620 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
620 KB |
Output is correct |
2 |
Correct |
6 ms |
860 KB |
Output is correct |
3 |
Incorrect |
7 ms |
1132 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1132 KB |
Output is correct |
2 |
Correct |
27 ms |
2656 KB |
Output is correct |
3 |
Correct |
17 ms |
2656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
2656 KB |
Output is correct |
2 |
Correct |
39 ms |
4660 KB |
Output is correct |
3 |
Correct |
21 ms |
4660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
7132 KB |
Output is correct |
2 |
Incorrect |
748 ms |
62876 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
107 ms |
62876 KB |
Output is correct |
2 |
Correct |
1252 ms |
85600 KB |
Output is correct |
3 |
Execution timed out |
3036 ms |
132096 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
959 ms |
132096 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1602 ms |
132096 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3020 ms |
132096 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |