using namespace std;
const int maxN = 100010;
void dfs(int u)
if(value[u] < mini && value[u]>=0)
long long sum=0;
sum= sum+ x[i];
Check your output for this test case:
Your Output : -1
Correct Output: 0
You must end your program after you print -1…your program seems to continue to print other values after printing -1.
@shashank_1…your code fails for this testcase
This is because…If there is ONE compenent in the graph and all are interconnected then there is not need to build any teleport hence the o/p should be 0 instead of -1.Hope this helps.
@shashank_1: there were two bugs in your code:
- when the whole graph visited in one go, u was still printing -1, instead of 0(that u fixed probably,actually I am not able to access your latest ideone submission).
- the second bug is that, u have not initialized the variable minx, with any max_value before making the comparison.
Below is the link of your modified code, which got AC.
u r right , thnx a lot…
bcoz of u, i m able to noe my mistake and correct it
nw i hv done dis ques using disjoint-set structure
here is the link to my solution CodeChef: Practical coding for everyone
gettin right answer for all above testcases bt getting WA plz help
@shashank_1: thnks, good going