标签:特殊 code key too find from sele actions number
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:
Find the number of pairs (i, j) (1≤i<j≤N) such that the following condition is held:
我有个乱搞做法,和题解略微不同,感性上看很有道理,在这里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)
贴一下官方题解:
标签:特殊 code key too find from sele actions number
原文地址:https://www.cnblogs.com/lyd729/p/9221081.html