[USACO19JAN]Grass Plantin
本人水平有限,题解不到为处,请多多谅解 本蒟蒻谢谢大家观看 题目: 传送门 乍一看,用dfs遍历树在七搞八搞,最后怀着激动的心情提交,AC三个点, TLE七个点 30分代码: 1 #include<bits/stdc++.h> 2 #pragma GCC optimize(3) 3 const int N=5e5+100; 4 using namespace std; 5 int n,tot,cnt=1,ans; 6 int ver[N],head[N],nxt[N],f[N],vis[N]; 7 void inint(){ 8 freopen("grass.in","r",stdin); 9 freopen("grass.out","w",stdout); 10 } 11 inline int read(){ 12 int x=0,f=1;char ch=getchar(); 13 while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();} 14 while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} 15 return x*f; 16 } 17 void add(int x,int y){ 18 ++tot; 19 ver[tot]=y; 20 nxt[tot]=head[x]