結果

問題 No.1401 全自動マクロの作り方
ユーザー mtsd
提出日時 2021-02-20 00:04:22
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 3,153 ms
コード長 2,580 bytes
コンパイル時間 1,596 ms
コンパイル使用メモリ 132,036 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-17 00:25:45
合計ジャッジ時間 10,618 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
std::fill( (T*)array, (T*)(array+N), val );
}
template<class T> inline bool chmax(T &a, T b){
if(a<b){
a = b;
return true;
}
return false;
}
template<class T> inline bool chmin(T &a, T b){
if(a>b){
a = b;
return true;
}
return false;
}
class tsort {
public:
int V;
vector<vector<int> > G;
vector<int> deg,res;
tsort(int node_size) : V(node_size), G(V), deg(V, 0){}
void add_edge(int from,int to){
G[from].push_back(to);
deg[to]++;
}
bool solve() {
queue<int> que;
for(int i = 0; i < V; i++){
if(deg[i] == 0){
que.push(i);
}
}
while(!que.empty()){
int p = que.front();
que.pop();
res.push_back(p);
for(int v : G[p]){
if(--deg[v] == 0){
que.push(v);
}
}
}
return (*max_element(deg.begin(),deg.end()) == 0);
}
};
vector<vector<int> > a;
int main(){
int n;
cin >> n;
a.resize(n);
vector<int>res;
tsort ts(2000);
set<int> st;
rep(i,n){
int d;
cin >> d;
a[i].resize(d);
rep(z,d){
cin >> a[i][z];
if(z==d-1){
st.insert(a[i][z]);
}
if(d!=1){
if(z==d-1){
if(a[i][z]!=a[i][0]){
ts.add_edge(a[i][0],a[i][z]);
}
st.insert(a[i][z]);
}
}
}
}
if(!ts.solve()){
cout << 0 << endl;
}else{
cout << 2000 << endl;
auto X = ts.res;
int id = -1;
rep(i,2000){
if(st.count(X[i])){
id = i;
}
}
rep(i,2000){
if(id==i)continue;
cout << X[i] << " ";
}
cout << X[id];
cout << endl;
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0