skh nb

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int _=1e5+7;
int read() {
    int x=0,f=1;char s=getchar();
    for(;s>'9'||s<'0';s=getchar()) if(s=='-') f=-1;
    for(;s>='0'&&s<='9';s=getchar()) x=x*10+s-'0';
    return x*f;
}
int n,m,a[_],ok[_],who[_],ans[_];
struct node {
    int opt,u,v;
}Q[111111];
bool cmp(int x,int y) {
    if(x==y) return 1;
    if(x==3 and y==2) return 1;
    if(x==2 and y==1) return 1;
    if(x==1 and y==3) return 1;
    return 0;
}
void work() {
    for(int i=1;i<=n;++i) ok[i]=1,who[i]=i;
    for(int i=1;i<=m;++i) {
        if(Q[i].opt==1) {
            int x=who[Q[i].u],y=who[Q[i].v];
            if(cmp(a[x],a[y])) ok[y]=0;
            else ok[x]=0,who[Q[i].u]=y;
        } else ans[Q[i].v]+=ok[Q[i].u];
    }
}
int main() {
    // freopen("a.in","r",stdin);
    n=read(),m=read();
    for(int i=1;i<=m;++i) {
        Q[i].opt=read();
        if(Q[i].opt==1) Q[i].u=read(),Q[i].v=read();
        else Q[i].u=read(),Q[i].v=i;
    }
    int limit=1;
    for(int i=1;i<=n;++i) limit*=3;
    for(int i=0;i<limit;++i) {
        int tmp=i;
        for(int j=1;j<=n;++j) a[j]=tmp%3+1,tmp/=3;
        work();
    }
    for(int i=1;i<=m;++i) if(Q[i].opt==2) printf("%d\n",ans[i]);
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/dsrdsr/p/11737016.html
今日推荐