讨论 / OMFG-题解!(注:喜欢Alan 和Marshmello的看过来)
fnoichzhe 2017-12-30 23:55:37
点我顶贴 收藏 删除
#include <cstdio>

const int N=55000;

int f[N],p[N],savege,n,k,d,x,y,alex,px,py,marshmello,alanwalker,d1;

int omfg (int x,int &px){

if(!f[x]) return x;

else {px=(px+p[x])%3;return omfg(f[x],px);}

}

int main(){

freopen("new.in","r",stdin);

freopen("poj1182.out","w",stdout);

scanf("%d%d",&n,&k);

savege=0;

for(int i=1;i<=n;++i) f[i]=0;

for(int i=1;i<=k;++i) {

scanf("%d%d%d",&d,&x,&y);

if(x>n||y>n){savege++;continue;}

if(d==2&&x==y){savege++;continue;}

d--;px=0;py=0;

marshmello=omfg(x,px);

alanwalker=omfg(y,py);

if(marshmello!=alanwalker){

f[marshmello]=alanwalker;

d1=(py-d+3)%3;

p[marshmello]=(d1-px+3)%3;

}else{

d1=(py-px+3)%3;

if(d!=d1){

savege++;

}

}

}

printf("%d",savege);

return 0;

}

#1 fnoichzhe@2017-12-30 23:55:55
回复 删除
顶啊d=====( ̄▽ ̄*)b
查看更多回复
提交回复