結果

問題 No.1401 全自動マクロの作り方
ユーザー chocoruskchocorusk
提出日時 2021-02-24 09:38:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,410 bytes
コンパイル時間 1,293 ms
コンパイル使用メモリ 133,848 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-24 17:10:48
合計ジャッジ時間 11,571 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 WA -
testcase_07 AC 3 ms
4,348 KB
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:41:10: warning: 'a' may be used uninitialized [-Wmaybe-uninitialized]
   41 |         a--; b--;
      |         ~^~
main.cpp:34:13: note: 'a' was declared here
   34 |         int a, b;
      |             ^

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <stack>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n; cin>>n;
    vector<int> g[2020];
    int deg[2020]={};
    for(int i=0; i<n; i++){
        int d; cin>>d;
        int a, b;
        for(int j=0; j<d; j++){
            int s; cin>>s;
            if(j==0) a=s;
            if(j==d-1) b=s;
        }
        if(a==b) continue;
        a--; b--;
        g[a].push_back(b);
        deg[b]++;
    }
    const int N=2000;
    queue<int> que;
    for(int i=0; i<N; i++){
        if(deg[i]==0) que.push(i);
    }
    vector<int> ans;
    while(!que.empty()){
        int x=que.front(); que.pop();
        ans.push_back(x);
        for(auto y:g[x]){
            deg[y]--;
            if(deg[y]==0) que.push(y);
        }
    }
    if(ans.size()<N) cout<<0<<endl;
    else{
        cout<<N<<endl;
        for(int i=0; i<N; i++){
            cout<<ans[i]+1;
            if(i<N-1) cout<<" ";
        }
        cout<<endl;
    }
    return 0;
}
0