結果

問題 No.1477 Lamps on Graph
ユーザー sten_sansten_san
提出日時 2021-07-03 04:17:59
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 1,354 bytes
コンパイル時間 226 ms
コンパイル使用メモリ 29,420 KB
実行使用メモリ 7,916 KB
最終ジャッジ日時 2023-09-12 09:45:43
合計ジャッジ時間 4,701 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 0 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 0 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 0 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 43 ms
4,376 KB
testcase_13 AC 39 ms
4,380 KB
testcase_14 AC 52 ms
4,796 KB
testcase_15 AC 23 ms
4,376 KB
testcase_16 AC 17 ms
4,376 KB
testcase_17 AC 15 ms
4,380 KB
testcase_18 AC 48 ms
4,852 KB
testcase_19 AC 38 ms
4,620 KB
testcase_20 AC 15 ms
4,376 KB
testcase_21 AC 41 ms
4,376 KB
testcase_22 AC 10 ms
4,376 KB
testcase_23 AC 29 ms
4,380 KB
testcase_24 AC 59 ms
5,360 KB
testcase_25 AC 21 ms
4,376 KB
testcase_26 AC 56 ms
5,632 KB
testcase_27 AC 26 ms
4,380 KB
testcase_28 AC 33 ms
4,384 KB
testcase_29 AC 30 ms
4,376 KB
testcase_30 AC 24 ms
4,380 KB
testcase_31 AC 18 ms
4,380 KB
testcase_32 AC 75 ms
7,892 KB
testcase_33 AC 71 ms
7,824 KB
testcase_34 AC 61 ms
7,916 KB
testcase_35 AC 81 ms
7,228 KB
testcase_36 AC 80 ms
7,296 KB
testcase_37 AC 72 ms
7,220 KB
testcase_38 AC 75 ms
7,084 KB
testcase_39 AC 79 ms
7,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdbool.h>

int a[100000], *g[100000], d[100000], s[100000], x[100000];
bool l[100000];

int comp(const void *x, const void *y) {
    return a[*(const int *)x] - a[*(const int *)y];
}

int main() {
    int n, m;
    scanf("%d %d", &n, &m);

    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);

        g[i] = NULL;
        d[i] = 0;
        s[i] = i;
    }

    qsort(&s[0], n, sizeof(int), comp);

    for (int i = 0; i < m; ++i) {
        int u, v;
        scanf("%d %d", &u, &v);
        --u; --v;

        g[u] = realloc(g[u], sizeof(int) * (d[u] + 1));
        g[v] = realloc(g[v], sizeof(int) * (d[v] + 1));
        g[u][d[u]] = v;
        g[v][d[v]] = u;
        ++d[u]; ++d[v];
    }

    int k;
    scanf("%d", &k);

    while (k--) {
        int b;
        scanf("%d", &b);
        --b;

        l[b] = true;
    }

    int *last = &x[0];
    for (int i = 0; i < n; ++i) {
        int v = s[i];

        if (!l[v]) {
            continue;
        }

        *last++ = v;
        for (int j = 0; j < d[v]; ++j) {
            int u = g[v][j];
            if (a[v] < a[u]) {
                l[u] = !l[u];
            }
        }
    }

    printf("%ld\n", last - &x[0]);

    int *iter = &x[0];
    while (iter != last) {
        printf("%d\n", *iter++ + 1);
    }
}

0