답안 #478302

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
478302 2021-10-06T19:56:09 Z rainboy Praktični (COCI18_prakticni) C
130 / 130
126 ms 6860 KB
#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];
	ds[i] = r;
	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 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(join(i, j, x))) < 0)
			yy[h] = -yy[h], k++;
	}
	printf("%d\n", k);
	for (l = 0; l < L; l++)
		if (bb[l]) {
			k = 0;
			for (h = 0; h < m; h++)
				if ((yy[h] & 1 << l) != 0)
					k++;
			printf("%d %d", bb[l], k);
			for (h = 0; h < m; h++)
				if ((yy[h] & 1 << l) != 0)
					printf(" %d", h + 1);
			printf("\n");
		}
	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 Correct 23 ms 664 KB Output is correct
2 Correct 23 ms 1824 KB Output is correct
3 Correct 6 ms 464 KB Output is correct
4 Correct 5 ms 616 KB Output is correct
5 Correct 40 ms 3400 KB Output is correct
6 Correct 43 ms 3364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 396 KB Output is correct
2 Correct 11 ms 940 KB Output is correct
3 Correct 14 ms 1196 KB Output is correct
4 Correct 17 ms 1232 KB Output is correct
5 Correct 41 ms 3016 KB Output is correct
6 Correct 25 ms 1864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 1244 KB Output is correct
2 Correct 39 ms 2700 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 1348 KB Output is correct
2 Correct 92 ms 5104 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 1200 KB Output is correct
2 Correct 45 ms 2888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 2372 KB Output is correct
2 Correct 28 ms 1924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 1644 KB Output is correct
2 Correct 87 ms 4780 KB Output is correct
3 Correct 42 ms 3016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 3120 KB Output is correct
2 Correct 126 ms 6860 KB Output is correct
3 Correct 97 ms 5884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 716 KB Output is correct
2 Correct 23 ms 1744 KB Output is correct
3 Correct 61 ms 3968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 1860 KB Output is correct
2 Correct 35 ms 2492 KB Output is correct
3 Correct 89 ms 5320 KB Output is correct