結果

問題 No.1553 Lovely City
ユーザー 👑 NachiaNachia
提出日時 2021-06-18 21:44:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,115 bytes
コンパイル時間 770 ms
コンパイル使用メモリ 80,236 KB
実行使用メモリ 14,576 KB
最終ジャッジ日時 2023-09-04 22:41:20
合計ジャッジ時間 9,590 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 RE -
testcase_07 WA -
testcase_08 RE -
testcase_09 RE -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 RE -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <atcoder/modint>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

using mll = atcoder::modint998244353;

int N,M;
vector<vector<int>> E;
vector<int> inIdx;
vector<int> I;
vector<int> F;

void testcase(){
  cin >> N >> M;
  E.resize(N);
  inIdx.assign(N,0);
  F.assign(N,0);
  rep(i,M){
    int u,v; cin >> u >> v; u--; v--;
    E[u].push_back(v);
    inIdx[v]++;
    F[u] = F[v] = 1;
  }

  rep(i,N) if(inIdx[i] == 0) I.push_back(i);
  for(int i=0; i<N; i++){
    int p = I[i];
    for(int e : E[p]) if(0 == --inIdx[e]) I.push_back(e);
  }

  bool cy = false;
  for(int i=0; i<N; i++) if(inIdx[i] != 0) cy = true;
  
  if(cy){
    I.clear();
    rep(i,N) if(F[i]) I.push_back(i);
    I.push_back(I.front());
  }

  cout << ((int)I.size()-1) << "\n";
  rep(i,I.size()-1){
    cout << (I[i]+1) << " " << (I[i+1]+1) << "\n";
  }
}

int main(){
  testcase();
  return 0;
}

struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_inst;
0