1 A colorful run Mr Brdrcrbri is a fitness coach of 2I1T Bhagyanagar. He wants his…
- User
1 A colorful run Mr Brdrcrbri is a fitness coach of 2I1T Bhagyanagar. He wants his students to remain healthy, but the“divoc” pandemic has made this difficult for him. Since he is a man of science, he has decided to separate the students into q different groups and tell them to maintain one hand distance while running wearing a mask. He has come up with a map of 2I1T Bhagyanagar. There are n checkpoints, and m roads connecting these checkpoints. He has assigned every road a color c. He plans on making group i run from a checkpoint ui to vi using roads of a single color. After drawing the map he gave you and your friend, “raseaC”, the task to count the number of colors using which group i can go from ui to vi using roads of a single color, but in typical 2I1T Bhagyanagar custom, you shifted the work by 17 days to do it on the final day. Quickly come up with the answers to the q queries Mr Brdrcrbri asks you. 1.1 Input format The first line contains two integers, n(2 ≤ n ≤ 100) and m(1 ≤ m ≤ 1000), denoting the number of checkpoints and the number of roads respectively. The next m lines contain three integers, ai , bi(1 ≤ ai < bi ≤ n) and ci(1 ≤ c ≤ m), denoting a road joining the checkpoints ai and bi with color ci . The roads are undirected, you can travel from ai to bi and from bi to ai using the same road. The next line contains a integer q(1 ≤ q ≤ 100), the number of groups. Then the next q lines contain two integers ui and vi(1 ≤ ui , vi ≤ n, ui ̸= vi), the starting and ending checkpoint of group i. Note, it is not necessary for all checkpoints to be connected by roads. 1.2 Output format Output q integers, where the i th line denotes the number of colors such that it is possible to travel from ui to vi using only a single color. 1 1.3 Examples 1.3.1 1 Input Output 7 7 2 1 2 1 1 1 7 2 0 2 3 1 0 2 4 3 2 5 3 2 7 2 3 5 3 4 1 2 3 4 1 4 2 6 1
- Assistant
- User
no check for all paths not just direct edges
- Assistant
- User
give cpp code
- Assistant