PROBLEM LINK:Author: Pavel Sheftelevich DIFFICULTY:Hard PREREQUISITES:Maximal planar graph PROBLEM:You are given N points and M edges connecting them. You have to determine whether it is possible to draw those N points and M edges on a plane such that no two edges intersect except at the endpoints and it is not possible to add another edge without intersecting an existing edge. EXPLANATION:The first part is to find whether it is possible to draw the points and edges such that the edges are non intersecting. That is the definition of planar graph. The second part of the condition is that if we add one more edge the graph will be non planar. Thus we have to find out whether the given graph is a maximal planar graph or not. This can be done in linear time using the algorithm given here. Time Complexity:$O(N)$ AUTHOR'S AND TESTER'S SOLUTIONS:
This question is marked "community wiki".
asked 15 Jun '15, 14:15

I used almost exactly the approach from the editorial  googled the paper and implemented the algorithm described there. That's a bad thing, though. For one, getting to the paper took me about half a minute on Google and 5 minutes of waiting for the login page on Researchgate to load. What's worse, there's literally no CS about it, it's all just implementation and googling; you don't have to read the paper (apart from the 3 algorithms you're asked to implement) at all. That's not how you make contest problems. Btw "The first part is to find whether it is possible to draw the points and edges such that the edges are non intersecting."  no, that isn't required in the solution. From what I understood, the described algorithm is simple exactly because it assumes the graph is maximal planar, and just reports "fail" when the assumption fails instead of trying more sophisticated ways to test if it's just planar. Editorial: 0/10 nothing to read. answered 15 Jun '15, 18:34

