Submission #478300

# Submission time Handle Problem Language Result Execution time Memory
478300 2021-10-06T19:55:33 Z rainboy Praktični (COCI18_prakticni) C
0 / 130
113 ms 3532 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] = 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 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--;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 80 ms 2304 KB There is a simple cycle which is not good
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 1168 KB There is a simple cycle which is not good
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 1408 KB There is a simple cycle which is not good
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 59 ms 1988 KB There is a simple cycle which is not good
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 57 ms 1636 KB There is a simple cycle which is not good
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 113 ms 3532 KB There is a simple cycle which is not good
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 59 ms 1936 KB There is a simple cycle which is not good
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 96 ms 3512 KB There is a simple cycle which is not good
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 684 KB There is a simple cycle which is not good
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 2124 KB There is a simple cycle which is not good
2 Halted 0 ms 0 KB -