RT,本来想找一篇题解对拍,发现题解区的 第一篇题解 给出的程序有严重的问题,它在我的电脑上会随机 RE。究其原因,是代码中的几处地方出现了下标访问至 −1 而导致数组越界。
b.cpp:47:26: runtime error: index -1 out of bounds for type 'long long int [400010][19]'
b.cpp:48:47: runtime error: index -1 out of bounds for type 'long long int [400010][19]'
b.cpp:49:47: runtime error: index -1 out of bounds for type 'long long int [400010][19]'
b.cpp:50:35: runtime error: index -1 out of bounds for type 'long long int [400010][19]'
b.cpp:51:49: runtime error: index -1 out of bounds for type 'long long int [400010][19]'
b.cpp:50:83: runtime error: index -1 out of bounds for type 'long long int [400010][19]'
b.cpp:59:19: runtime error: index -1 out of bounds for type 'long long int [400010]'
b.cpp:73:19: runtime error: index -1 out of bounds for type 'long long int [400010]'
通过进一步研究这篇题解给出的代码,发现问题源头出在这两句:
dfs(1,-1);
和
bz[u][0]=fa;
很显然,这两句代码会把 1 的父亲节点设为 −1。这会在后续跳倍增时访问到负数下标而 RE。
综上,我想请求将这篇有错误代码的题解打回。