移動遊戲By HYJ

來源:互聯網
上載者:User

標籤:algo   set   pac   inline   putchar   return   string   ios   sizeof   

暴力求SG函數即可,記憶化賊方便

/*program from Wolfycz*/#include<cmath>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define inf 0x7f7f7f7fusing namespace std;typedef long long ll;typedef unsigned int ui;typedef unsigned long long ull;inline int read(){    int x=0,f=1;char ch=getchar();    for (;ch<‘0‘||ch>‘9‘;ch=getchar())  if (ch==‘-‘)    f=-1;    for (;ch>=‘0‘&&ch<=‘9‘;ch=getchar())    x=(x<<1)+(x<<3)+ch-‘0‘;    return x*f;}inline void print(int x){    if (x>=10)     print(x/10);    putchar(x%10+‘0‘);}const int N=1e4,M=1e5;int pre[M+10],now[N+10],child[M+10],tot;int can[N+10];int n,m;void join(int x,int y){pre[++tot]=now[x],now[x]=tot,child[tot]=y;}void dfs(int x){    if (can[x]!=-1) return;    bool flag=0;    for (int p=now[x],son=child[p];p;p=pre[p],son=child[p]){        dfs(son);        if (!can[son])  flag=1;    }    can[x]=flag;}void init(){    tot=0;    memset(now,0,sizeof(now));    memset(can,-1,sizeof(can));}int main(){    for (int Data=read();Data;Data--){        init();        n=read(),m=read(),can[n]=0;        for (int i=1;i<=m;i++){            int x=read(),y=read();            join(x,y);        }        dfs(1);        printf(can[1]?"yes":"no");        putchar(‘\n‘);    }    return 0;}

移動遊戲By HYJ

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.