P13002

[GCJ 2022 Finals] Goose, Goose, Ducks?

NOI/NOI+/CTSC

题目描述

The first international Geese conference just wrapped up, and even though it should have been a happy occasion, it was bittersweet. The organizers found a paper with detailed plans of a duck infiltration. Now, they are trying to identify the infiltrating group from among the attendees.

The document that they found contained a list of M\mathbf{M} triples of integers (Xi,Yi,Ci)(\mathbf{X}_i, \mathbf{Y}_i, \mathbf{C}_i) meaning the ducks would meet exactly Ci\mathbf{C}_i seconds after the start of the conference at point (Xi,Yi)(\mathbf{X}_i, \mathbf{Y}_i), which is Xi\mathbf{X}_i meters east and Yi\mathbf{Y}_i meters north of the center of the conference floor. Each goose may or may not have been at those specific points at those specific times, but every duck certainly was.

Both ducks and geese walk at a maximum speed of one meter per second, which means an attendee that is at point (x,y)(x, y) at time tt can reach any point of the form (x+Δx,y+Δy)(x + \Delta_x, y + \Delta_y) by time t+Δtt + \Delta_t as long as Δx2+Δy2≤Δt2\Delta_x^2 + \Delta_y^2 \leq \Delta_t^2. Each attendee's position at time 0 can be any point, independently of the other attendees.

After the discovery, the group held a questioning session to try to identify the ducks. During that session, attendees issued a series of statements, one at a time. The jj-th of those, in the order they were issued, was made by attendee Aj\mathbf{A}_j, claiming that both they and attendee Bj\mathbf{B}_j were at point (Uj,Vj)(\mathbf{U}_j, \mathbf{V}_j) exactly Dj\mathbf{D}_j seconds after the start of the conference. Points in statements may or may not be points where duck meetings happened.

Statements from geese are always true, but ducks may lie. Moreover, ducks know which attendees are ducks and which are geese. To avoid getting caught easily, ducks only make statements that are consistent with all statements previously made by geese. Note that statements made by geese are consistent with all ducks being at all duck meetings.

It may not be possible to determine all the ducks with the information provided. However, knowing the minimum number of ducks will at least provide a lower bound on the level of duck activity. Note that there was at least one duck. Find this minimum number of ducks.

Formally, a hypothesis HH is a partition of all attendees into a set of ducks (named HH-ducks) and geese (named HH-geese). HH is consistent with a set of statements SS if there exists a path for each attendee moving at most one meter per second such that:

  • all HH-ducks were at all duck meetings and
  • for each statement in SS claiming that AA saw BB at point PP at time TT, both AA and BB's paths went through point PP at time TT.

A hypothesis HH is feasible under a set of statements SS if:

  • HH-ducks is not empty (i.e., there was at least one duck),
  • the subset of all statements from SS made by members of HH-geese is consistent with HH (i.e., statements from geese are always true), and
  • for each statement s∈Ss \in S made by a member of HH-ducks, if P⊆SP \subseteq S is the subset of statements made by members of HH-geese issued before ss, there exists a hypothesis H′H' (which may or may not be equal to HH) such that {s}∪P\{s\} \cup P is consistent with H′H' (i.e., ducks do not contradict previous statements made by geese).

Notice that the hypotheses HH such that HH-ducks contains all attendees is always feasible.

Find the minimum size of HH-ducks over all feasible hypotheses HH.

输入格式

The first line of the input gives the number of test cases, T\mathbf{T}. T\mathbf{T} test cases follow. Each test case starts with a line containing three integers, N\mathbf{N}, M\mathbf{M}, and S\mathbf{S}, representing the numbers of attendees, duck meetings, and statements, respectively. The next M\mathbf{M} lines each describe a different duck meeting with three integers Xi\mathbf{X}_i, Yi\mathbf{Y}_i, and Ci\mathbf{C}_i, representing that there was a meeting at point (Xi,Yi)(\mathbf{X}_i, \mathbf{Y}_i), held exactly Ci\mathbf{C}_i seconds after the start of the conference. Then, the last S\mathbf{S} lines of a test case each describe a statement. The jj-th of these lines describes the jj-th issued statement with five integers Aj\mathbf{A}_j, Bj\mathbf{B}_j, Uj\mathbf{U}_j, Vj\mathbf{V}_j, and Dj\mathbf{D}_j, representing that attendee Aj\mathbf{A}_j stated that they and attendee Bj\mathbf{B}_j were both at point (Uj,Vj)(\mathbf{U}_j, \mathbf{V}_j) exactly Dj\mathbf{D}_j seconds after the start of the conference.

