## Kevin Needs Help

View as PDF

Points: 20
Time limit: 1.0s
Memory limit: 256M

Author:
Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Kevin is planning something and needs your help, Kevin needs your help to check if two paths on a weighted tree are identical.

For two paths to be identical, the edges in which the two paths travel in are equal. In other words, given two paths (say one from to and one from to ) the weight of the edge of the first path is equal to the weight of the edge of the second path. Both paths must have the same number of edges to be identical

If two paths are identical, print T, else print F.

#### Input Specification

The first line will contain and , the number of nodes in the weighted tree and the number of queries.

The next lines will contain , , and , a bidirectional edge from node to of weight .

The next lines will contain , , , and , Kevin asking if path to is identical to path to .

#### Output Specification

Print lines, the answer to each query.

#### Sample Input 1

10 5
1 2 1
2 3 2
3 4 3
4 5 4
3 6 5
7 3 2
8 3 3
9 7 1
8 10 4
9 5 1 10
9 10 1 5
10 9 5 1
7 8 2 4
10 9 1 5

#### Sample Output 1

T
T
T
T
F