제출 #536552

#제출 시각아이디문제언어결과실행 시간메모리
536552rainboy전압 (JOI14_voltage)C11
10 / 100
1090 ms4092 KiB
#include <stdio.h>
#include <string.h>

#define N	100000
#define M	200000

int ds[N * 2];

int find(int i) {
	return ds[i] < 0 ? i : (ds[i] = find(ds[i]));
}

void join(int i, int j) {
	i = find(i);
	j = find(j);
	if (i == j)
		return;
	if (ds[i] > ds[j])
		ds[i] = j;
	else {
		if (ds[i] == ds[j])
			ds[i]--;
		ds[j] = i;
	}
}

int main() {
	static int ii[M], jj[M];
	int n, m, h, h_, i, j, cnt;

	scanf("%d%d", &n, &m);
	for (h = 0; h < m; h++)
		scanf("%d%d", &ii[h], &jj[h]), ii[h]--, jj[h]--;
	cnt = 0;
	for (h = 0; h < m; h++) {
		memset(ds, -1, n * 2 * sizeof *ds);
		for (h_ = 0; h_ < m; h_++) {
			i = ii[h_], j = jj[h_];
			if (h_ == h)
				join(i << 1 | 0, j << 1 | 0), join(i << 1 | 1, j << 1 | 1);
			else
				join(i << 1 | 0, j << 1 | 1), join(i << 1 | 1, j << 1 | 0);
		}
		cnt++;
		for (i = 0; i < n; i++)
			if (find(i << 1 | 0) == find(i << 1 | 1)) {
				cnt--;
				break;
			}
	}
	printf("%d\n", cnt);
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

voltage.c: In function 'main':
voltage.c:31:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
voltage.c:33:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |   scanf("%d%d", &ii[h], &jj[h]), ii[h]--, jj[h]--;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...