Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) F 构造

http://codeforces.com/contest/967/problem/F

 

Topic meaning:

An undirected graph with n points and n*(n-1)/2 edges, of which m paths are currently open (that is, can be walked), and the rest are closed

Definition: After going from x to y (ie x->y), all the states of the edges connected to x are reversed (ie on->off, off->on)

Ask, from the starting point 1 to the ending point n, at least a few steps are required, and this path is output (if there are multiple shortest paths, output any one)

If not present, output -1

 

Ideas:

In fact, this question looks like bfs at first glance, but every state is changing, so the complexity of bfs is increasing exponentially, definitely tle

After drawing a picture, you will find that there are the following problems.

For a graph with a+1 points and b edges (where the end point, that is, the point a+1 has no edge connected to it), if b=a*(a-1)/2, then, no matter what They can't get to the point of a+1.

So, the problem is transformed into, if b<a*(a-1)/2 takes a few steps.

So we can find that in the case of b<a*(a-1)/2, we can find the case of bb=aa*(aa-1)/2. where bb represents a subset of b and aa represents a subset of a

So continue to analyze, and finally only get two cases

 

The first:

The case of a=3, b=2 (Note, a=4 is the end point, which was defined earlier = =)

Graphics: ①->②->③

That is, the number of steps in this case is 4 steps, that is, 1->2->3->1->4

 

The second:

a=4, b=5

(= =) a total of 4 points, tell you the side, you can draw it yourself

The sides are:

1 2

2 3

3 4

4 1

1 3

In this case the number of steps is 5

 

Of course, there may be cases where the number of steps <= 4, that is, starting from 1 and going directly to the end according to the side given by the question, I don't need to say this! ! !

So there is no such thing as le6 mentioned in output.

Retired players can only help you here = =!

Then look at yourself~0~

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325137069&siteId=291194637