AGC 016 E Poor Turkeys

Posted lyd729

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AGC 016 E Poor Turkeys相关的知识,希望对你有一定的参考价值。

Problem Statement

There are N turkeys. We number them from 1 through N.

M men will visit here one by one. The i-th man to visit will take the following action:

  • If both turkeys xi and yi are alive: selects one of them with equal probability, then eats it.
  • If either turkey xi or yi is alive (but not both): eats the alive one.
  • If neither turkey xi nor yi is alive: does nothing.

Find the number of pairs (ij) (1≤i<jN) such that the following condition is held:

  • The probability of both turkeys i and j being alive after all the men took actions, is greater than 0.

Constraints

  • 2≤N≤400
  • 1≤M≤105
  • 1≤xi<yiN


我有个乱搞做法,和题解略微不同,感性上看很有道理,在这里mark一下,如果哪位能叉掉请在评论区告知我。

设bz[i][j]∈{0,1}表示i是否可能与j同时存活。

易于发现这个bz是有传递性的,即如果bz[x][y]=0,bz[y][z]=0,那么一定有bz[x][z]=0

每次的连边(x,y)相当于是令bz[x][y]=0,那么我们传递一次bz数组。

特殊地,如果在这次(x,y)之前,已经有bz[x][y]=0,那么这次以后,x和y必定都死了,die[x]=die[y]=1。

最后如果数对(i,j)满足die[x]=0 and die[y]=0 and bz[x][y]=1,就满足条件。

复杂度O(nm+n^2)

 

贴一下官方题解:

Editorial


以上是关于AGC 016 E Poor Turkeys的主要内容,如果未能解决你的问题,请参考以下文章

AtCoder Grand Contest 016 E - Poor Turkeys

[agc016e]poor turkeys

[agc016E]Poor Turkeys

AGC216E Poor Turkeys

[agc016d]xor replace

AGC016EPoor Turkeys