WA!
  • 板块学术版
  • 楼主wangzl
  • 当前回复0
  • 已保存回复0
  • 发布时间2021/8/7 10:28
  • 上次更新2023/11/4 11:45:04
查看原帖
WA!
222039
wangzl楼主2021/8/7 10:28

传送门

#include<cstdio>
#include<iostream>
#include<cmath>
#define N 50000+5
using namespace std;
int n, k, ans, bing[N], fight[N];
int father(int x) {
	if(x == bing[x]) return x;
	fight[x] = (fight[x] + fight[bing[x]]) % 3;
	return bing[x] = father(bing[x]);
}
inline int read() {
	int s=0, w=1;
	char c = getchar();
	while (c < '0' || c>'9') {
		if (c == '-') w = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		s = (s << 3) + (s << 1) + (c ^ 48);
	}
	return w * s;
}
int main() {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; ++i) {
		bing[i] = i;
	}
	for (int i = 1; i <= k; ++i) {
		int kind, ani_1, ani_2;
		scanf("%d%d%d", &kind, &ani_1, &ani_2);
		if ( (kind==2 && ani_1 == ani_2) || ani_1 > n || ani_2 > n) {
			++ans;
			continue;
		}
		int father_1 = father(ani_1), father_2 = father(ani_2);
		if (kind == 1) {
			if (father_1 == father_2 && fight[father_1] != fight[father_2]) {
				++ans;
				continue;
			}
			if (father_1 != father_2)
				bing[father_1] = father_2,
				fight[father_1] = (fight[ani_2] - fight[ani_1] + 3) % 3;
		}
		else {
			if (father_1 == father_2 && (fight[father_1] - fight[father_2] + 3) % 3 != 1) {
				++ans;
				continue;
			}
			if (father_1 != father_2)
				bing[father_1] = father_2,
				fight[father_1] = (fight[ani_2] - fight[ani_1] + 4) % 3;
		}
	}
	printf("%d", ans);
	return 0;
}
2021/8/7 10:28
加载中...