Violence to the SG function can be, memory thief convenient
/*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 ();D ata;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;}
Mobile games by Hyj