比赛 20160414 评测结果 AAAAWTWATTAEWAATTTTA
题目名称 树木园 最终得分 45
用户昵称 KZNS 运行时间 7.835 s
代码语言 C++ 内存使用 6.10 MiB
提交时间 2016-04-14 17:28:32
显示代码纯文本
//KZNS
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
//
ifstream fin ("cactus.in");
ofstream fout ("cactus.out");
const int Nmax = 100003;
class poi {
public:
	int sz, hs, sm;
	vector<int> cds;
	poi() {
		sm = 0;
		sz = 0;
		hs = 0;
	}
};
inline bool operator < (poi a, poi b) {
	if (a.sz == b.sz) {
		if (a.sm == b.sm) {
			if (a.hs == b.hs) {
				for (int i = 0; i < a.cds.size(); i++) {
					if (a.cds[i] != b.cds[i])
						return a.cds[i] < b.cds[i];
				}
				return 1;
			}
			else {
				return a.hs < b.hs;
			}
		}
		else {
			return a.sm < b.sm;
		}
	}
	else {
		return a.sz < b.sz;
	}
}
inline bool operator == (poi a, poi b) {
	if (a.sz != b.sz)
		return false;
	if (a.sm != b.sm)
		return false;
	if (a.hs != b.hs)
		return false;
	for (int i = 0; i < a.cds.size(); i++)
		if (a.cds[i] != b.cds[i])
			return false;
	return true;
}
//
int N, M;
vector<int> gp1[Nmax], gp2[Nmax];
poi ls1[Nmax], ls2[Nmax];
//
void fir() {
	fin >> N >> M;
	int a, b;
	for (int i = 0; i < M; i++) {
		fin >> a >> b;
		gp1[a].push_back(b);
		gp1[b].push_back(a);
	}
	for (int i = 0; i < M; i++) {
		fin >> a >> b;
		gp2[a].push_back(b);
		gp2[b].push_back(a);
	}
}
void d1() {
	for (int i = 1; i <= N; i++) {
		ls1[i].hs = ls1[i].sz = gp1[i].size();
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < gp1[i].size(); j++) {
			ls1[i].cds.push_back(ls1[gp1[i][j]].sz);
			ls1[i].sm += ls1[gp1[i][j]].sz;
			ls1[i].hs ^= ls1[gp1[i][j]].sz;
		}
	}
	for (int i = 1; i <= N; i++) {
		sort(ls1[i].cds.begin(), ls1[i].cds.end());
	}
	sort(ls1+1, ls1+N+1);
}
void d2() {
	for (int i = 1; i <= N; i++) {
		ls2[i].hs = ls2[i].sz = gp2[i].size();
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < gp2[i].size(); j++) {
			ls2[i].cds.push_back(ls2[gp2[i][j]].sz);
			ls2[i].sm += ls2[gp2[i][j]].sz;
			ls2[i].hs ^= ls2[gp2[i][j]].sz;
		}
	}
	for (int i = 1; i <= N; i++) {
		sort(ls2[i].cds.begin(), ls2[i].cds.end());
	}
	sort(ls2+1, ls2+N+1);
}
//
int main() {
	fir();
	d1();
	d2();
	for (int i = 1; i <= N; i++) {
		if (!(ls1[i] == ls2[i])) {
			fout << "NO" << endl;
			return 0;
		}
	}
	fout << "YES" << endl;
	return 0;
}
//UBWH