c++ - pat 1021 deepest root 第4个测试点无法通过
怪我咯
怪我咯 2017-04-17 15:38:57
0
0
726

1.pat 1021 deepest root 第4个测试点无法通过
2.代码:跟参考答案代码基本一致,只是变量名变了而已;求大神指出代码中无法通过测试的原因!谢谢

#include #include #include using namespace std; const int maxn=100010; vector adj[maxn]; bool root[maxn]; int father[maxn]; void init(int n) { for(int i=1;i<=n;++i) { father[i]=i; } } int findfather(int x) { int a=x; while(x!=father[x]) { x=father[x]; } while(a!=father[a]) { int temp=a; a=father[a]; father[temp]=x; } return x; } void sunion(int a, int b) { int fa=father[a]; int fb=father[b]; if(fa!=fb) father[fb]=fa; } int blockcount(int n) { int block=0; for(int i=1;i<=n;++i) { //int rt=findfather(i); root[findfather(i)]=true; } for(int i=1;i<=n;++i) { block+=root[i]; } return block; } int maxheight=0; vector tempdeepest, ans; void dfs(int vt, int height, int pre) { if(height>maxheight) { tempdeepest.clear(); tempdeepest.push_back(vt); maxheight=height; } else if(height==maxheight) tempdeepest.push_back(vt); for(int i=0;i

怪我咯
怪我咯

走同样的路,发现不同的人生

全部回复 (0)
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!