M

 avatar
user_8384735
c_cpp
3 years ago
559 B
4
Indexable
// 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);
	}
}
Editor is loading...