Jomax100's blog

By Jomax100, history, 5 years ago, In English

As the title suggests, I submitted the identical source code, which in my environment and in c++17 gives the right answer, but in c++14 it gives WA. I am aware this usually involves some sort of default initialization, but I believe my codes does not rely on that. I appreciate your help and insights as to what might be happening!

WA

AC

Two editorials for this problem, but I followed this one

  • Vote: I like it
  • +18
  • Vote: I do not like it

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Jomax100 (previous revision, new revision, compare).

»
5 years ago, # |
  Vote: I like it +75 Vote: I do not like it
id[a[i].u] = sz(id);

It is not guaranteed that sz(id) will be evaluated before id[a[i].u], until C++17.
For more info: Order of evaluation

»
5 years ago, # |
  Vote: I like it -22 Vote: I do not like it

You should write forn(h, sz(b)+1){ forn(u, sz(b)+1){ forn(v, sz(b)+1){ mmin(dp[u][v], dp[u][h] + dp[h][v]); } } } because your indexes are from 1 to sz(b),not 0 to sz(b)-1 After changing it got AC:57892426

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Interesting fix. On my machine the ids started at 0. This must be the undefined behaviour mentioned by meooow