FIRESC - Editorial

can you tell me where my solution is failing?
my submission is http://www.codechef.com/viewsolution/1909473

Can anyone tell me what is wrong with my approach and for which test case it fails… My submission id is http://www.codechef.com/viewsolution/1913075

i have used same approach as gven in editorial but it is giving me wrong answer.anyone explain me…where i am wrong first in C is C SOLUTION http://www.codechef.com/viewsolution/1910690 and second is in JAVA is JAVA SOLUTION http://www.codechef.com/viewsolution/1907414

1 Like

Hi all,

I dont know how to represent graph having large no of nodes to represent using adjacency list.
I know it requires hash table(as using linked list is not feasible here)
but i want to know how to implement.

I am getting wrong answer …
Can you give me failing case…
http://www.codechef.com/viewsolution/1930220

This might help, https://class.coursera.org/algs4partI-002/lecture/8

They both have the same mistake. You do not handle possible overflow in this statement

total = ((total N)*(count N) % N;

As you can see, because N is 1000000007, the result of the product might exceed the range of 32-bit integers. You must cast total as long long in C to solve the issue. Cast total to long in JAVA to get AC.

Checkout the fixes here.

I could point out two bugs

  • You have to find uniques in the id array. You are simply parsing over it and inserting ‘i’ instead of find(i) in the HashSet.
  • Multiplying everything and storing in a long will potentially overflow. It is fixed by storing the result modulo 1000000007 along the way.

Try this test case

1
4 3
1 2
1 3
4 3

You print

2 4

The answer should be

1 4

Can you see how?

1 Like

http://www.codechef.com/viewsolution/1939836 getting wrong ans…really pissed off :frowning: please find the error…thanx in advance…

Yes right… after changing the logic to total = ((total N)*(count N) % N;… my code also worded… huh…
http://www.codechef.com/viewsolution/1927944

Can anyone plz tell me why I m getting a runtime error in my


[1]


  [1]: http://www.codechef.com/viewsolution/1946001

I have used BFS instead of DFS but am getting a wrong answer. Could you please point out the mistake?

http://www.codechef.com/viewsolution/1926182

Hi, i used the Union Set Method , but for some reason it kept flagging it as Wrong Answer. I wrote a solution in C first, but thought that might be overflowing for some value, so i resorted to Python, in which overflowing will not be an issue, given the range.

My solution is here : http://www.codechef.com/viewsolution/1908378 (PYTH)

Can anyone tell me where it’s going wrong ? Thanks. I’m all out of ideas.

http://www.codechef.com/viewsolution/1892955
please tell me in which cases my code is getting WA…

please give me a case where my code gives wrong answer. I have used a different approach, but i want to know why its failing. http://www.codechef.com/viewsolution/1909473

Any border test cases? I am still getting WA
http://www.codechef.com/viewsolution/1954203

Hey, am still getting WA. Can you give me any border test case?
http://www.codechef.com/viewsolution/1954203

@anton_lunyov >> Please clarify this:

for (VI::iterator v = a[u].begin(); v != a[u].end(); ++v) {
	// *v is the adjacent vertex itself
	if (!mark[*v]) {
		// if it was not visited before we move to it
		dfs(*v);
	}
}

In the loop part, the begin() and end() functions are called each time an iteration occurs, so isn’t it time consuming? Instead if we just store

x = a[u].begin() 

and

y = a[u].end() 

before entering the loop and then use x and y, do we save some time?

I think all that the .begin() function does is accessing elements on well known positions that are known ahead of time and thus takes constant time, and that gives you no advantage, but maybe doing such modification on the .end() part might help, Im not sure if the gains would be significant though