406073: GYM102254 F Friendship Matters

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. Friendship Matterstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

At IME++, students learn multiple algorithms and data structures and usually participate in contests. Some contests are individual, others are in trios and some, rare ones, are in groups of any size.

In $$$2019$$$ one of the rare any-group-size contests appeared, so every student of IME++ decided to participate. Although the contest have no size limits, some students don't work so well with others, so they decided that each student will start in it's own team and then the teams will be joining others.

You are responsible to verify if the students are happy with the teams or not, so you know ahead of time which student pairs don't work very well together and, while the teams are getting decided, you want to know if a pair of students are in the same team or not.

IME++ has $$$n$$$ students, you know the first name of each student (the size of the names are at most 10 English letters with the first letter uppercase and the rest lowercase, all names are distinct), also there are $$$q$$$ queries of two types:

  • $$$1$$$ $$$student_1$$$ $$$student_2$$$: join groups containing $$$student_1$$$ and $$$student_2$$$;
  • $$$2$$$ $$$student_1$$$ $$$student_2$$$: ask if $$$student_1$$$ and $$$student_2$$$ are in the same group or not.
Input

The first line of input contains two integers, $$$n$$$ and $$$q$$$ ($$$2 \le n \le 10^5$$$, $$$1 \le q \le 10^5$$$) — the number of students at IME++ and the number of queries, respectively.

The next $$$n$$$ lines contains, each, one string, $$$s_i$$$ ($$$2 \le |s_i| \le 10$$$) — the name of the $$$i$$$-th student. The names are in English alphabet with first letter uppercase and rest lowercase. All names are distinct.

The next $$$q$$$ lines contains, each, one integer and two strings, separated with spaces, $$$t_i$$$, $$$s_x$$$ and $$$s_y$$$ ($$$1 \le t_i \le 2$$$, $$$s_x \ne s_y$$$) — the type of the $$$i$$$-th query and the names of the students of the $$$i$$$-th query. It's guaranteed that $$$s_x$$$ and $$$s_y$$$ are names of students. If $$$t_i$$$ equals $$$1$$$ and the students $$$s_x$$$ and $$$s_y$$$ are already on the same group, nothing changes.

It's guaranteed that there will be at least one query of type $$$2$$$.

Output

For each query of type $$$2$$$ you must print "yes" or "no" (without quotes), meaning if the given students are in the same group or not, respectively.

ExamplesInput
6 13
Navarro
Arnon
Matheus
Xavier
Rebeca
Naum
1 Naum Rebeca
2 Rebeca Naum
1 Matheus Xavier
1 Navarro Arnon
2 Matheus Navarro
2 Rebeca Matheus
1 Navarro Matheus
2 Xavier Arnon
2 Xavier Rebeca
1 Rebeca Arnon
2 Naum Rebeca
2 Naum Matheus
2 Naum Xavier
Output
yes
no
no
yes
no
yes
yes
yes
Input
6 8
Sergio
Yu
Mateus
Cesar
Gustavo
Caio
1 Sergio Mateus
1 Cesar Yu
1 Cesar Gustavo
2 Cesar Sergio
1 Caio Mateus
1 Gustavo Yu
2 Caio Sergio
2 Gustavo Sergio
Output
no
yes
no

加入题单

算法标签: