QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#579231#3318. Four-ColoringzltWA 3ms4632kbC++141.9kb2024-09-21 10:49:322024-09-21 10:49:33

Judging History

你现在查看的是最新测评结果

  • [2024-09-21 10:49:33]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:4632kb
  • [2024-09-21 10:49:32]
  • 提交

answer

#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define mems(a, x) memset((a), (x), sizeof(a))

using namespace std;
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<int, int> pii;

const int maxn = 20050;

int n, m, ans[maxn];
pii b[maxn];
bool vis[maxn], mk[maxn];
vector<int> G[maxn];

struct node {
	int x, y, i;
} a[maxn];

void dfs(int u, int x, int y) {
	mk[u] = 1;
	for (int v : G[u]) {
		if (vis[v] && !mk[v] && (ans[v] == x || ans[v] == y)) {
			dfs(v, x, y);
		}
	}
}

void solve() {
	scanf("%d%d%*d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		scanf("%d%d", &a[i].x, &a[i].y);
		a[i].i = i;
		b[i] = mkp(a[i].x, a[i].y);
	}
	sort(a + 1, a + n + 1, [&](const node &a, const node &b) {
		return a.x > b.x || (a.x == b.x && a.y > b.y);
	});
	while (m--) {
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].pb(v);
		G[v].pb(u);
	}
	for (int i = 1; i <= n; ++i) {
		int u = a[i].i, S = 0;
		vis[u] = 1;
		for (int v : G[u]) {
			if (vis[v]) {
				S |= (1 << ans[v]);
			}
		}
		if (S != 30) {
			ans[u] = 1;
			while (S & (1 << ans[u])) {
				++ans[u];
			}
			continue;
		}
		int v1 = -1, v2 = -1, v3 = -1, v4 = -1;
		for (int v : G[u]) {
			if (vis[v]) {
				if (b[v].fst == a[i].x) {
					v1 = v;
				} else if (b[v].fst - a[i].x == b[v].scd - a[i].y) {
					v2 = v;
				} else if (b[v].scd == a[i].y) {
					v3 = v;
				} else {
					v4 = v;
				}
			}
		}
		int x = ans[v1], y = ans[v3];
		mems(mk, 0);
		dfs(v1, x, y);
		if (mk[v3]) {
			mems(mk, 0);
			x = ans[v2];
			y = ans[v4];
			dfs(v2, x, y);
		}
		for (int j = 1; j <= n; ++j) {
			if (mk[j]) {
				ans[j] ^= x ^ y;
			}
		}
		ans[u] = x;
	}
	for (int i = 1; i <= n; ++i) {
		printf("%d\n", ans[i]);
	}
}

int main() {
	int T = 1;
	// scanf("%d", &T);
	while (T--) {
		solve();
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 4632kb

input:

4009 9537
0 20
20 0
20 20
0 40
10 30
20 40
10 27
10 26
12 27
11 26
9 26
9 24
10 25
10 24
11 24
12 24
10 23
12 23
12 25
12 26
13 24
13 26
10 50
40 40
20 60
30 30
30 50
40 60
30 47
30 46
32 47
31 46
29 46
29 44
30 45
30 44
31 44
32 44
30 43
32 43
32 45
32 46
33 44
33 46
30 70
60 60
40 80
50 50
50 70
6...

output:

2
4
3
3
2
1
2
1
1
4
2
4
2
3
1
2
2
4
3
2
1
3
2
3
3
2
1
2
2
1
1
3
2
4
2
3
1
2
2
4
3
2
1
3
1
3
3
4
2
1
2
1
1
4
2
4
2
3
1
2
2
4
3
2
1
3
2
3
3
2
2
1
2
1
1
4
2
4
2
3
1
2
2
4
3
2
1
3
2
4
3
3
1
2
2
1
1
3
2
4
2
3
1
2
2
4
3
2
1
3
1
4
3
1
1
2
2
1
1
3
2
4
2
3
1
2
2
4
3
2
1
3
3
1
1
4
2
3
2
1
1
4
2
4
2
3
1
2
2
4
...

result:

wrong answer Integer 0 violates the range [1, 4]