Universal Cup Judging System

Universal Cup

Süre Sınırı: 2.0 s Bellek Sınırı: 1024 MB Toplam puan: 100 Zorluk: [göster] Hack'lenebilir ✓
İstatistikler

Recordemos el Algoritmo de Tarjan para calcular los puntos de articulación (también llamados vértices de corte) en un grafo no dirigido, cuyo pseudocódigo se muestra en el Algoritmo 1.

Algorithm 1 The Correct Tarjan Algorithm
 1: function TARJAN(i, d)
 2:     visited[i] <- true
 3:     depth[i] <- d
 4:     low[i] <- d
 5:     childCount <- 0
 6:     isArticulation <- false
 7:
 8:     for each j in adj[i] do
 9:         if j = parent[i] then
10:             continue
11:         end if
12:         if not visited[j] then
13:             parent[j] <- i
14:             TARJAN(j, d + 1)
15:             childCount <- childCount + 1
16:             if low[j] >= depth[i] then
17:                 isArticulation <- true
18:             end if
19:             low[i] <- min(low[i], low[j])
20:         else
21:             low[i] <- min(low[i], depth[j])
22:         end if
23:     end for
24:     if (parent[i] != null and isArticulation)
        or (parent[i] = null and childCount > 1)
        then
25:         Output i as articulation point
26:     end if
27: end function
Algorithm 2 The Incorrect Trajan Algorithm
 1: function TRAJAN(i, d)
 2:     visited[i] <- true
 3:     depth[i] <- d
 4:     low[i] <- d
 5:     childCount <- 0
 6:     isArticulation <- false
 7:
 8:     for each j in adj[i] do
 9:         if j = parent[i] then
10:             continue
11:         end if
12:         if not visited[j] then
13:             parent[j] <- i
14:             TRAJAN(j, d + 1)
15:             childCount <- childCount + 1
16:             if low[j] >= depth[i] then
17:                 isArticulation <- true
18:             end if
19:         end if
20:         low[i] <- min(low[i], low[j])
21:
22:
23:     end for
24:     if (parent[i] != null and isArticulation)
        or (parent[i] = null and childCount > 1)
        then
25:         Output i as articulation point
26:     end if
27: end function

Observa que en el pseudocódigo, $\textit{adj}[i]$ es el arreglo que contiene todos los vértices adyacentes al vértice $i$, $\textit{parent}$ es un arreglo en el que el valor inicial de cada elemento es $\text{null}$, y $\textit{visited}$ es un arreglo en el que el valor inicial de cada elemento es $\text{false}$.

Algunos estudiantes pueden tener dificultades para comprender este algoritmo, especialmente desde la línea $19$ hasta la línea $22$. No entienden por qué el Algoritmo de Tarjan necesita calcular el valor de $\textit{low}[i]$ de forma diferente, y pueden quedarse con una versión incorrecta del algoritmo en mente. Llamemos a esta versión incorrecta el Algoritmo de Trajan, que se muestra en el Algoritmo 2. Observa que los algoritmos de Tarjan y de Trajan son casi iguales, salvo por los nombres de las funciones y las $4$ líneas que van de la línea $19$ a la línea $22$.

Dado un grafo conexo no dirigido con $n$ vértices y $m$ aristas, para cada vértice $u$ determina si existe un vértice $v$ y un arreglo $2$-dimensional $\textit{adj}$ ($\textit{adj}$ debe representar el grafo dado) tales que $\textsc{Tarjan}(v, 0)$ y $\textsc{Trajan}(v, 0)$ produzcan resultados diferentes en el vértice $u$ (es decir, que el Algoritmo de Tarjan indique que el vértice $u$ es un punto de articulación mientras que el Algoritmo de Trajan no lo haga, o viceversa).

Entrada

Hay múltiples casos de prueba. La primera línea de la entrada contiene un entero $T$ ($1 \le T \le 10^4$) que indica el número de casos de prueba. Para cada caso de prueba:

La primera línea contiene dos enteros $n$ y $m$ ($2 \le n \le 10^5$, $1 \le m \le 10^5$) que indican el número de vértices y aristas en el grafo dado.

En las siguientes $m$ líneas, la $i$-ésima línea contiene dos enteros $u_i$ y $v_i$ ($1 \le u_i, v_i \le n$) que indican que hay una arista conectando los vértices $u_i$ y $v_i$ en el grafo.

Se garantiza que el grafo dado es conexo y que no tiene bucles ni aristas múltiples. Además, ni la suma de $n$ ni la suma de $m$ en todos los casos de prueba superarán $10^6$.

Salida

Para cada caso de prueba, imprime una línea con algunos enteros separados por un espacio en orden creciente. Cada entero es un vértice en el que los algoritmos de Tarjan y de Trajan pueden producir resultados diferentes. Si no existen tales vértices, imprime Empty en una línea en su lugar.

Ejemplo

Entrada de ejemplo 1

2
9 12
1 3
2 3
1 2
3 6
6 9
9 3
4 6
5 6
4 5
7 9
8 9
7 8
2 1
1 2

Salida de ejemplo 1

3 6 9
Empty

Nota

Para el primer caso de prueba de ejemplo:

  • Para $u = 3$, considera $v = 1$ y $\textit{adj} = [[3, 2], [3, 1], [1, 2, 6, 9], [6, 5], [6, 4], [4, 5, 3, 9], [9, 8], [9, 7], [7, 8, 3, 6]]$.
  • Para $u = 6$, considera $v = 4$ y $\textit{adj} = [[2, 3], [1, 3], [9, 6, 2, 1], [6, 5], [6, 4], [4, 5, 3, 9], [9, 8], [9, 7], [7, 8, 3, 6]]$.
  • Para $u = 9$, considera $v = 7$ y $\textit{adj} = [[2, 3], [1, 3], [9, 6, 2, 1], [5, 6], [4, 6], [9, 3, 5, 4], [9, 8], [9, 7], [7, 8, 3, 6]]$.

Observa que todos los $\textit{adj}$ de la explicación están indexados desde $1$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.