THOUSES - Editorial

They will not reveal test cases where the program failed

Bro, i dont know java so I cant really help much.

Bro thanks a lot for response

https://www.codechef.com/viewsolution/46668706
my first two test cases are not passing any suggestions

I did consider the structure of tree but got WA in test case 1 and 2 because I made directed graph. But when i converted it to undirected graph(leaving everything else unchanged), case 1 and 2 passed. Is there any problem with cases 1 and 2 because this isn’t suppose to happen. If you make undirected graph then you have to anyway skip the edge to parent, thats why i made directed graph. Please clarify this. And btw, atleast after the contest is over codechef should show the test case on which our code failed. How am I supposed to learn anything new if I dont get to know what was my mistake?

yupp, codechef have to show test cases at least for long challenge

https://www.codechef.com/viewsolution/46672678

Can someone please check this? I am only able to pass the first two test cases.

Hey, I can pass only the first two test cases. Maybe we can check each other’s code and get an insight into what’s wrong with ours.

ok did you applied the same approach

Mod will not reduce the value in any case

Hello Leo, please let me know for which test case it is falling
Solution: 46363012 | CodeChef
https://www.codechef.com/viewsolution/46363012

I can actually explain the reason. But before that, I want you to try a problem. Don’t worry, I will provide you with the link, what you are actually supposed to do is, implement the solution in Java and run against the input that follows.

Problem Link: Josephus Problem - GeeksforGeeks

Input:

N = 1000000
K = 10000 (In fact, value of K doesn't matter).

PS: I really have a solution. I actually wanted to start a thread on this.

Oh, actually I don’t use Java. I use C++ or Python.(mostly C++)

convert n in to binary and left shift be 1,append 0 at right extrem
Regards
Samuel

I thought the reason could be the “Stack limit reached” exception. But you didn’t use recursion in your code.

Coming to the reason, The CSES Josephus problem can be solved recursively. Implementing the solution available on GFG and running it for larger values of N (say around 1 Million), will result in stack overflow Exception. For this, you have to write some exclusive code, using Thread.

public class Main implements Runnable {
    public void run() {
        int testcases = 0;
        // testcases++;
        if(testcases == 0)
            testcases = io.nextInt();
        preCompute();
        for(int test = 0; test < testcases; test++) {
            // io.print("Case #" + (test + 1) + ": ");
            solve();
        }
    }

    public static void main(String[] args) { // This way the recursion depth can be increased
        new Thread(null, new Main(), "Main Thread", 1 << 30).start();
    }
}

But, this is not required in Codechef, since the environment provides enough stack size for Java.

WA on test 3 and 6. Please Help.
Code: CodeChef: Practical coding for everyone

For people getting WAs in first three files, consider the edges undirected. Edge (u, v) doesn’t mean that node u is a parent of node v. It can be the other way as well.

1 Like

I have implemented implemented using Maps,one WA,two NZAC

https://www.codechef.com/viewsolution/46363012
Hello Karina124,Why to go for BSF?
we have below info available
1)Always n is leafe
2)1 to n are like notebook writing way
By Maintaining parent child info and Node count info{sub tree count}
i wrote,but facing issues

Hello below is my approach
1)Maintaining Maps for NodeCount and Parentof maps
2)NodeCount Map give the number of nodes it covers/sub tree size
3)X_at_Node Map populated with the help of NodeCount Map
4)Add all X values int the X_at_Node Map gives the Answer