結果

問題 No.2464 To DAG
ユーザー t98slidert98slider
提出日時 2023-09-09 11:08:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,040 bytes
コンパイル時間 3,733 ms
コンパイル使用メモリ 173,452 KB
実行使用メモリ 43,240 KB
最終ジャッジ日時 2023-09-09 11:08:45
合計ジャッジ時間 21,336 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 WA -
testcase_02 WA -
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 108 ms
14,568 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,504 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 28 ms
6,892 KB
testcase_27 AC 186 ms
22,988 KB
testcase_28 AC 187 ms
22,984 KB
testcase_29 AC 188 ms
22,032 KB
testcase_30 AC 127 ms
12,700 KB
testcase_31 AC 111 ms
10,860 KB
testcase_32 AC 105 ms
10,336 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 45 ms
5,036 KB
testcase_38 AC 45 ms
4,952 KB
testcase_39 AC 7 ms
12,560 KB
testcase_40 AC 10 ms
12,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    vector<pair<int,int>> ans;
    for(int i = 0; i < m; i++){
        int u, v;
        cin >> u >> v;
        g[--u].emplace_back(--v);
    }
    vector<int> idx(n), visited(n);
    auto dfs = [&](auto dfs, int v) -> int {
        if(idx[v] == g[v].size()) return -1;
        if(visited[v]) return v;
        visited[v] = true;
        for(int &j = idx[v]; j < g[v].size(); ){
            int u = g[v][j++];
            int res = dfs(dfs, u);
            if(res != -1){
                if(res != v){
                    visited[v] = false;
                    return res;
                }
            }else{
                ans.emplace_back(v + 1, u + 1);
            }
        }
        return -1;
    };
    for(int v = 0; v < n; v++) dfs(dfs, v);
    cout << n << ' ' << ans.size() << '\n';
    for(auto &&pa : ans) cout << pa.first << ' ' << pa.second << '\n';
}
0