The problem statement isn't "misleading", it's entirely incorrect however you interpret it. @ushsh, both the preedit and postedit versions of the problem are wrong. The edit just rewrote the sentence while for the most part maintaining its meaning. Easy example: for n=4, m=5, the graph can ALWAYS be drawn by choosing (it said you could choose points from the euclidean plane) the 4 points to be the vertices of a square and the 5 edges to be its outer edges and one diagonal, in which case you can never draw the 6th edge, making the answer 1 in this case. Every graph with (4,5) is isomorphic to the graph described in this embedding. PREEDIT VERSION ... He marked N pairwise different points on the plane and then connected M pairs of these points by straightline segments. None of these segments intersect(maybe except at the initial N points). Then Leha tried to draw the M+1th segment but surprisingly it turned out that it was impossible to connect any pair of points by straightline segment which wouldn't intersect with any of the previous segments. ... The questions is: whether it's possible to choose N points on the Euclidean plane such that they will fit the situation described above. Yes, it's possible to choose points as described above. You said "is it possible to choose". This means you are allowed to choose any planar embedding, even one that would prevent you from adding another edge. POSTEDIT VERSION The question is: whether it's possible to choose N points on the Euclidean plane in any way such that they will always fit the situation described above. Yes, it is possible to choose points "in any way" (as described above) such that they will "always" fit the situation. "Any way" means "any one way out of all possible ways". By saying "always", the author obviously meant to say (as we realized after some WAs), output 1 if (i) there exists at least one choice of points with a corresponding planar embedding, and (ii) considering all graphs (>= 0 of them) resulting from an edge addition to the input graph, none of them has a choice of points corresponding to a planar embedding. That is, is the graph maximal planar. Totally different question. Making some words in a sentence bold does not change their meaning. Linguistic accuracy is the foundation of making problem statements, as all of mathematics and computer science depend on formal notation and on rigour in language. I understand that the problem was probably translated from another language, but that definitely does not justify its being incorrect after testing. I know this is a pretty long rant, but I wasted a lot of time on this problem (as I did with the author's previous problem LPARTY a few months ago, which also had a terrible choice of words and story). I do hope I am correct and would appreciate it if someone could explain how I am wrong in case I am. answered 15 Jun '15, 18:10
If you choose points in ANY WAY, and they ALWAYS fit the conditions stated (regardless of what points you chose), then answer is 1. (read my comment on @Amlesh's second answer). "the graph can ALWAYS be drawn by choosing (it said you could choose points from the euclidean plane) the 4 points to be the vertices of a square and the 5 edges to be its outer edges and one diagonal, in which case you can never draw the 6th edge, making the answer 1 in this case." Answer is 0 in this case. In your example, the graph cannot ALWAYS be drawn by choosing the points such that it's a maximal planar graph
(15 Jun '15, 21:11)
Again, you are stressing the wrong words. "If you choose points in ANY WAY, and they ALWAYS fit the conditions stated (regardless of what points you chose)" IT DOES NOT SAY IF YOU CHOOSE. IT SAYS IS IT POSSIBLE TO CHOOSE. If you want to consider ALL POSSIBLE SETS OF POINTS, then you CANNOT use the phrase "IS IT POSSIBLE TO CHOOSE"! You must say "among all possible sets of points". Both IS IT POSSIBLE and TO CHOSE make your argument wrong. IS IT POSSIBLE ALWAYS means is there at least one case which is true, NOT is there at least one case which is false. Please read this carefully.
(20 Jul '15, 00:32)

Could not download paper. Please write normal editorial or give working link. answered 15 Jun '15, 20:27

@Amlesh, no, you can add one more edge, just draw a triangle and point inside it connected to all vertices of triangle. @tapasjain01, yes your algorithm should receive 20 points, because when n <= 5, only nonplanar graph is K5, which is has more edges than 3*56/ answered 15 Jun '15, 15:41

I agree with @Amlesh. This is the fcking shittiest problem statement I have ever seen in my life. To think I spent days trying the wrong problem when I have so much more important shit to do, darn. You guys do not know how to write problem statements. The question clearly wanted an embedding of a planar graph on the plane such that any new edge intersects a previous segment. Now, it is like, "Hehe, just a misunderstanding, I meant a maximal planar graph. Not a big deal". I hate you all. answered 15 Jun '15, 18:58

IMHO the problem statement is misleading, since as its stated we aren't quite looking for maximal planar graphs. Consider the following input: 4 5 1 2 2 3 3 4 4 1 1 3 One way this can be interpreted is as a square with one of its diagonals connected. This is a planar embedding of a graph where no additional edge can be drawn, but however this graph is not maximal. As stated, the problem is to determine whether there exists a maximal embedding of the given graph (if its planar of course), and not just determine if the graph itself is maximal. In fact I noticed a lot of the AC solutions miss the above case. answered 15 Jun '15, 15:21

@madiyar the problem statement clearly states that we are to "try to place the given N points and M nonintersecting segments that are given, you will never be able to place M+1th segment". So for the input I described in my post, we can clearly embed the graph as a square with only one diagonal drawn, making it maximal. What the problem setter intended was to show that regardless of how the graph is embedded that it should be maximal, which isn't how the statement is currently worded. answered 15 Jun '15, 15:45
My interpretation of the statement "The question is: whether it's possible to choose N points on the Euclidean plane in any way such that they will always fit the situation described above" is that if there is at least one way of choosing points such that it does not conform to the conditions then answer is NO. The highlighted phrases are important. If you choose the points in ANY WAY, and they ALWAYS conform to the conditions, then answer is YES which is what the statement says basically. IMHO the statement is not ambiguous.
(15 Jun '15, 20:48)

But i won't choose these points. i would go for 1=(0,0) 2=(1,0) 3=(1,1) and 4=(0,1). So thats a possible way of choosing the points and hence the answer should be "YES" according to me. Because the question states "whether it's possible to choose N points on the Euclidean plane in any way such that they will always fit the situation described above." and YES, it is possible. answered 15 Jun '15, 15:50

@miteshag The question asks us to determine whether there exists an embedding such that we can't draw an extra edge. Yes I agree that this graph isn't maximal, but there exists a way to embed that graph so that there are no ways to add additional edges, namely a square with one of its diagonals. The problem statement should have mentioned that "regardless of how we place the N points on the plane such that the edges don't cross, we can't place a new edge between existing points", instead of "try to place the N points in a way such that ....". Its particularly frustrating because I immediately dismissed the idea of just classifying the graph as maximally planar precisely due to the fact that I thought the graph just had have one embedding that was maximal, as the problem statement suggests :( answered 15 Jun '15, 15:55

I attempted the question for 20 marks . This is my solution. http://www.codechef.com/viewsolution/7154533 It gave WA on the second part of the subtask meant for 20 points. Now , have a look at this solution, http://www.codechef.com/viewsolution/7211402 What i can't understand is that I just used a greater than sign for just namesake (in case there are more than n*(n1)/2 segments given as the value of m). Afterall , it was specifically mentioned that no two points can be connected by more than 1 segment , and no point can be connected to itself. So, how can this solution of mine can be wrong. Pls, help where am I wrong. answered 15 Jun '15, 21:43

@tapasjain01 @Amlesh For the case given with diagonal in a sqaure, we get to choose the points in cartesian plane.Hence, if I choose 1=(0,0) 2=(10,0) 3=(0,10) 4=(1,1). Then after making the graph, I can still add an edge, from 2 to 4. Hence answer will be 0. answered 15 Jun '15, 15:43

I read it again just now. Now I see that your point is valid. answered 15 Jun '15, 15:55

The problem statement changed to The question is: whether it's possible to choose N points on the Euclidean plane in any way such that they will always fit the situation described above.at 14/06/2015, 02:00 hrs IST. But I think it was too late. answered 15 Jun '15, 16:06

Next time pay please more attention to the problem statement and clarify the updates somehow, otherwise people try to solve another problem which is much more complex. answered 15 Jun '15, 20:26

Check this : http://www.codechef.com/viewsolution/7234731 I just changed your soln a little bit.... All >= signs are there as it is except for n = 5 (last case) as 5C2 is 10.... That was your mistake for n = 5 and m = 9 ans is 1 and for n = 5 and m = 10 ans must be 0... Hope you can understand... answered 16 Jun '15, 00:20

@shivamg_isc , agree with you. As the problem statement says the given m edges are nonintersecting. For n=5, and the optimal planar graph will have 9 edges (i.e. we cannot add more edge). Since they are not giving nonintersecting edges they cannot give m>=10 for n=5, so for m<9 answer should be 0 and m>=9 answer should be 1. But it gave me wrong answer. I got correct answer for 20 points when i did m==9 instead of m>=9. Why so, if they haven't given m>=10 (because for m>=10 the m edges will intersect) ??? I mean answer should not depend for m>=10 for n=5 since they are not giving nonintersecting edges. Am i wrong anywhere in understanding anything?? answered 16 Jun '15, 00:26

@checkmate1 , Yes 5C2 is 10.But they cannot give m=10 for n=5 because for this the edges will intersect but question say the given m edges are nonintersecting. So how they can give m=10 nonintersecting edges for n=5??? So one cannot say whats the answer for m=10 and n=5. answered 16 Jun '15, 00:32

@shubham201 that is what.. this is exactly the point which flashed in my mind. It is impossible for them to give m=10 for n=5. Was there some problem with the test cases ? :/ .. This question sucks . answered 16 Jun '15, 00:46

Editorials are supposed to provide an opportunity for us to learn. Not point to a third party link! Wake up guys! answered 16 Jun '15, 22:19

Uploaded the paper (PDF) here: https://www.scribd.com/doc/269955060/Asimplerecognitionofmaximalplanargraphs answered 29 Jun '15, 14:44
