結果

問題 No.1477 Lamps on Graph
ユーザー sten_sansten_san
提出日時 2021-07-03 03:43:22
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 3,058 bytes
コンパイル時間 1,125 ms
コンパイル使用メモリ 30,800 KB
実行使用メモリ 10,192 KB
最終ジャッジ日時 2023-09-12 09:06:34
合計ジャッジ時間 11,676 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 1 ms
4,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 RE -
testcase_24 RE -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 RE -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 61 ms
10,096 KB
testcase_34 AC 63 ms
10,184 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef struct vector {
    void *head;
    size_t used, capa;
} *vector;

#define vector_make(...) vector_make_overload(__VA_ARGS__, vector_make_2, vector_make_1)(__VA_ARGS__)
#define vector_make_1(bsize) vector_make_(bsize)
#define vector_make_2(type, size) vector_make_(sizeof(type) * (size))
#define vector_make_overload(arg1, arg2, name, ...) name

#define vector_resize(type, vec, size) vector_resize_(vec, sizeof(type) * (size))

#define vector_index(type, vec, index) ((type *)(vec)->head)[index]
#define vector_size(type, vec) ((vec)->used / sizeof(type))
#define vector_push_back(type, vec, value) \
do { \
    vector_resize(type, vec, vector_size(type, vec) + 1); \
    vector_index(type, vec, vector_size(type, vec) - 1) = value; \
} while (0)

vector vector_make_(size_t bsize) {
    vector v = malloc(sizeof(struct vector));

    if (v == NULL) {
        return NULL;
    }

    v->head = malloc(bsize);

    if (v->head == NULL) {
        free(v);
        return NULL;
    }

    v->used = bsize;
    v->capa = bsize;

    return v;
}

bool vector_resize_(vector v, size_t bsize) {
    if (bsize <= v->capa) {
        v->used = bsize;
        return true;
    }

    size_t new_capa = (bsize + v->capa) / (v->capa + 1) * (v->capa + 1);

    void *new = realloc(v->head, new_capa);
    if (new == NULL) {
        return false;
    }

    v->head = new;
    v->used = bsize;
    v->capa = new_capa;

    return true;
}

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

    vector a = vector_make(int, n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &vector_index(int, a, i));
    }

    vector g = vector_make(vector, n);
    for (int i = 0; i < n; ++i) {
        vector_index(vector, g, i) = vector_make(int, 0);
    }

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

        vector_push_back(int, vector_index(vector, g, u), v);
        vector_push_back(int, vector_index(vector, g, v), i);
    }

    vector lamp = vector_make(bool, n);
    for (int i = 0; i < n; ++i) {
        vector_index(bool, lamp, i) = false;
    }

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

    for (int i = 0; i < k; ++i) {
        int b;
        scanf("%d", &b);
        --b;
        vector_index(bool, lamp, b) = true;
    }

    vector x = vector_make(int, 0);
    for (int i = 0; i < n; ++i) {
        if (!vector_index(bool, lamp, i)) {
            continue;
        }

        vector_push_back(int, x, i);

        vector list = vector_index(vector, g, i);

        vector_index(bool, lamp, i) = false;
        for (int j = 0; j < vector_size(int, list); ++j) {
            int v = vector_index(int, list, j);

            if (vector_index(int, a, i) < vector_index(int, a, v)) {
                vector_index(bool, lamp, v) ^= 1;
            }
        }
    }

    printf("%zu\n", vector_size(int, x));
    for (int i = 0; i < vector_size(int, x); ++i) {
        printf("%d\n", vector_index(int, x, i) + 1);
    }
}

0