답안 #478293

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
478293 2021-10-06T19:44:48 Z rainboy Praktični (COCI18_prakticni) C
0 / 130
97 ms 3948 KB
#include <assert.h>
#include <stdio.h>
#include <string.h>

#define N	100000
#define M	100000
#define L	30

int ds[N], xx[N];

int find(int i) {
	int p, r;

	if (ds[i] < 0)
		return i;
	p = ds[i], r = find(p);
	xx[i] ^= xx[p];
	return r;
}

int join(int i, int j, int x) {
	int ri = find(i), rj = find(j);

	x ^= xx[i] ^ xx[j], i = ri, j = rj;
	if (i == j)
		return x;
	if (ds[i] > ds[j])
		ds[i] = j, xx[i] = x;
	else {
		if (ds[i] == ds[j])
			ds[i]--;
		ds[j] = i, xx[j] = x;
	}
	return 0;
}

int bb[L];

int get(int x) {
	int l, y;

	y = 0;
	for (l = 0; l < L; l++)
		if ((x & 1 << l) != 0) {
			y |= 1 << l;
			if ((bb[l] & 1 << l) != 0)
				x ^= bb[l];
			else {
				bb[l] = x;
				return -y;
			}
		}
	return y;
}

int main() {
	static int xx[M], yy[M];
	int n, m, h, i, j, k, l;

	scanf("%d%d", &n, &m);
	memset(ds, -1, n * sizeof *ds);
	k = 0;
	for (h = 0; h < m; h++) {
		int x;

		scanf("%d%d%d", &i, &j, &x), i--, j--;
		if ((yy[h] = get(xx[h] = join(i, j, x))) < 0)
			yy[h] = -yy[h], k++;
	}
	printf("%d\n", k);
	for (l = 0; l < L; l++)
		if (bb[l]) {
			printf("%d", bb[l]);
			k = 0;
			for (h = 0; h < m; h++)
				if ((yy[h] & 1 << l) != 0)
					k++;
			printf(" %d", k);
			for (h = 0; h < m; h++)
				if ((yy[h] & 1 << l) != 0)
					xx[h] ^= bb[l], printf(" %d", h + 1);
			printf("\n");
		}
	for (h = 0; h < m; h++)
		assert(xx[h] == 0);
	return 0;
}

Compilation message

parkticni.c: In function 'main':
parkticni.c:60:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
parkticni.c:66:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |   scanf("%d%d%d", &i, &j, &x), i--, j--;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 50 ms 2500 KB There is a simple cycle which is not good
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 32 ms 1372 KB There is a simple cycle which is not good
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 1604 KB There is a simple cycle which is not good
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 55 ms 2372 KB There is a simple cycle which is not good
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 46 ms 2008 KB There is a simple cycle which is not good
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 80 ms 3780 KB There is a simple cycle which is not good
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 62 ms 2308 KB There is a simple cycle which is not good
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 97 ms 3948 KB There is a simple cycle which is not good
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 796 KB There is a simple cycle which is not good
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 2612 KB There is a simple cycle which is not good
2 Halted 0 ms 0 KB -