Yes; that was the problem.
However, this problem was quite biased against Python users IMO; did users in other languages experience the same problem?
Yes; that was the problem.
However, this problem was quite biased against Python users IMO; did users in other languages experience the same problem?
brilliantly done!
quality & timing of editorials have seriously improved on codechefā¦nic work
is Strassen algorithm really fast enough to solve this? http://discuss.codechef.com/questions/48384/strassen-algorithm-not-fast-enough
why tle ?
please helpā¦
The editorials of codechef are a lot more exhaustive and easier to understand than that of codeforces.
will this work? all pair shortest paths of cost 2
Here are solutions both in JAVA and C++.
Both of them use BitSet concept. Iāll try and write this in terms for even a layman to understand. If youāre a beginner, iām assuming you know what the ā&ā bitwise operator returns for 2 binary values. If you donāt then just google it. Itās pretty easy
C++:
My C++ submission: http://www.codechef.com/viewsolution/6843913
JAVA:
Same concept. Its gets much easier here.JAVA has an awesome āBitset.intersects(BitSet)ā method. Intersect means that they have atleast one common bit set.
1.Create an ArrayList of Bitsets and build the graph up.
2.Now same. run a loop for each vertex to check for non adjacent vertices. After that, simply check when (i!=j && !gr.get(i).get(j)) -> if(gr.get(i).intersects(gr.get(j))), ans++;
CAUTION: the second .get(j) is a bitset method. Not the arrayList one. It checks if the bit is set at position j
DONE!
My JAVA submission: http://www.codechef.com/viewsolution/6843885
Meanwhile, iām picking up some of my old WA and TLE submission and try and make a few optimisations here
It seems my optimisations were correct!! Cuts the runtime by HALF
Here is my submission. Iāll leave it to you to understand why this works :). Common sense actually
Hereās a similar SPOJ question I had solved. Itās easier than this. I just used HashMaps there. http://www.spoj.com/problems/FACEFRND/