結果

問題 No.2464 To DAG
ユーザー planesplanes
提出日時 2023-09-08 22:46:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 709 ms / 2,000 ms
コード長 1,475 bytes
コンパイル時間 1,976 ms
コンパイル使用メモリ 185,260 KB
実行使用メモリ 86,480 KB
最終ジャッジ日時 2023-09-08 22:47:41
合計ジャッジ時間 25,513 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 359 ms
86,480 KB
testcase_03 AC 679 ms
38,224 KB
testcase_04 AC 571 ms
35,036 KB
testcase_05 AC 553 ms
36,276 KB
testcase_06 AC 515 ms
35,004 KB
testcase_07 AC 447 ms
23,152 KB
testcase_08 AC 534 ms
26,756 KB
testcase_09 AC 455 ms
24,612 KB
testcase_10 AC 446 ms
23,232 KB
testcase_11 AC 294 ms
17,636 KB
testcase_12 AC 227 ms
14,788 KB
testcase_13 AC 310 ms
17,964 KB
testcase_14 AC 443 ms
23,824 KB
testcase_15 AC 501 ms
28,804 KB
testcase_16 AC 237 ms
17,260 KB
testcase_17 AC 38 ms
5,132 KB
testcase_18 AC 157 ms
11,560 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 343 ms
20,692 KB
testcase_23 AC 339 ms
20,840 KB
testcase_24 AC 332 ms
20,808 KB
testcase_25 AC 339 ms
20,704 KB
testcase_26 AC 113 ms
9,192 KB
testcase_27 AC 675 ms
34,752 KB
testcase_28 AC 678 ms
37,020 KB
testcase_29 AC 709 ms
34,652 KB
testcase_30 AC 696 ms
24,308 KB
testcase_31 AC 693 ms
22,172 KB
testcase_32 AC 669 ms
21,556 KB
testcase_33 AC 447 ms
30,408 KB
testcase_34 AC 220 ms
17,284 KB
testcase_35 AC 360 ms
21,008 KB
testcase_36 AC 353 ms
20,968 KB
testcase_37 AC 259 ms
20,900 KB
testcase_38 AC 256 ms
20,908 KB
testcase_39 AC 10 ms
17,100 KB
testcase_40 AC 10 ms
17,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

  #include <bits/stdc++.h> 
using namespace std;
using ll =int;
#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--)




vector<set<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;

vector<pair<ll,ll>> no;
  for(auto x:vec[now]) {
no.push_back(x);
    ll k=dfs(x.first);

    if(k>=0) {
      del[x.second]=true;
      if(k!=now) {
         for(auto y:no) vec[now].erase(y);
        this_sec[now]=false;
        return k;
      }
    }

    else check_edge[x.second]=true;
  }

  for(auto y:no) vec[now].erase(y);

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

}


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

vector<tuple<ll,ll,ll>> memo(M);


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


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

vector<pair<ll,ll>> ans(0);
for(auto x:memo) {
  if(del[get<2>(x)]) continue;
  ans.push_back(make_pair(get<0>(x),get<1>(x)));
}

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




0