Title Description
Since the topic and people in a hurry so it can not be a story as background.
At first there were apples $ n $, $ m $ individuals turn to eat apples, the first $ i $ individuals will try to eat the $ u_i $ or $ v_i $ No. apple, specifically three cases.
$ \ bullet 1. $ are still two apples, then that person will pick an apple to eat.
$ \ bullet 2. $ only one apple, then that person will eat this apple.
$ \ bullet 3. $ not in, this person can not eat apples left.
I wonder how many of Apple's $ (i, j) (i <j) $ satisfy the probability that they both survived the $> 0 $.
Input Format
The first two row number $ n, m $.
Next $ m $ rows of two numbers $ u_i, v_i $.
Output Format
A number indicates the answer.
Sample
Sample input:
4 3
1 2
3 4
2 3
Sample output:
1
Data range and tips
Sample explained:
Only $ (1,4) $ satisfies the condition.
data range:
For the test point $ 1 \ sim 5 $: $ n, m \ leqslant 20 $.
For the test point $ 5 \ sim 8 $: If the apple seen as the point man seen as the side, it will form a tree.
For the test point $ 9 \ sim 15 $: $ m \ leqslant 400 $.
For the test point $ 16 \ sim 25 $: no special restrictions.
For all data, $ n \ leqslant 400, m \ leqslant 5 \ times 10 ^ 4 $.
answer
Consider a similar $ DP $ practices, the definition of $ f_k (S) $ $ k $ express after individual came, the probability of the set $ S $ whether Apple have not eaten, we can list the state transition equation:
$ \ Alpha.u_i, v_i \ in S, f_k (S) = 0 $, are certainly not in this collection, because the two can not co-apples survive.
$ \ Beta.u_i \ in S, f_k (S) = f_ {k-1} (S \ cup \ {u_i \}) $, comparable to the time it can have, but this time will not have.
$\gamma.v_i\in S,f_k(S)=f_{k-1}(S\cup\{v_i\})$,同上。
$ Delta.u_i, v_i \ notin S, f_k (S) = f_ {k-1} (S) $, if not in, certainly no problem.
But we finally may get a lot of collections, choose the smallest one?
Certainly not, then we consider the conversion of some ideas.
Against the push, then the state transition equation becomes:
$ \ Alpha. u_i, V_I \ in S $, not move up.
$\beta.u_i\in S,f_k(S\cup\{u_i\})=f_{k+1}(S)$。
$\gamma.v_i\in S,f_k(S\cup\{v_i\})=f_{k+1}()S$。
$delta.u_i,v_i\notin S,f_k(S)=f_{k+1}(S)$。
The initial value of $ f_m (i) = 1 $.
Time complexity: $ \ Theta (n \ times n + n ^ 2) $.
Expectations score: $ 100 $ points.
Actual score: $ 100 $ points.
Code time
#include<bits/stdc++.h>
using namespace std;
int n,m;
bool vis[401];
pair<int,int> e[50001];
bool bit[401][401];
int ans;
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
scanf("%d%d",&e[i].first,&e[i].second);
for(int i=1;i<=n;i++)
{
bit[i][i]=1;
for(int j=m;j;j--)
{
if(bit[i][e[j].first]&&bit[i][e[j].second])vis[i]=1;
if(bit[i][e[j].first]||bit[i][e[j].second])bit[i][e[j].first]=bit[i][e[j].second]=1;
}
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
for(int k=1;k<=n;k++)
if(vis[i]||vis[j]||bit[i][k]&&bit[j][k])goto nxt;
ans++;
nxt:;
}
printf("%d",ans>>1);
return 0;
}
rp++