#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, a, b, c, l, odp;
vector <int> v[500001];
queue <int> que;
int odw[500001];
int main()
{
scanf("%d%d%d%d", &n, &m, &x, &y);
for(int i=1; i<=m; ++i)
{
scanf("%d", &a);
getchar_unlocked();
getchar_unlocked();
c=getchar_unlocked();
scanf("%d", &b);
v[b].push_back(a);
if(c=='-')
{
v[a].push_back(b);
}
}
for(int i=0; i<(1<<y); ++i)
{
a=i;
b=x;
while(a)
{
++b;
if(a&1)
{
que.push(b);
}
a>>=1;
}
++l;
c=0;
while(!que.empty())
{
a=que.front();
que.pop();
if(odw[a]==l)
{
continue;
}
odw[a]=l;
if(a<=x)
{
++c;
}
for(int i:v[a])
{
if(odw[i]<l)
{
que.push(i);
}
}
}
if(c==x)
{
++odp;
}
}
printf("%d\n", odp);
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | #include <bits/stdc++.h> using namespace std; int n, m, x, y, a, b, c, l, odp; vector <int> v[500001]; queue <int> que; int odw[500001]; int main() { scanf("%d%d%d%d", &n, &m, &x, &y); for(int i=1; i<=m; ++i) { scanf("%d", &a); getchar_unlocked(); getchar_unlocked(); c=getchar_unlocked(); scanf("%d", &b); v[b].push_back(a); if(c=='-') { v[a].push_back(b); } } for(int i=0; i<(1<<y); ++i) { a=i; b=x; while(a) { ++b; if(a&1) { que.push(b); } a>>=1; } ++l; c=0; while(!que.empty()) { a=que.front(); que.pop(); if(odw[a]==l) { continue; } odw[a]=l; if(a<=x) { ++c; } for(int i:v[a]) { if(odw[i]<l) { que.push(i); } } } if(c==x) { ++odp; } } printf("%d\n", odp); return 0; } |
English