아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

The Decades of Coding Competitions

메모리 제한1024 MB

요약
각 변에 색이 칠해진 무방향 그래프에서 질의 (P, C)마다 P에서 C로 가는 어떤 보행이 홀수 개의 서로 다른 색을 지날 수 있는지 판정한다.
난이도

보통10점 중 7점

유형
그래프, 비트 연산, 유니온 파인드, BFS
정답자
아직 제출이 없습니다

문제

It has been almost 1515 years since Sphinny became the premiere programming contestant by mastering the art of scheduling contests. She has grown alongside Coding Competitions and graduated into a programming contest organizer, and her Programming Club League (PCL) is the most popular sport in her city.

There are N\mathbf{N} bus stops in Sphinny's city, and M\mathbf{M} express bus routes. Each route bidirectionally connects two different bus stops, called their endpoints. Because of the popularity of PCL, the driver of each bus routes cheers for exactly one club.

Sphinny has to pick up the contest materials for the jj-th contest at bus stop P_j\mathbf{P\_j} and then the contest will be run in bus stop C_j\mathbf{C\_j}. She can only use the given bus routes to travel between them. Formally, a path for Sphinny to go from P_j\mathbf{P\_j} to C_j\mathbf{C\_j} is a list of bus routes such that each two consecutive routes have a common endpoint. Also the first route in the path has P_j\mathbf{P\_j} as an endpoint and the last one has C_j\mathbf{C\_j} as an endpoint. Notice that the same bus route can be used multiple times in a path. If Sphinny's path from P_j\mathbf{P\_j} to C_j\mathbf{C\_j} contains one or more bus routes whose driver cheers for club cc, then club cc will join the contest. Otherwise, club cc will not join the contest. For organizational reasons, Sphinny needs the number of clubs in each contest to be an odd number.

Given the layout of Sphinny's city's bus routes and the contests' details, find out for how many contests there exists a path for Sphinny to take that can ensure an odd number of clubs joining it.

입력

The first line of the input gives the number of test cases, T\mathbf{T}. T\mathbf{T} test cases follow. The first line of each test case contains three integers N\mathbf{N}, M\mathbf{M}, and Q\mathbf{Q}: the number of bus stops, bus routes, and contests, respectively.

Then, M\mathbf{M} lines follow representing a different bus route each. The ii-th of these lines contains three integers U_i\mathbf{U\_i}, V_i\mathbf{V\_i}, and K_i\mathbf{K\_i}, meaning that the ii-th bus route connects bus stops U_i\mathbf{U\_i} and V_i\mathbf{V\_i} and its driver cheers for club K_i\mathbf{K\_i}.

Finally, the last Q\mathbf{Q} lines represent a contest each. The jj-th of these lines contains two integers P_j\mathbf{P\_j} and C_j\mathbf{C\_j}, representing that materials for the jj-th contest need to be picked up at bus stop P_j\mathbf{P\_j} and the contest needs to be run at bus stop C_j\mathbf{C\_j}.

출력

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is the number of contests for which Sphinny can find a path that ensures an odd number of clubs join it.

제한

  • 1≤T≤1001 \le \mathbf{T} \le 100.
  • 1≤U_i≤N1 \le \mathbf{U\_i} \le \mathbf{N}, for all ii.
  • 1≤V_i≤N1 \le \mathbf{V\_i} \le \mathbf{N}, for all ii.
  • U_i≠V_i\mathbf{U\_i} \neq \mathbf{V\_i}, for all ii
  • (U_i,V_i)≠(U_j,V_j)(\mathbf{U\_i}, \mathbf{V\_i}) \neq (\mathbf{U\_j}, \mathbf{V\_j}) and (U_i,V_i)≠(V_j,U_j)(\mathbf{U\_i}, \mathbf{V\_i}) \neq (\mathbf{V\_j}, \mathbf{U\_j}), for all i≠ji \neq j. (No two bus routes have the same pair of endpoints.)
  • 1≤P_j≤N1 \le \mathbf{P\_j} \le \mathbf{N}, for all jj.
  • 1≤C_j≤N1 \le \mathbf{C\_j} \le \mathbf{N}, for all jj.
  • P_j≠C_j\mathbf{P\_j} \neq \mathbf{C\_j}, for all jj.

예제2

  1. 예제 1

    입력
    2
    5 5 3
    1 2 1
    2 3 2
    2 4 1
    2 5 1
    4 5 1
    1 3
    3 4
    5 1
    3 1 2
    1 3 1
    1 2
    1 3
    
    예상 출력
    Case #1: 1
    Case #2: 1
    
  2. 예제 2

    입력
    1
    4 5 2
    1 2 3
    1 3 3
    3 4 7
    2 3 3
    2 4 6
    1 2
    1 4
    
    예상 출력
    Case #1: 2