Recently I've tried to solve this problem 160D - Edges in MST but there was a bug in my code, I've tried to debug the code but that was just wasting time, then I've rewritten the code again and got AC :D. Making a comparison between the two codes was so weird they were almost identical, I read about undefined - behavior in C++ but I couldn't find anything like that.
WA code: 12013993
AC code: 12013990
Any help would be appreciated.
It seems like you have an index out of bounds somewhere in your code. I changed MAXN constant and it passed(12110970).
You are right but shouldn't it gives RTE. and why did it passed in the second submission?
You actually do have undefined behavior possible in both of your programs. Array
s
should be 2N size as you store two elements for each edge. What actually happened is that arraydfs_num
is allocated right after arrays
in memory so you would use it as part ofs
you are missing and overwrite its data, in second programs
is after all other arrays so you would mess with memory that you don't know anything about and get lucky.Thanks, I really appreciate your help.