結果

問題 No.2780 The Bottle Imp
ユーザー umezoumezo
提出日時 2024-06-19 06:20:54
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,323 bytes
コンパイル時間 5,700 ms
コンパイル使用メモリ 321,072 KB
実行使用メモリ 49,392 KB
最終ジャッジ日時 2024-06-19 06:21:04
合計ジャッジ時間 10,106 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 36 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint=modint998244353;//modint1000000007

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
template <class T> using V=vector<T>;
template <class T> using VV=V<V<T>>; //B(n,V<int>(n))

V<int> A[100100];
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int n;
  cin>>n;
  scc_graph g(n);
  V<int> M(n);
  rep(i,n){
    cin>>M[i];
    rep(j,M[i]){
      int a;
      cin>>a;
      a--;
      g.add_edge(i,a);
      A[i].push_back(a);
    }
  }
  auto scc=g.scc();
  V<int> G(n);
  int a=scc.size();
  rep(i,a){
    for(auto j:scc[i]) G[j]=i; 
  }
  V<set<int>> to(a),from(a);
  rep(i,n){
    for(auto x:A[i]){
      if(G[x]==G[i]) continue;
      from[G[x]].insert(G[i]);
      to[G[i]].insert(G[x]);
    }
  }
  V<int> dp(a),out(a);
  queue<int> que;
  rep(i,a){
    if(to[i].size()==0){
      que.push(i);
      dp[i]=1;
    }
    else out[i]=to[i].size();
  }
  while(que.size()){
    auto b=que.front(); que.pop();
    for(auto x:from[b]){
      dp[x]=max(dp[x],dp[b]+1);
      out[x]--;
      if(out[x]==0) que.push(x);
    }
  }
  int ma=0;
  rep(i,a) ma=max(ma,dp[i]);
  if(ma==a) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
    
  return 0;
}
0