输出格式

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 minimum number of ducks that might have infiltrated the conference.

输入输出样例

输入样例 #1

text
2
2 1 2
1 2 3
1 2 1 1 1
2 1 2 2 2
4 2 4
4 3 10
-4 -3 20
1 3 4 3 11
2 4 0 0 16
3 1 6 3 9
4 2 0 0 16

输出样例 #1

text
Case #1: 1
Case #2: 2

说明/提示

Sample Explanation

In Sample Case #1, attendee 1 being the only duck is a feasible hypothesis.

In Sample Case #2, attendees 2 and 4 being the only ducks is a feasible hypothesis. Note that there is at least one duck, so all attendees being geese is not feasible.

Limits

  • 1≤T≤501 \leq \mathbf{T} \leq 50.
  • −109≤Xi≤109-10^9 \leq \mathbf{X}_i \leq 10^9, for all ii.
  • −109≤Yi≤109-10^9 \leq \mathbf{Y}_i \leq 10^9, for all ii.
  • 1≤Ci≤1091 \leq \mathbf{C}_i \leq 10^9, for all ii.
  • Ci<Ci+1\mathbf{C}_i < \mathbf{C}_{i+1}, for all ii.
  • (Xi−Xi+1)2+(Yi−Yi+1)2≤(Ci−Ci+1)2(\mathbf{X}_i - \mathbf{X}_{i+1})^2 + (\mathbf{Y}_i - \mathbf{Y}_{i+1})^2 \leq (\mathbf{C}_i - \mathbf{C}_{i+1})^2, for all ii.
  • 1≤Aj≤N1 \leq \mathbf{A}_j \leq \mathbf{N}, for all jj.
  • 1≤Bj≤N1 \leq \mathbf{B}_j \leq \mathbf{N}, for all jj.
  • Aj≠Bj\mathbf{A}_j \neq \mathbf{B}_j, for all jj.
  • −109≤Uj≤109-10^9 \leq \mathbf{U}_j \leq 10^9, for all jj.
  • −109≤Vj≤109-10^9 \leq \mathbf{V}_j \leq 10^9, for all jj.
  • 1≤Dj≤1091 \leq \mathbf{D}_j \leq 10^9, for all jj.
  • (Aj,Bj,Uj,Vj,Dj)≠(Ak,Bk,Uk,Vk,Dk)(\mathbf{A}_j, \mathbf{B}_j, \mathbf{U}_j, \mathbf{V}_j, \mathbf{D}_j) \neq (\mathbf{A}_k, \mathbf{B}_k, \mathbf{U}_k, \mathbf{V}_k, \mathbf{D}_k), for all j≠kj \neq k.

Test Set 1 (11 Pts, Visible Verdict)

  • Time limit: 20 seconds.
  • 2≤N≤502 \leq \mathbf{N} \leq 50.
  • 1≤M≤501 \leq \mathbf{M} \leq 50.
  • 1≤S≤501 \leq \mathbf{S} \leq 50.

Test Set 2 (24 Pts, Hidden Verdict)

  • Time limit: 60 seconds.
  • 2≤N≤1052 \leq \mathbf{N} \leq 10^5.
  • 1≤M≤1051 \leq \mathbf{M} \leq 10^5.
  • 1≤S≤1051 \leq \mathbf{S} \leq 10^5.

🚀 提交评测

登录并绑定洛谷账号后即可在此在线提交代码并实时评测。

前往登录

💡 题解 (0)

登录后即可撰写并分享您的解题思路。

暂无题解,快来发布全站第一篇题解吧!

💬 题目讨论 (0)

登录后可以发起或参与讨论。

暂无讨论内容。

📊 题目信息

题号P13002
难度NOI/NOI+/CTSC
时间限制20000 ms
内存限制1024 MB
题目来源洛谷题库
算法标签
强连通分量

⚡ 快速操作

在线提交代码在洛谷打开原题 ↗