結果

問題 No.2780 The Bottle Imp
ユーザー テナガザルテナガザル
提出日時 2024-06-08 00:23:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,838 bytes
コンパイル時間 1,194 ms
コンパイル使用メモリ 99,400 KB
実行使用メモリ 29,604 KB
最終ジャッジ日時 2024-06-08 10:40:25
合計ジャッジ時間 4,656 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 72 ms
12,672 KB
testcase_08 AC 75 ms
12,672 KB
testcase_09 AC 76 ms
12,544 KB
testcase_10 AC 75 ms
12,672 KB
testcase_11 AC 72 ms
12,672 KB
testcase_12 AC 134 ms
22,760 KB
testcase_13 AC 137 ms
22,940 KB
testcase_14 AC 38 ms
5,888 KB
testcase_15 AC 39 ms
5,760 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 38 ms
5,888 KB
testcase_19 AC 38 ms
5,888 KB
testcase_20 AC 37 ms
5,760 KB
testcase_21 WA -
testcase_22 AC 25 ms
6,144 KB
testcase_23 AC 32 ms
5,888 KB
testcase_24 AC 59 ms
11,136 KB
testcase_25 AC 105 ms
17,428 KB
testcase_26 AC 48 ms
8,320 KB
testcase_27 AC 32 ms
8,960 KB
testcase_28 AC 30 ms
8,832 KB
testcase_29 AC 46 ms
12,160 KB
testcase_30 AC 38 ms
11,136 KB
testcase_31 AC 58 ms
14,388 KB
testcase_32 AC 20 ms
5,376 KB
testcase_33 AC 68 ms
20,264 KB
testcase_34 AC 107 ms
29,604 KB
testcase_35 AC 18 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 18 ms
5,376 KB
testcase_39 AC 55 ms
13,704 KB
testcase_40 AC 53 ms
13,800 KB
testcase_41 AC 55 ms
13,704 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

int main()
{
  int n, m;
  cin >> n;
  vector<vector<int>> g(n), gr(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);
      gr[v].push_back(i);
    }
  }
  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);
  reverse(topo.begin(), topo.end());
  vector<int> tmp;
  auto dfs = [&](auto f, int now) -> void
  {
    if (check[now] == 0) return;
    tmp.push_back(now);
    check[now] = 0;
    for (int v : gr[now]) f(f, v);
  };
  vector<int> newid(n);
  int cnt = 0;
  for (int v : topo)
  {
    if (check[v] == 0) continue;
    tmp.clear();
    dfs(dfs, v);
    for (auto v1 : tmp) newid[v1] = cnt;
    ++cnt;
  }
  set<pair<int, int>> st;
  vector<vector<int>> ng(cnt);
  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];
      ng[a].push_back(b);
    }
  }
  check.assign(n, 0);
  topo.clear();
  g = ng;
  for (int i = 0; i < cnt; ++i)
  {
    topologicalsort(topologicalsort, i);
  }
  reverse(topo.begin(), topo.end());
  for (int i = 0; i < topo.size() - 1; ++i)
  {
    int np = topo[i + 1];
    bool flag = true;
    for (int v : ng[topo[i]])
    {
      if (v == np)
      {
        flag = false;
        break;
      }
    }
    if (flag)
    {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}
0