luogu#P6722. 「MCOI-01」Village 村庄

    ID: 3945 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划 DP搜索图论二分图树的直径

「MCOI-01」Village 村庄

Background

Today, the kind and lovely 0x3 Miaojang rode a little pony to a village.

“Eh, the layout of this village...” “Feels like the place where I played Ciste before, qwq.”

0x3 Miaojang has a map that contains information about this village.

Then 0x3 Miaojang wants to use this map to determine whether Ciste has a solution or not.

Note: Ciste is a treasure-map game in Is the Order a Rabbit?.

Problem Description

The village is simplified into an undirected connected graph with nn nodes (numbered from 11 to nn) and n1n-1 edges.

0x3 Miaojang thinks the information in this undirected graph is related to a new graph that satisfies the following conditions:

  • The vertex set of the new graph is the same as that of the original graph.
  • In the new graph, there is an undirected edge between uu and vv if and only if dis(u,v)kdis(u,v) \ge k in the original graph (kk is a given constant, and dis(u,v)dis(u,v) is the length of the shortest path from node uu to node vv).

0x3 Miaojang also believes that if this "new graph" is a bipartite graph, then Ciste "has a solution"; if this "new graph" is not a bipartite graph, then this Ciste "has no solution". (If you do not know what a bipartite graph is, please see the Hint.)

So 0x3 Miaojang would like you to determine whether this Ciste "has a solution".

Input Format

The first line contains a positive integer TT, meaning there are TT test cases.
For each test case, the first line contains two positive integers n,kn,k. Then follow n1n-1 lines, each containing three positive integers x,y,vx,y,v, meaning there is an undirected edge of weight vv between node xx and node yy.
The input is guaranteed to be valid.

Output Format

For each test case, output one line: if it "has a solution", output Yes, otherwise output Baka Chino.

5
5 2
1 2 1
2 3 1
3 4 1
4 5 1
5 3
1 2 1
2 3 1
3 4 1
4 5 1
5 8
1 3 3
1 2 1
2 4 6
2 5 2
5 2
1 3 3
1 2 1
2 4 6
2 5 2
7 4
1 2 3
1 3 3
2 5 3
2 6 3
3 7 3
2 4 2
Baka Chino
Yes
Yes
Baka Chino
Baka Chino

Hint

Sample Explanation

For the first test case in the samples:

Original graph:

New graph:

The new graph is not bipartite, so output Baka Chino.

For the third test case in the samples:

Original graph:

New graph:

The new graph is bipartite, so output Yes.

Constraints

This problem uses bundled testdata.

  • Subtask 1 (16 pts): n10n \le 10.
  • Subtask 2 (24 pts): n100n \le 100.
  • Subtask 3 (8 pts): n1000n \le 1000.
  • Subtask 4 (28 pts): the graph degenerates into a chain.
  • Subtask 5 (24 pts): no special restrictions.

For 100%100\% of the testdata, n105n \le 10^5, T10T \le 10, v1000v \le 1000, k1000000k \le 1000000.

The testdata of this problem is generated using CYaRon.

Hint

A bipartite graph (also called a bipartite graph / "erbufen tu") is a special model in graph theory. Let G=(V,E)G=(V,E) be an undirected graph. If the vertex set VV can be divided into two disjoint subsets (A,B)(A,B), and every edge (i,j)(i,j) in the graph connects two vertices ii and jj that belong to these two different sets respectively (iA,jB)(i \in A,j \in B), then the graph GG is called a bipartite graph. (Quoted from Baidu Baike.)

Notes

Minecraft OI Round 1 A

  • Idea: 0x3 Miaojang.
  • Solution/Std: 0x3 Miaojang.
  • Data: 0x3 Miaojang.
  • Tester: tarjin.

Translated by ChatGPT 5