問題一覧 > 教育的問題

No.2274 Triangle Coloring

レベル : / AI推定難易度 : 1800 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 10
作問者 : 👑 p-adic / テスター : ecottea
お気に入りにしたユーザー ProblemId : 9231 / 自分の提出
問題文最終更新日: 2023-03-02 18:08:50
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 384 (順位表) の他の問題:

Problem Statement

The input gives $4$ positive integers $N, M, B, Q$, an undirected multigraph $G$ with $N$ vertices and $M$ edges, and $Q$ queries (described later).

Here, an undirected multigraph refers to one that has no self-loops.

 

The vertices of $G$ are numbered with the non-negative integers $n$ less than $N$ and called "vertex $n$", and the edges of $G$ are numbered with the non-negative integers $m$ less than $M$ and called "edge $m$". The $2$ vertices connected by edge $m$ are denoted vertex $i_m$ and vertex $j_m$ ($i_m, j_m$ are integers satisfying $0 \leq i_m < j_m < N$).

For $3$ non-negative integers $m_0, m_1, m_2$ less than $M$, we write $\triangle m_0 m_1 m_2$ to mean that edge $m_0$, edge $m_1$, and edge $m_2$ form a cycle passing through $3$ vertices.

Each query is a tuple $(m_0,m_1,m_2)$ of $3$ non-negative integers $m_0, m_1, m_2$ less than $M$ satisfying the following $2$ conditions:

  • $m_0 < m_1 < m_2$
  • $\triangle m_0 m_1 m_2$

Also, edge $m_0$, edge $m_1$, and edge $m_2$ are called "the $3$ edges of triangle $(m_0,m_1,m_2)$".

 

Consider ways of painting the edges of $G$ using only white and black. The notion of a way of painting is defined precisely using the notion of coloring. (Click to expand)

 

Let $E$ be the set of all edges of $G$, and fix $2$ sets $W$ and $B$ corresponding to white and black. They may be fixed in any way; one common choice is, for example, $W = \{\}$, $B = \{\{\}\}$.

A $\{W,B\}$-coloring of $E$ is a map from $E$ to $\{W,B\}$. In particular, when $W = \{\}$ and $B = \{\{\}\}$, a $\{W,B\}$-coloring is called a $2$-coloring. Given a $\{W,B\}$-coloring of $E$, by interpreting edges with value $W$ as painted white and edges with value $B$ as painted black, we mathematically formalize the notion of a way of painting the edges of $G$ (with white and black) as the $\{W,B\}$-coloring of $E$ itself.

In this formalization, things such as "the order in which edges are painted" are not taken into account. In particular, by considering the necessary and sufficient condition for two maps to coincide, we see that $2$ ways of painting $f$ and $g$ are equal if and only if, for every edge $e$ of $G$, the color of $e$ in $f$ equals the color of $e$ in $g$.

 

There are $2^M$ ways of painting in total; among them, a way of painting satisfying the following condition is called a "good painting":

  • For every non-negative integer $n$ less than $N$, the number of white edges having vertex $n$ as an endpoint is even.

When sets $S$ and $T$ of good paintings are determined by the following procedure, find the remainders when the numbers of elements of the final $S$ and $T$, respectively, are divided by $B$.

  1. First, let $S$ be the set of all "good paintings that paint at least $1$ edge white", and let $T$ be the set consisting only of the "good painting that paints all edges black".
  2. Then, each time a query $(m_0,m_1,m_2)$ is given, every good painting $c$ belonging to $S$ that satisfies the following condition is removed from $S$ and added to $T$:
    • There exists a good painting $c'$ belonging to $T$ such that the painting obtained from $c'$ by changing the colors of all $3$ edges of triangle $(m_0,m_1,m_2)$ is $c$.

Input

The input is given from standard input in the following format:

  • On line $1$, $N, M, B, Q$ are given, separated by single spaces.
  • For each non-negative integer $m$ less than $M$, $i_m, j_m$ are given on line $2 + m$, separated by single spaces.
  • For each positive integer $q$ not exceeding $Q$, the components of the $q$-th query are given on line $1 + M + q$, separated by single spaces.

Constraints

The input satisfies the following constraints:

  • $N$ is an integer satisfying $3 \leq N \leq 10^{18}$
  • $M$ is an integer satisfying $3 \leq M \leq 4 \times 10^2$
  • $B$ is an integer satisfying $2 \leq B \leq 10^9$
  • $Q$ is an integer satisfying $1 \leq Q \leq 10^3$
  • For each non-negative integer $m$ less than $M$, $i_m, j_m$ are integers satisfying $0 \leq i_m < j_m < N$
  • For each positive integer $q$ not exceeding $Q$, the components $m_0, m_1, m_2$ of the $q$-th query $(m_0,m_1,m_2)$ are integers satisfying $0 \leq m_0 < m_1 < m_2 < M$ and $\triangle m_0 m_1 m_2$

Output

Print the remainders when the numbers of elements of the final $S$ and $T$ are divided by $B$, separated by a single space, on $1$ line.

Print a newline at the end.

Sample

Sample 1
Input
3 3 2 1
0 1
1 2
0 2
0 1 2
Output
0 0

Initially, $S$ contains only

  • the good painting that paints all edges white

and $T$ contains only

  • the good painting that paints all edges black.

When the query $(0,1,2)$ is given,

  • the good painting that paints all edges white,

which is the painting obtained from the latter by changing the colors of all $3$ edges of triangle $(0,1,2)$, is removed from $S$ and added to $T$.

Therefore, the final numbers of elements of $S$ and $T$ are $0$ and $2$, and their remainders when divided by $B = 2$ are $0$ and $0$.

Sample 2
Input
3 4 3 1
0 1
0 1
1 2
0 2
0 2 3

Multiple edges may connect the same $2$ vertices.

Output
2 2

Initially, $S$ contains

  • the good painting that paints edge $0$ black and the rest white,
  • the good painting that paints edge $1$ black and the rest white,
  • the good painting that paints edge $2$ and edge $3$ black and the rest white,

and $T$ contains only

  • the good painting that paints all edges black.

When the query $(0,2,3)$ is given,

  • the good painting that paints edge $1$ black and the rest white,

which is the painting obtained from the good painting belonging to $T$ by changing the colors of all $3$ edges of triangle $(0,2,3)$, is removed from $S$ and added to $T$.

Therefore, the final numbers of elements of $S$ and $T$ are $2$ and $2$, respectively, and their remainders when divided by $B = 3$ are $2$ and $2$.

Sample 3
Input
3 4 3 2
0 1
0 1
1 2
0 2
0 2 3
1 2 3
Output
0 1

The situation after processing query number $1$ is the same as the final situation of Sample Case 2. Therefore, $S$ contains

  • the good painting that paints edge $0$ black and the rest white,
  • the good painting that paints edge $2$ and edge $3$ black and the rest white,

and $T$ contains

  • the good painting that paints all edges black,
  • the good painting that paints edge $1$ black and the rest white.

When query number $2$, $(1,2,3)$, is given,

  • the good painting that paints edge $0$ black and the rest white,
  • the good painting that paints edge $2$ and edge $3$ black and the rest white,

which are the good paintings obtained from the good paintings belonging to $T$ by changing the colors of all $3$ edges of triangle $(1,2,3)$, are removed from $S$ and added to $T$.

Therefore, the final numbers of elements of $S$ and $T$ are $0$ and $4$, respectively, and their remainders when divided by $B = 3$ are $0$ and $1$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。