結果

問題 No.1477 Lamps on Graph
ユーザー tnakao0123tnakao0123
提出日時 2021-04-16 22:23:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,531 bytes
コンパイル時間 799 ms
コンパイル使用メモリ 99,032 KB
実行使用メモリ 10,388 KB
最終ジャッジ日時 2023-09-16 01:14:37
合計ジャッジ時間 4,647 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,868 KB
testcase_01 AC 3 ms
5,796 KB
testcase_02 AC 3 ms
5,960 KB
testcase_03 AC 3 ms
5,820 KB
testcase_04 AC 3 ms
5,936 KB
testcase_05 AC 3 ms
5,880 KB
testcase_06 AC 3 ms
6,040 KB
testcase_07 AC 3 ms
5,876 KB
testcase_08 AC 3 ms
5,988 KB
testcase_09 AC 4 ms
5,880 KB
testcase_10 AC 3 ms
5,896 KB
testcase_11 AC 3 ms
5,824 KB
testcase_12 AC 39 ms
7,640 KB
testcase_13 AC 36 ms
7,396 KB
testcase_14 AC 46 ms
7,712 KB
testcase_15 AC 23 ms
6,744 KB
testcase_16 AC 15 ms
6,720 KB
testcase_17 AC 14 ms
6,548 KB
testcase_18 AC 36 ms
7,496 KB
testcase_19 AC 32 ms
7,444 KB
testcase_20 AC 15 ms
6,648 KB
testcase_21 AC 31 ms
7,280 KB
testcase_22 AC 12 ms
6,220 KB
testcase_23 AC 29 ms
6,864 KB
testcase_24 AC 51 ms
8,072 KB
testcase_25 AC 21 ms
6,612 KB
testcase_26 AC 47 ms
8,128 KB
testcase_27 AC 26 ms
6,788 KB
testcase_28 AC 30 ms
7,440 KB
testcase_29 AC 28 ms
7,004 KB
testcase_30 AC 19 ms
6,676 KB
testcase_31 AC 16 ms
6,660 KB
testcase_32 AC 58 ms
10,388 KB
testcase_33 AC 54 ms
9,364 KB
testcase_34 AC 50 ms
6,972 KB
testcase_35 AC 65 ms
9,244 KB
testcase_36 AC 65 ms
9,108 KB
testcase_37 AC 57 ms
9,000 KB
testcase_38 AC 60 ms
8,992 KB
testcase_39 AC 64 ms
9,160 KB
権限があれば一括ダウンロードができます

ソースコード

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 = 100000;

/* 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