#P10809. [LMXOI Round 2] Nirvana

    ID: 11879 远端评测题 2200ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>Special JudgeO2优化双连通分量圆方树

[LMXOI Round 2] Nirvana

Background

HQZ is tinkering with a machine made by LMX.

Problem Description

An undirected connected graph is defined to be good if and only if there exists an orientation of all edges such that the original graph can be turned into a directed acyclic graph in which only SS has in-degree 00 and only TT has out-degree 00.

Given an undirected connected graph with nn vertices and mm edges, with no self-loops, define one operation as choosing two (possibly identical) vertices x,yx, y uniformly at random with xyx \le y, and adding an edge between xx and yy. Let PP be the probability that the graph after one operation is good. Output Pmod998244353P \bmod 998244353.

If P>0P > 0, you need to construct an orientation after adding one edge.

If P=0P = 0, you need to construct a plan that deletes the minimum number of vertices so that the original graph becomes good.

Input Format

The first line contains four positive integers n,m,S,Tn, m, S, T, as described above.

The next mm lines each contain two positive integers xi,yix_i, y_i, indicating an undirected edge between xix_i and yiy_i.

Output Format

The first line contains a non-negative integer PP.

If P>0P > 0, output the next two lines. The first of these lines contains two positive integers u,vu, v, indicating that the edge you add is the directed edge uvu \to v. The second line contains a string ss of length mm consisting only of 00 and 11. If si=0s_i = 0, then the direction of edge (xi,yi)(x_i, y_i) is xiyix_i \to y_i; otherwise it is yixiy_i \to x_i.

If P=0P = 0, output the next two lines. The first of these lines contains a positive integer cc, indicating the minimum number of vertices to delete. The second line contains cc positive integers, indicating the vertices to delete.

Scoring:

If the output format is correct, then if your program correctly outputs the probability PP, you will get 30%30\% of the score for that test point.

On top of that, if you also construct a correct plan, you will get 100%100\% of the score for that test point.

If your program has an incorrect output format, unexpected errors may occur.

5 8 1 4
1 2
2 3
3 4
4 5
1 3
1 4
2 4
3 5
665496236
1 2
00010000
6 5 5 6
1 2
1 3
1 4
1 5
1 6
0
3
2 3 4
9 9 1 7
1 3
2 3
3 4
3 5
4 5
4 6
5 7
4 8
8 9
0
4
2 6 8 9

Hint

For all data, 1n,m5×1051 \le n, m \le 5 \times 10^5.

update 7/27: Subtask #7 is new hack testdata. The constraints are the same as Subtask #6.

Subtask # nn mm Special Property Score
Subtask #1 10\le 10 None 2525
Subtask #2 500\le 500 =n1= n - 1 xi=i,yi=i+1x_i = i, y_i = i + 1 1010
Subtask #3 5×105\le 5 \times 10^5 =n= n The original graph is a cycle 55
Subtask #4 500\le 500 None 2020
Subtask #5 5×105\le 5 \times 10^5 =n1= n - 1 xi=i,yi=i+1x_i = i, y_i = i + 1
Subtask #6 5×105\le 5 \times 10^5 None

Translated by ChatGPT 5