CF1499G.Graph Coloring

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a bipartite graph consisting of n1n_1 vertices in the first part, n2n_2 vertices in the second part, and mm edges, numbered from 11 to mm . You have to color each edge into one of two colors, red and blue. You have to minimize the following value: vVr(v)b(v)\sum \limits_{v \in V} |r(v) - b(v)| , where VV is the set of vertices of the graph, r(v)r(v) is the number of red edges incident to vv , and b(v)b(v) is the number of blue edges incident to vv .

Sounds classical and easy, right? Well, you have to process qq queries of the following format:

  • 11 v1v_1 v2v_2 — add a new edge connecting the vertex v1v_1 of the first part with the vertex v2v_2 of the second part. This edge gets a new index as follows: the first added edge gets the index m+1m + 1 , the second — m+2m + 2 , and so on. After adding the edge, you have to print the hash of the current optimal coloring (if there are multiple optimal colorings, print the hash of any of them). Actually, this hash won't be verified, you may print any number as the answer to this query, but you may be asked to produce the coloring having this hash;
  • 22 — print the optimal coloring of the graph with the same hash you printed while processing the previous query. The query of this type will only be asked after a query of type 11 , and there will be at most 1010 queries of this type. If there are multiple optimal colorings corresponding to this hash, print any of them.

Note that if an edge was red or blue in some coloring, it may change its color in next colorings.

The hash of the coloring is calculated as follows: let RR be the set of indices of red edges, then the hash is (iR2i)mod998244353(\sum \limits_{i \in R} 2^i) \bmod 998244353 .

Note that you should solve the problem in online mode. It means that you can't read the whole input at once. You can read each query only after writing the answer for the last query. Use functions fflush in C++ and BufferedWriter.flush in Java languages after each writing in your program.

输入格式

The first line contains three integers n1n_1 , n2n_2 and mm ( 1n1,n2,m21051 \le n_1, n_2, m \le 2 \cdot 10^5 ).

Then mm lines follow, the ii -th of them contains two integers xix_i and yiy_i ( 1xin11 \le x_i \le n_1 ; 1yin21 \le y_i \le n_2 ) meaning that the ii -th edge connects the vertex xix_i from the first part and the vertex yiy_i from the second part.

The next line contains one integer qq ( 1q21051 \le q \le 2 \cdot 10^5 ) — the number of queries you have to process.

The next qq lines contain the queries in the format introduced in the statement.

Additional constraints on the input:

  • at any moment, the graph won't contain any multiple edges;
  • the queries of type 22 are only asked if the previous query had type 11 ;
  • there are at most 1010 queries of type 22 .

输出格式

To answer a query of type 11 , print one integer — the hash of the optimal coloring.

To answer a query of type 22 , print one line. It should begin with the integer kk — the number of red edges. Then, kk distinct integer should follow — the indices of red edges in your coloring, in any order. Each index should correspond to an existing edge, and the hash of the coloring you produce should be equal to the hash you printed as the answer to the previous query.

If there are multiple answers to a query, you may print any of them.

输入输出样例

  • 输入#1

    3 4 2
    1 2
    3 4
    10
    1 1 3
    1 2 3
    2
    1 3 3
    2
    1 2 4
    2
    1 2 1
    1 1 1
    2

    输出#1

    8
    8
    1 3
    40
    2 3 5
    104
    3 5 6 3
    104
    360
    4 5 6 3 8
首页