Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8466157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:15:33+00:00 2026-06-10T15:15:33+00:00

I was solving a programming problem on a site. On my machine (Visual Studio

  • 0

I was solving a programming problem on a site. On my machine (Visual Studio 2010) a test case gives wrong result, while gives correct result on the site. I am not sure what is the compiler of the site’s judge, but I think it is something like gcc or cygwin.

THE CODE

A graph problem. The graph here is represnted as a tree. The graph is directed, and doesn’t contain loops. The solution is (2 * sum of all edges - max path length from root)

//     to-vertex & edge-length
vector<pair<int, int> > pr[100];
int dfs(int i) // to find max path length from root
{
    int mx = 0;
    for (int j = 0; j < pr[i].size(); ++j)
        mx = max(mx, dfs(pr[i][j].first) + pr[i][j].second);
    return mx;
}

int PowerOutage::estimateTimeOut(vector <int> from_vertex,
                 vector <int> to_vertex, vector <int> edge_length)
{
    int tot = 0;
    for (int i = 0; i < from_vertex.size(); ++i)
    {
        pr[from_vertex[i]].push_back(make_pair(to_vertex[i], edge_length[i]));
        tot += (2 * edge_length[i]);
    }
    return tot - dfs(0);
}

THE TEST CASE

from_vertex   {0,     0,   0,   0,   0}
to_vertex     {1,     2,   3,   4,   5}
edge_length   {100, 200, 300, 400, 500}

Visual Studio returns: 2493, While the site’s compiler returns the correct answer: 2500.

Why the two results are different? I think there is some hidden bug (in my code) that appears in VS giving wrong answer but disapper in the other compiler. Should I determine the site’s compiler and use it instead?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:15:34+00:00Added an answer on June 10, 2026 at 3:15 pm

    Despite my first(wrong) assumption, OP has found out that it was 2500 already but the test-function had the flaw after i asked him “where is 2500 printed?”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While solving any programming problem, what is your modus operandi ? How do you
I was practising the algorithm based programming problem.I am having difficulty,in solving this problem.I
I'm solving UVA's Edit Step Ladders on an uva sub-site named programming-challenges.com, but since
I watched Dynamic Programming - Kapsack Problem (YouTube) . However, I am solving a
I'm currently solving a programming problem to enhance my skills (I'm still a newbie)
I was solving a programming problem, which wants to find the SYMMETRIC DIFFERENCE between
I am solving a programming problem which is stuck at calculating nCr efficiently and
I have a question about solving UI freezing. Introduction: I am currently programming an
While solving exercises from the K&R C book, I stumbled upon the exercise 2.1.
I am solving problem 9 on the Project Euler . In my solution I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.