#include <bits/stdc++.h>
using namespace std;
vector<int> g[500100];
int odw[500100];
int odwnum = 0;
bool ozn[500100];
bool bfs(int p)
{
++odwnum;
queue<int> qu;
qu.push(p);
odw[p] = odwnum;
while(!qu.empty())
{
auto t = qu.front();
qu.pop();
for(auto pp : g[t])
{
if(ozn[pp]) return true;
if(odw[pp] != odwnum)
{
odw[pp] = odwnum;
qu.push(pp);
}
}
}
return false;
}
int ans = 0;
int n, m, a, b;
void dp(int p = a + 1)
{
if(p > a + b)
{
for(int i = 1; i <= a; ++i)
{
if(!bfs(i)) return;
}
++ans;
return;
}
ozn[p] = 0;
dp(p + 1);
ozn[p] = 1;
dp(p + 1);
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> a >> b;
for(int i = 0; i < m; ++i)
{
int i1, i2;
char t[4];
cin >> i1 >> t >> i2;
if(t[1] == '-')
{
g[i1].push_back(i2);
g[i2].push_back(i1);
}
else
{
g[i1].push_back(i2);
}
}
dp();
cout << ans;
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 70 71 72 73 | #include <bits/stdc++.h> using namespace std; vector<int> g[500100]; int odw[500100]; int odwnum = 0; bool ozn[500100]; bool bfs(int p) { ++odwnum; queue<int> qu; qu.push(p); odw[p] = odwnum; while(!qu.empty()) { auto t = qu.front(); qu.pop(); for(auto pp : g[t]) { if(ozn[pp]) return true; if(odw[pp] != odwnum) { odw[pp] = odwnum; qu.push(pp); } } } return false; } int ans = 0; int n, m, a, b; void dp(int p = a + 1) { if(p > a + b) { for(int i = 1; i <= a; ++i) { if(!bfs(i)) return; } ++ans; return; } ozn[p] = 0; dp(p + 1); ozn[p] = 1; dp(p + 1); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> a >> b; for(int i = 0; i < m; ++i) { int i1, i2; char t[4]; cin >> i1 >> t >> i2; if(t[1] == '-') { g[i1].push_back(i2); g[i2].push_back(i1); } else { g[i1].push_back(i2); } } dp(); cout << ans; return 0; } |
English