MLE什么鬼

P1305 新二叉树

@[sunzk](/space/show?uid=67403) 你的f赋值了吗?
by Lolierl @ 2018-02-10 14:39:27


@[Lolierl](/space/show?uid=22930) 我不是很懂你什么意思lol
by Carrot_killer @ 2018-02-10 14:46:27


@[Lolierl](/space/show?uid=22930) 赋值了吧,是不是指初始化 为什么会导致MLE啊
by Carrot_killer @ 2018-02-10 14:48:19


@[sunzk](/space/show?uid=67403) 初始化f[i]=i;不然find爆了
by Lolierl @ 2018-02-10 14:50:42


@[Lolierl](/space/show?uid=22930) 感谢大神,我懂了。但是为什么加了之后会输出一些奇怪的东西,是不是dfs也有问题
by Carrot_killer @ 2018-02-10 14:57:17


@[sunzk](/space/show?uid=67403) 暂时没看出来,给你看看我的代码吧 ```cpp #include<iostream> #include<queue> using namespace std; int ls[30],rs[30]; void dfs(int x) { cout<<char(x+96); if(ls[x]!=0)dfs(ls[x]); if(rs[x]!=0)dfs(rs[x]); return; } int main() { ios::sync_with_stdio(false); int n; cin>>n; int root=0; for(int i=1;i<=n;i++) { char fa,l,r; cin>>fa>>l>>r; if(i==1)root=fa-96; if(l!='*')ls[fa-96]=l-96; if(r!='*')rs[fa-96]=r-96; } dfs(root); return 0; } ```
by Lolierl @ 2018-02-10 14:59:48


@[Lolierl](/space/show?uid=22930) 好的谢谢
by Carrot_killer @ 2018-02-10 15:03:25


然而我已经5MLE~~5TLE~~了lol
by yy233 @ 2018-03-04 18:36:49


|