M

 avatar
user_8384735
c_cpp
2 years ago
559 B
2
Indexable
Never
// icpcM.cpp
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
const int N = 100005;
vector<vector<int> > v(N, vector<int>());
int vis[N];
bool flag = 0;
void connect(int s, int e){
	if (flag) return ;
	if (s == e) flag = 1;
	vis[s] = 1;
	for (auto x : v[s])
		if (!vis[x])
			connect(x, e);
}
int main(){
	int n; cin >> n;
	int p, q;
	while (n--){
		memset(vis, 0, sizeof(vis));
		cin >> p >> q;
		flag = 0;
		connect(p, q);
		cout << (flag? "Y\n" : "N\n");
		v[p].push_back(q);
		v[q].push_back(p);
	}
}