結果

問題 No.2464 To DAG
ユーザー fumofumofunifumofumofuni
提出日時 2023-09-10 21:22:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,150 bytes
コンパイル時間 2,557 ms
コンパイル使用メモリ 208,236 KB
実行使用メモリ 38,984 KB
最終ジャッジ日時 2023-09-10 21:22:36
合計ジャッジ時間 29,734 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 351 ms
38,984 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 459 ms
18,848 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 130 ms
7,680 KB
testcase_27 AC 748 ms
29,956 KB
testcase_28 AC 741 ms
30,104 KB
testcase_29 AC 714 ms
30,404 KB
testcase_30 AC 643 ms
19,408 KB
testcase_31 AC 617 ms
18,432 KB
testcase_32 AC 633 ms
17,396 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 10 ms
14,716 KB
testcase_40 AC 10 ms
14,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")

#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,1,0,-1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n,m;cin >> n >> m;
    vvl g(n);
    rep(i,m){
        ll a,b;cin >> a >> b;a--;b--;
        g[a].emplace_back(b);
    }
    vl itr(n);//今何番目のedgeを見ているか?
    vl vis(n);//
    auto dfs=[&](auto &self,ll v) -> ll {
        vis[v]=1;
        for(ll &i=itr[v];i<g[v].size();i++){
            ll to=g[v][i];
            if(vis[to]==1){
                g[v][i]=-1;
                i++;
                vis[v]=0;
                return to;
            }
            auto f=self(self,to);
            if(f>=0){
                g[v][i]=-1;
                if(f!=v){
                    vis[v]=0;
                    i++;
                    return f;
                }
            }
            i++;
        }
        vis[v]=0;
        return -1;
    };
    rep(i,n)dfs(dfs,i);
    vpl ans;
    rep(i,n){
        for(auto p:g[i]){
            if(p==-1)continue;
            ans.emplace_back(i,p);
        }
    }
    cout << n <<" " << ans.size() << endl;
    for(auto p:ans)cout << p.first+1 <<" " << p.second+1 << endl;

}


0