Submission #382580

#TimeUsernameProblemLanguageResultExecution timeMemory
382580rainboyBridges (APIO19_bridges)C11
13 / 100
3084 ms2028 KiB
#include <stdio.h>

#define N	50000
#define M	100000

int ds[N], sz[N];

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, sz[j] += sz[i];
	else {
		if (ds[i] == ds[j])
			ds[i]--;
		ds[j] = i, sz[i] += sz[j];
	}
}

int main() {
	static int ii[M], jj[M], ww[M];
	int n, m, q, h;

	scanf("%d%d", &n, &m);
	for (h = 0; h < m; h++)
		scanf("%d%d%d", &ii[h], &jj[h], &ww[h]), ii[h]--, jj[h]--;
	scanf("%d", &q);
	while (q--) {
		int t, w;

		scanf("%d", &t);
		if (t == 1) {
			scanf("%d%d", &h, &w), h--;
			ww[h] = w;
		} else {
			int s, i;

			scanf("%d%d", &s, &w), s--;
			for (i = 0; i < n; i++)
				ds[i] = -1, sz[i] = 1;
			for (h = 0; h < m; h++)
				if (w <= ww[h])
					join(ii[h], jj[h]);
			printf("%d\n", sz[find(s)]);
		}
	}
	return 0;
}

Compilation message (stderr)

bridges.c: In function 'main':
bridges.c:30:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   30 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
bridges.c:32:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   32 |   scanf("%d%d%d", &ii[h], &jj[h], &ww[h]), ii[h]--, jj[h]--;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bridges.c:33:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   33 |  scanf("%d", &q);
      |  ^~~~~~~~~~~~~~~
bridges.c:37:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   37 |   scanf("%d", &t);
      |   ^~~~~~~~~~~~~~~
bridges.c:39:4: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   39 |    scanf("%d%d", &h, &w), h--;
      |    ^~~~~~~~~~~~~~~~~~~~~
bridges.c:44:4: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   44 |    scanf("%d%d", &s, &w), s--;
      |    ^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...