AGC216E Poor Turkeys

题意

出门左转https://arc085.contest.atcoder.jp/tasks/arc085_d

题解

参考Editorial

假设当前有火鸡集合 $S$,已经过了 $t-1$ 步,我们来考虑第 $t$ 步对 $S$ 的影响:

  • 如果 $x_t\in S$ and $y_t\in S$,那么 $x_t$ 或者 $y_t$ 不可能存活,
  • 如果 $x_t\in S$ and $y_t\not\in S$,在 $t-1$ 时要有 $y_t$。

用bitset维护 $N$ 个集合,然后 $\mathcal O(NM)$ 处理出集合。

调试记录

  • 一遍过QaQ

image

代码

#include <bits/stdc++.h>
using namespace std;

int n,m; bitset<400> S[400];
int x[200005], y[200005];
bool no[200005];

int main() {
    scanf("%d%d", &n, &m);
    for (int i=0; i<n; i++) S[i][i] = 1;
    for (int i=0; i<m; i++) scanf("%d%d", &x[i], &y[i]), --x[i], --y[i];
    for (int i=m-1; i>=0; i--) {
        for (int j=0; j<n; j++) {
            if (S[j][x[i]] && S[j][y[i]]) no[j] = 1;
            else if (S[j][x[i]]) S[j][y[i]] = 1;
            else if (S[j][y[i]]) S[j][x[i]] = 1;
        }
    }
    int ans = 0;
    for (int i=0; i<n-1; i++)
        for (int j=i+1; j<n; j++)
            if (!no[i] && !no[j] && !(S[i] & S[j]).count()) {
                ++ans;
            }
    printf("%d\n", ans);
    return 0;
}
posted @ 2018-08-14 08:51  MCH__ds  阅读(198)  评论(0编辑  收藏  举报