Submission #545911

# Submission time Handle Problem Language Result Execution time Memory
545911 2022-04-05T16:08:44 Z rainboy One-Way Streets (CEOI17_oneway) C
100 / 100
103 ms 13728 KB
#include <stdio.h>
#include <stdlib.h>

#define N	100000
#define M	100000

int min(int a, int b) { return a < b ? a : b; }

int ii[M], jj[M]; char cc[M + 1];
int *eh[N], eo[N];

void append(int i, int h) {
	int o = eo[i]++;

	if (o >= 2 && (o & o - 1) == 0)
		eh[i] = (int *) realloc(eh[i], o * 2 * sizeof *eh[i]);
	eh[i][o] = h;
}

int ta[N], tb[N], kk[N];

void dfs(int f, int i) {
	static int time;
	int o;

	ta[i] = tb[i] = ++time;
	for (o = eo[i]; o--; ) {
		int h = eh[i][o], j = i ^ ii[h] ^ jj[h];

		if (h != f) {
			if (!ta[j]) {
				dfs(h, j);
				if (tb[j] != ta[j] || kk[j] == 0)
					cc[h] = 'B';
				else
					cc[h] = (i == ii[h]) == (kk[j] < 0) ? 'R' : 'L';
				tb[i] = min(tb[i], tb[j]);
				kk[i] += kk[j];
			} else {
				cc[h] = 'B';
				tb[i] = min(tb[i], ta[j]);
			}
		}
	}
}

int main() {
	int n, m, q, h, i, j;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++)
		eh[i] = (int *) malloc(2 * sizeof *eh[i]);
	for (h = 0; h < m; h++) {
		scanf("%d%d", &i, &j), i--, j--;
		ii[h] = i, jj[h] = j;
		append(i, h), append(j, h);
	}
	scanf("%d", &q);
	while (q--) {
		scanf("%d%d", &i, &j), i--, j--;
		kk[i]++, kk[j]--;
	}
	for (i = 0; i < n; i++)
		if (!ta[i])
			dfs(-1, i);
	printf("%s\n", cc);
	return 0;
}

Compilation message

oneway.c: In function 'append':
oneway.c:15:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   15 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
oneway.c: In function 'main':
oneway.c:50:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
oneway.c:54:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |   scanf("%d%d", &i, &j), i--, j--;
      |   ^~~~~~~~~~~~~~~~~~~~~
oneway.c:58:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |  scanf("%d", &q);
      |  ^~~~~~~~~~~~~~~
oneway.c:60:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |   scanf("%d%d", &i, &j), i--, j--;
      |   ^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 48 ms 5476 KB Output is correct
12 Correct 46 ms 6608 KB Output is correct
13 Correct 50 ms 8032 KB Output is correct
14 Correct 66 ms 9436 KB Output is correct
15 Correct 72 ms 9812 KB Output is correct
16 Correct 64 ms 8104 KB Output is correct
17 Correct 55 ms 9592 KB Output is correct
18 Correct 59 ms 8140 KB Output is correct
19 Correct 57 ms 10664 KB Output is correct
20 Correct 40 ms 7748 KB Output is correct
21 Correct 45 ms 7092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 48 ms 5476 KB Output is correct
12 Correct 46 ms 6608 KB Output is correct
13 Correct 50 ms 8032 KB Output is correct
14 Correct 66 ms 9436 KB Output is correct
15 Correct 72 ms 9812 KB Output is correct
16 Correct 64 ms 8104 KB Output is correct
17 Correct 55 ms 9592 KB Output is correct
18 Correct 59 ms 8140 KB Output is correct
19 Correct 57 ms 10664 KB Output is correct
20 Correct 40 ms 7748 KB Output is correct
21 Correct 45 ms 7092 KB Output is correct
22 Correct 101 ms 10708 KB Output is correct
23 Correct 103 ms 9164 KB Output is correct
24 Correct 90 ms 9292 KB Output is correct
25 Correct 86 ms 13728 KB Output is correct
26 Correct 81 ms 10320 KB Output is correct
27 Correct 98 ms 9332 KB Output is correct
28 Correct 41 ms 3460 KB Output is correct
29 Correct 71 ms 8680 KB Output is correct
30 Correct 67 ms 8276 KB Output is correct
31 Correct 79 ms 9700 KB Output is correct
32 Correct 74 ms 10300 KB Output is correct