結果

問題 No.2780 The Bottle Imp
ユーザー テナガザルテナガザル
提出日時 2024-06-07 23:16:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,657 bytes
コンパイル時間 1,240 ms
コンパイル使用メモリ 94,048 KB
実行使用メモリ 19,272 KB
最終ジャッジ日時 2024-06-08 10:37:57
合計ジャッジ時間 3,565 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 41 ms
6,784 KB
testcase_08 AC 40 ms
6,656 KB
testcase_09 AC 40 ms
6,656 KB
testcase_10 AC 40 ms
6,784 KB
testcase_11 AC 40 ms
6,784 KB
testcase_12 AC 61 ms
9,280 KB
testcase_13 AC 60 ms
9,268 KB
testcase_14 AC 32 ms
5,376 KB
testcase_15 AC 32 ms
5,376 KB
testcase_16 AC 32 ms
5,376 KB
testcase_17 AC 32 ms
5,376 KB
testcase_18 AC 34 ms
5,376 KB
testcase_19 AC 34 ms
5,376 KB
testcase_20 AC 34 ms
5,376 KB
testcase_21 AC 32 ms
5,376 KB
testcase_22 AC 17 ms
5,376 KB
testcase_23 AC 27 ms
5,376 KB
testcase_24 AC 33 ms
6,144 KB
testcase_25 AC 51 ms
7,992 KB
testcase_26 AC 34 ms
6,016 KB
testcase_27 AC 27 ms
6,528 KB
testcase_28 AC 27 ms
6,400 KB
testcase_29 AC 30 ms
7,040 KB
testcase_30 AC 33 ms
8,064 KB
testcase_31 AC 52 ms
10,108 KB
testcase_32 AC 20 ms
5,376 KB
testcase_33 AC 59 ms
14,664 KB
testcase_34 AC 92 ms
19,272 KB
testcase_35 AC 18 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 1 ms
5,376 KB
testcase_38 AC 17 ms
5,376 KB
testcase_39 AC 47 ms
9,932 KB
testcase_40 AC 47 ms
9,928 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int main()
{
  int n, m;
  cin >> n;
  vector<vector<int>> g(n);
  for (int i = 0; i < n; ++i)
  {
    int m;
    cin >> m;
    for (int j = 0; j < m; ++j)
    {
      int v;
      cin >> v;
      --v;
      g[i].push_back(v);
    }
  }
  vector<int> check(n), topo;
  auto topologicalsort = [&](auto f, int now) -> void
  {
    if (check[now]) return;
    check[now] = 1;
    for (auto v : g[now]) f(f, v);
    topo.push_back(now);
  };
  for (int i = 0; i < n; ++i)
  {
    topologicalsort(topologicalsort, i);
  }
  vector<int> gr;
  auto dfs = [&](auto f, int now) -> void
  {
    if (check[now] == 0) return;
    gr.push_back(now);
    check[now] = 0;
    for (int v : g[now]) f(f, v);
  };
  vector<int> newid(n);
  int cnt = 0;
  for (int v : topo)
  {
    if (check[v] == 0) continue;
    gr.clear();
    dfs(dfs, v);
    for (auto v1 : gr) newid[v1] = cnt;
    ++cnt;
  }
  set<pair<int, int>> st;
  vector<int> np(cnt, -1);
  for (int i = 0; i < n; ++i)
  {
    for (auto v : g[i])
    {
      if (newid[i] == newid[v] || st.find({newid[i], newid[v]}) != st.end()) continue;
      st.insert({newid[i], newid[v]});
      int a = newid[i], b = newid[v];
      if (np[a] != -1)
      {
        cout << "No" << endl;
        return 0;
      }
      np[a] = b;
    }
  }
  vector<int> ncheck(cnt, 1);
  int now = newid[0];
  ncheck[now] = 0;
  while (np[now] != -1)
  {
    now = np[now];
    ncheck[now] = 0;
  }
  for (int i = 0; i < cnt; ++i)
  {
    if (ncheck[i])
    {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}
0