結果

問題 No.1477 Lamps on Graph
ユーザー tnakao0123tnakao0123
提出日時 2021-04-16 22:23:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,528 bytes
コンパイル時間 852 ms
コンパイル使用メモリ 97,324 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-16 01:13:46
合計ジャッジ時間 9,513 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1477.cc:  No.1477 Lamps on Graph - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;

/* global variables */

int as[MAX_N], pns[MAX_N], xs[MAX_N];
vi nbrs[MAX_N];
bool ls[MAX_N];

/* subroutines */

/* main */

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

  for (int i = 0; i < n; i++) scanf("%d", as + i);

  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--, v--;
    if (as[u] < as[v]) nbrs[u].push_back(v), pns[v]++;
    else if (as[u] > as[v]) nbrs[v].push_back(u), pns[u]++;
  }

  int k;
  scanf("%d", &k);
  for (int i = 0; i < k; i++) {
    int bi;
    scanf("%d", &bi);
    bi--;
    ls[bi] = true;
  }

  qi q;
  for (int i = 0; i < n; i++)
    if (pns[i] == 0) q.push(i);

  int xn = 0;
  while (! q.empty()) {
    int u = q.front(); q.pop();
    if (ls[u]) xs[xn++] = u;

    vi &nbru = nbrs[u];
    for (vi::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
      int v = *vit;
      ls[v] ^= ls[u];
      if (--pns[v] == 0) q.push(v);
    }
  }

  printf("%d\n", xn);
  for (int i = 0; i < xn; i++) printf("%d\n", xs[i] + 1);
  return 0;
}
0