結果
問題 |
No.1401 全自動マクロの作り方
|
ユーザー |
👑 ![]() |
提出日時 | 2021-02-19 22:45:23 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 856 bytes |
コンパイル時間 | 2,194 ms |
コンパイル使用メモリ | 203,028 KB |
最終ジャッジ日時 | 2025-01-19 01:03:27 |
ジャッジサーバーID (参考情報) |
judge3 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 2 |
other | WA * 3 RE * 4 |
ソースコード
#include <bits/stdc++.h> using namespace std; using LL=long long; using ULL=unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) int N; vector<vector<int>> S; vector<vector<int>> V; vector<int> I; int Z=2000; int main(){ cin>>N; S.resize(N); rep(i,N){ int d; cin>>d; S[i].resize(d); rep(j,d){ cin>>S[i][j]; S[i][j]--; } } V.resize(Z); I.assign(Z,0); rep(i,N){ if(S[i].front()!=S[i].back()){ V[S[i].front()].push_back(S[i].back()); I[S[i].back()]++; } } queue<int> Q; rep(i,Z) if(I[i]==0) Q.push(i); vector<int> ans; while(Q.size()){ int p=Q.front(); Q.pop(); ans.push_back(p); for(int e:V[p]) if(--I[e]==0) Q.push(e); } if(ans.size()!=Z) cout<<0<<endl; else{ cout<<ans.size()<<endl; rep(i,ans.size()){ if(i) cout<<" "; cout<<(ans[i]+1); } } return 0; }