結果

問題 No.679 不思議マーケット
ユーザー 0w10w1
提出日時 2020-11-14 19:19:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,067 bytes
コンパイル時間 2,339 ms
コンパイル使用メモリ 203,788 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 06:32:13
合計ジャッジ時間 3,384 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 12 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);

  int N, M; {
    cin >> N >> M;
  }

  vector<int> G(M);
  vector<vector<int>> H(M); {
    for (int i = 0; i < M; ++i) {
      int n;
      cin >> G[i] >> n;
      --G[i];
      H[i].resize(n);
      for (int j = 0; j < n; ++j) {
        cin >> H[i][j];
        --H[i][j];
      }
    }
  }

  vector<int> taken(N); {
    vector<int> cnt(N); {
      for (int g : G) ++cnt[g];
    }
    for (int i = 0; i < N; ++i) if (cnt[i] == 0) taken[i] = 1;
  }

  vector<int> cnt(M); {
    auto update = [&](int u) {
      for (int i = 0; i < M; ++i) {
        for (int h : H[i]) if (h == u) cnt[i] += 1;
      }
    };
    for (int i = 0; i < N; ++i) if (taken[i]) update(i);
    while (true) {
      bool flag = false;
      for (int i = 0; i < M; ++i) if (cnt[i] == H[i].size() && !taken[G[i]]) {
        flag = true;
        taken[G[i]] = 1;
        update(G[i]);
      }
      if (!flag) break;
    }
  }

  int res = count(taken.begin(), taken.end(), 1);
  cout << res << endl;
}
0