Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a mistake of ch9 / UVa1218.cpp ? #12

Open
Sengxian opened this issue Oct 15, 2015 · 0 comments
Open

Is there a mistake of ch9 / UVa1218.cpp ? #12

Sengxian opened this issue Oct 15, 2015 · 0 comments

Comments

@Sengxian
Copy link

In line 44 and 45

        if(d[u][0] > INF) d[u][0] = INF; // avoid overflow!
        if(d[u][1] > INF) d[u][1] = INF;

and line 51

        d[u][2] = min(d[u][2], d[u][1] - d[v][2] + d[v][0]); // neither u or father is server

If d[u][1] and d[v][2] are set to INF. d[u][1] - d[v][2] will be a zero, it’s obviously meaningless.

Although it is accepted, it will make mistakes in some test cases. Like

7
1 5
4 1
3 5
2 3
6 5
7 2
-1

the correct ans is 3, but the code get 1.

If we change it to this

                if(d[v][0] > INF) d[v][0] = INF;
                if(d[v][1] > INF) d[v][1] = INF * 2; // avoid INF - INF = 0

It will be all right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant