| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 2048 MB | 39 | 12 | 12 | 34.286% |
Bessie is designing a nuclear reactor to power Farmer John's lucrative new AI data center business, CowWeave!
The reactor core consists of $N$ ($1\le N \le 2\cdot 10^5$) fuel rods, numbered $1$ through $N$. The $i$-th rod has a "stable operating range" $[l_i, r_i]$ ($-10^9 \leq l_i \leq r_i \leq 10^9$), meaning it can only generate power if its energy $a_i$ (chosen by Bessie) satisfies $l_i \le a_i \le r_i$; otherwise, it sits idle and does not generate power. Moreover, $a_i$ must always be an integer. Note that $a_i$ can be any integer, not limited to $[-10^9, 10^9]$.
However, quantum interactions between the rods mean that there are $M$ constraints of the form $(x, y, z)$ where Bessie must satisfy $a_x + a_y = z$ ($1 \leq x,y \leq N$ and $-10^9\le z\le 10^9$) to prevent the reactor from melting down.
Help Bessie find the maximum number of power-generating rods she can achieve in her design without it melting down!
The first line contains $T$ ($1\le T\le 10$), the number of independent tests. Each test is specified in the following format:
It is guaranteed that neither the sum of $N$ nor the sum of $M$ over all tests exceeds $4\cdot 10^5$.
If no choice of rod energies exists that satisfies all constraints, output $-1$. Otherwise, output the maximum number of power-generating rods Bessie can achieve.
2 3 3 1 2 3 1 2 3 1 1 2 2 2 10 1 1 4 3 2 1 2 3 1 2 3 1 1 2 2 2 10
-1 2
In the second test, the constraints require that:
Choosing energies $a=[1, 5, 3]$ results in $2$ power-generating rods because:
and $a$ satisfies all required constraints.
1 3 2 10 -10 10 10 -10 10 1 2 0 2 3 0
3
Choosing rod energies $a=[10, -10, 10]$ results in $3$ power-generating rods.
5 3 3 1 -1 0 2 1 2 1 2 1 1 3 4 2 3 3 1 1 -100 100 1 1 3 1 1 -100 100 1 1 2 1 2 -100 100 1 1 2 1 1 4 1 2 -100 100 1 1 2 1 1 2
2 -1 1 -1 1