You are not logged in. Please login at www.codechef.com to post your questions!

×

CONPOIN - Editorial

PROBLEM LINK:

Practice
Contest

Author: Pavel Sheftelevich
Tester: Mahbubul Hasan and Sunny Aggarwal
Editorialist: Balajiganapathi Senthilnathan
Russian Translator: Sergey Kulik
Mandarian Translator: Minako Kojima

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:

Author's solution
Tester's solution

This question is marked "community wiki".

asked 15 Jun '15, 14:15

balajiganapath's gravatar image

6★balajiganapath ♦♦
75542742
accept rate: 77%

edited 20 Jun '15, 00:13


10

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.

link

answered 15 Jun '15, 18:34

xellos0's gravatar image

7★xellos0
5.9k54292
accept rate: 10%

The problem statement isn't "misleading", it's entirely incorrect however you interpret it.

@ushsh, both the pre-edit and post-edit 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.

PRE-EDIT VERSION

... He marked N pairwise different points on the plane and then connected M pairs of these points by straight-line segments. None of these segments intersect(maybe except at the initial N points). Then Leha tried to draw the M+1-th segment but surprisingly it turned out that it was impossible to connect any pair of points by straight-line 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.


POST-EDIT 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.

link

answered 15 Jun '15, 18:10

vvneagleone's gravatar image

5★vvneagleone
903
accept rate: 0%

edited 15 Jun '15, 18:34

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) rushilpaul4★

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) vvneagleone5★

Could not download paper. Please write normal editorial or give working link.

link

answered 15 Jun '15, 20:27

argos's gravatar image

7★argos
713
accept rate: 0%

@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 non-planar graph is K5, which is has more edges than 3*5-6/

link

answered 15 Jun '15, 15:41

madiyar's gravatar image

6★madiyar
211
accept rate: 0%

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.

link

answered 15 Jun '15, 18:58

xorfire's gravatar image

6★xorfire
1363
accept rate: 14%

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.

link

answered 15 Jun '15, 15:21

Amlesh's gravatar image

4★Amlesh
2393
accept rate: 0%

edited 15 Jun '15, 15:22

Please update the link to the Contest problem

link

answered 15 Jun '15, 15:44

krutarthkp800's gravatar image

4★krutarthkp800
334
accept rate: 0%

@madiyar the problem statement clearly states that we are to "try to place the given N points and M non-intersecting 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.

link

answered 15 Jun '15, 15:45

Amlesh's gravatar image

4★Amlesh
2393
accept rate: 0%

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) rushilpaul4★

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.

link

answered 15 Jun '15, 15:50

tapasjain01's gravatar image

6★tapasjain01
1063
accept rate: 0%

@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 :(

link

answered 15 Jun '15, 15:55

Amlesh's gravatar image

4★Amlesh
2393
accept rate: 0%

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*(n-1)/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.

link

answered 15 Jun '15, 21:43

shivamg_isc's gravatar image

5★shivamg_isc
6211210
accept rate: 0%

Case n=5, m=10 the answer is 0 while you are printing 1.

(17 Jun '15, 16:07) tapasjain016★

@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.

link

answered 15 Jun '15, 15:43

miteshag's gravatar image

5★miteshag
312
accept rate: 0%

edited 15 Jun '15, 15:47

I read it again just now. Now I see that your point is valid.

link

answered 15 Jun '15, 15:55

miteshag's gravatar image

5★miteshag
312
accept rate: 0%

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.

link

answered 15 Jun '15, 16:06

ushsh's gravatar image

6★ushsh
12
accept rate: 0%

I have had my time on this problem because of the misleading and ambiguous explanation. What I initially (and for several days) undertood was whether you can plot the N points in a plane such as no two intersect and adding one more STRAIGHT line would be impossible. There was a lot of red herring in the explanation:

  1. Why do the edges have to be straight? In no way does this change anything about the problem.
  2. What is with this sentence: "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." ? It has not much sense at all
  3. If the condition has to hold in any circumstance, WHY emphasize on the collinearity of the points? It makes no sense. This one drove me on the wrong track.

Other than that, the problem was nice, and maybe I would have learned the algorithm for this one, if I had undertood it properly sooner.

link

answered 15 Jun '15, 17:26

retrograd's gravatar image

6★retrograd
1503
accept rate: 12%

Edit: To clarify why the second point is a big contradiction to what the problem actually asks for:

"whether it's possible to choose N points in any way(this was in bold)". Whether it's possible means that we should analyze whether there is at least one way of doing it, then "any way" messes up the logic. If you really meant looking for a maximal planarity testing, you should have said:

"Whether, for any placement of the N points and M segments such as no two intersect, adding the M+1-th segment would break this property". This is much clearer and follows the rule of logic.

(15 Jun '15, 17:31) retrograd6★

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.

link

answered 15 Jun '15, 20:26

helthazar's gravatar image

6★helthazar
1
accept rate: 0%

@shivamg_isc

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...

link

answered 16 Jun '15, 00:20

checkmate1's gravatar image

1★checkmate1
1
accept rate: 0%

@shivamg_isc , agree with you. As the problem statement says the given m edges are non-intersecting. For n=5, and the optimal planar graph will have 9 edges (i.e. we cannot add more edge). Since they are not giving non-intersecting 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 non-intersecting edges. Am i wrong anywhere in understanding anything??

link

answered 16 Jun '15, 00:26

shubham201's gravatar image

3★shubham201
513
accept rate: 8%

edited 16 Jun '15, 00:40

@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 non-intersecting. So how they can give m=10 non-intersecting edges for n=5??? So one cannot say whats the answer for m=10 and n=5.

link

answered 16 Jun '15, 00:32

shubham201's gravatar image

3★shubham201
513
accept rate: 8%

@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 .

link

answered 16 Jun '15, 00:46

shivamg_isc's gravatar image

5★shivamg_isc
6211210
accept rate: 0%

Editorials are supposed to provide an opportunity for us to learn. Not point to a third party link! Wake up guys!

link

answered 16 Jun '15, 22:19

njr07121977's gravatar image

3★njr07121977
211
accept rate: 0%

link

answered 29 Jun '15, 14:44

yleewei's gravatar image

1★yleewei
8414
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×15,482
×1,329
×1,197
×156
×2

question asked: 15 Jun '15, 14:15

question was seen: 4,986 times

last updated: 20 Jul '15, 00:32