记录编号 26963 评测结果 AWAWAWAAAW
题目名称 线段 最终得分 60
用户昵称 GravatarVani 是否通过 未通过
代码语言 C++ 运行时间 0.004 s
提交时间 2011-07-30 14:46:00 内存使用 0.26 MiB
显示代码纯文本
#include <cstdio>
#include <algorithm>
#include <cctype>
namespace Solve {
	const int MAXN = 500;

	inline int ScanInt(void) {
		int r = 0, c;
		while (!isdigit(c = getchar()));
		r = c - '0';
		while ( isdigit(c = getchar())) r = r * 10 + c - '0';
		return r;
	}

	int f[MAXN], d[MAXN], n;

	inline int Find(int x) {
		if (f[x] == x) return x;
		int ret = Find(f[x]);
		return d[x] = (d[x] + d[f[x]]) & 1, f[x] = ret;
	}

	void solve(void) {
		int n = ScanInt();
		for (int i = 1; i <= n; i++) f[i] = i, d[i] = 0;
		int m = ScanInt(), _ = true;
		while (m--) {
			int x = ScanInt(), y = ScanInt(), type = ScanInt();
			int t1 = Find(x), t2 = Find(y);
			if (t1 == t2) {
				if (((d[x] + d[y]) & 1) != type)
					_ = false;
			}else {
				f[t1] = t2;
				d[t1] = ((d[x] + d[y]) & 1) ^ type;
			}
		}
		if (_) {
			if (Find(1) != Find(n)) puts("2");
			else printf("%d\n", (d[1] + d[n]) & 1);
		} else puts("No Answer");
	}
}
int main(int argc, char** argv) {
		freopen("line.in", "r", stdin);
		freopen("line.out", "w", stdout);
	int T_T; scanf("%d", &T_T); while (T_T--)
	Solve::solve();
	return 0;
}