結果

問題 No.2464 To DAG
ユーザー planesplanes
提出日時 2023-09-08 22:32:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,391 bytes
コンパイル時間 2,617 ms
コンパイル使用メモリ 174,188 KB
実行使用メモリ 52,476 KB
最終ジャッジ日時 2023-09-08 22:32:38
合計ジャッジ時間 28,410 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 210 ms
52,476 KB
testcase_03 AC 562 ms
26,896 KB
testcase_04 AC 468 ms
23,716 KB
testcase_05 AC 426 ms
23,416 KB
testcase_06 AC 381 ms
22,272 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 113 ms
6,996 KB
testcase_27 AC 594 ms
26,984 KB
testcase_28 AC 603 ms
27,076 KB
testcase_29 AC 567 ms
26,792 KB
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 TLE -
testcase_36 RE -
testcase_37 TLE -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

  #include <bits/stdc++.h> 
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 #define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

ll INF=2e18;
vector<vector<pair<ll,ll>>> vec;
vector<bool> del;
vector<bool> this_sec;
vector<bool> check;
vector<bool> check_edge;


ll dfs(ll now) {

  if(this_sec[now]) {
    return now;
  }
  if(check[now]) return -1;

  this_sec[now]=true;

  for(auto x:vec[now]) {
    if(del[x.second]||check_edge[x.second]) continue;

    ll k=dfs(x.first);
    if(k>=0) {
      del[x.second]=true;

      if(k!=now) {
        this_sec[now]=false;
        return k;
      }
    }

    else check_edge[x.second]=true;
  }

  check[now]=true;
  this_sec[now]=false;
  
  return -1;

}


int main() {
    ios::sync_with_stdio(false);
  cin.tie(0);
  
  ll N,M;cin>>N>>M;
vec=vector<vector<pair<ll,ll>>> (N,vector<pair<ll,ll>> (0));
del=vector<bool> (M);
check=vector<bool> (N);
check_edge=vector<bool> (N);
this_sec=vector<bool> (N);


for(ll i=0;i<M;i++) {
  ll U,V;cin>>U>>V;
  U--;V--;
  vec[U].push_back(make_pair(V,i));
}


for(ll i=0;i<N;i++) {
  ll k=dfs(i);
}

vector<pair<ll,ll>> ans(0);
for(ll i=0;i<N;i++) {
  for(auto x:vec[i]) {
    if(del[x.second]) continue;
    ans.push_back(make_pair(i+1,x.first+1));
  }
}

cout<<N<<" "<<ans.size()<<endl;
for(auto x:ans) cout<<x.first<<" "<<x.second<<endl;
}




0