2013-team5/andrew/30/H

从 Trac 迁移的文章

这是从旧校内 Wiki 迁移的文章,可能存在一些样式问题,您可以向 memset0 反馈。

原文章内容如下:

{{{
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
using namespace std;
int f[210][210];
int n,m;
bitset <201> S[210];

void gao(){
    for (int i=1; i<=n; i++) S[i].reset();
    for (int i=1; i<=n; i++)
        for (int j=i+1; j<=n; j++) if (f[i][j]){
            S[j]|=S[i]; S[j].set(i-1,1);
        }
    int ans=0;
    for (int i=1; i<=n; i++) ans+=S[i].count();
    printf("%d\n",ans);
}

int main(){
    freopen("settling.in","r",stdin);
    freopen("settling.out","w",stdout);
    scanf("%d%d",&n,&m);
    int i,j,k;
    for (i=1; i<=m; i++){
        int x,y;
        scanf("%d%d",&x,&y);
        f[x][y]=1;
    }
    gao();

    int q,x,y;
    char ss[9];
    scanf("%d",&q);
    while (q--){
        scanf("%s%d%d",ss,&x,&y);
        if (ss[0]=='?')
            if (S[y][x-1]) puts("YES"); else puts("NO");
        else{
            if (ss[0]=='+') f[x][y]=1; else f[x][y]=0;
            gao();
        }
    }
    return 0;
}
}}}
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
using namespace std;
int f[210][210];
int n,m;
bitset <201> S[210];
void gao(){
    for (int i=1; i<=n; i++) S[i].reset();
    for (int i=1; i<=n; i++)
        for (int j=i+1; j<=n; j++) if (f[i][j]){
            S[j]|=S[i]; S[j].set(i-1,1);
        }
    int ans=0;
    for (int i=1; i<=n; i++) ans+=S[i].count();
    printf("%d\n",ans);
}
int main(){
    freopen("settling.in","r",stdin);
    freopen("settling.out","w",stdout);
    scanf("%d%d",&n,&m);
    int i,j,k;
    for (i=1; i<=m; i++){
        int x,y;
        scanf("%d%d",&x,&y);
        f[x][y]=1;
    }
    gao();
    int q,x,y;
    char ss[9];
    scanf("%d",&q);
    while (q--){
        scanf("%s%d%d",ss,&x,&y);
        if (ss[0]=='?')
            if (S[y][x-1]) puts("YES"); else puts("NO");
        else{
            if (ss[0]=='+') f[x][y]=1; else f[x][y]=0;
            gao();
        }
    }
    return 0;
}