cf/mirror

Words on Tree

CF
1657F2600· international gm9s1024 MB⌨ stdin/stdout

Examples

Sample 1of 4
Input
3 2
2 3
2 1
2 1 ab
2 3 bc
Output
YES
abc
Sample 2of 4
Input
3 2
2 3
2 1
2 1 ab
2 3 cd
Output
NO
Sample 3of 4
Input
10 10
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 2 ab
1 3 ab
1 4 ab
1 5 ab
1 6 ab
1 7 ab
1 8 ab
1 9 ab
1 10 ab
10 2 aba
Output
YES
baaaaaaaaa
Sample 4of 4
Input
10 10
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 2 ab
1 3 ab
1 4 aa
1 5 ab
1 6 ab
1 7 ab
1 8 ab
1 9 ab
1 10 ab
10 2 aba
Output
NO
1657F.cpp
loading editor…
Ln 11·137 BGNU C++20 (64)
loading graph engine…