Блог пользователя Alireza_Asadi

Автор Alireza_Asadi, история, 5 лет назад, По-английски

Hi Everyone! I encountered a problem a few weeks ago and came up with an idea but I got TLE (explained in the comments) and idk how to make it better. Will you plz help me solve it?
The problem statement is as follows:
We have decided to add signs to the map for logistics team drivers to use. A simplified model of the map is defined as a graph in which all the edges of the street are two-sided and the vertices represent positions with unique names.
For this reason, John :) intends to add a sign to the map called "Obligatory turn!". Consider street e connects position v to position w. At position vs entrance to street e an "Obligatory turn!" sign will be installed if by entering street e from v, the driver has to turn 180 degrees to return to position v.
Also, to simplify the map, we intend to add the minimum number of "Obligatory turn!" signs. We do this with the rule that if at the entrance of the position v to street e an "Obligatory turn!" is installed and at the entrance of position x to street f another "Obligatory turn!" is installed too, assuming that entering from position v and passing through street e it is possible to reach position x and then to street f without making any turns, then the sign "Obligatory distance!" from x is not necessary and should be deleted.
In this question, John asks you to help him find the places where we should install this sign. Sample Image

INPUT
In the first line of the input, two numbers are given, m and n, where n is the number of positions(nodes) and m is the number of streets(edges). In the next m lines, the numbers v and w are given, indicating that there is a two-way street between the positions v and w. Also, all pairs of positions are unique at the input.

1 <= n,m <= 5*10^5

OUTPUT
In the first line, output k, which indicates the number of signs required. In the next k lines, output two integers each line, v and w, indicating that the "Obligatory turn!" sign must be installed at the entrance of the position v to the street between v and w. The output lines of the position of the signs should be printed in ascending order with respect to v, and in term of equality of vs, ascending with respect to w.

TEST CASE 1

INPUT
6 5
1 2
1 3
2 3
4 5
5 6
OUTPUT 
2
4 5
6 5

TEST CASE 2

INPUT
8 8
1 2
1 3
2 3
3 4
1 5
1 6
6 7
6 8
OUTPUT
3
1 5
1 6
3 4

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

Автор Alireza_Asadi, история, 5 лет назад, По-английски

Hi Everyone! I have asked this question on stackexchange and got no chance getting an answer to my problem. Will you plz help me solve it?

I have come up with a solution but I don't exactly know if it is true. I think for the tallest possible height, we can always get to that by adding d to the highest tower. and for the lowest possible height, we can get the min of the array and add 1 to its m neighboring towers in a for loop and keep doing this again. finally the tallest tower will have the minimum height. Am I correct?

Полный текст и комментарии »

  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится