結果

問題 No.2464 To DAG
ユーザー t98slidert98slider
提出日時 2023-09-09 11:21:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,027 bytes
コンパイル時間 2,905 ms
コンパイル使用メモリ 173,884 KB
実行使用メモリ 44,576 KB
最終ジャッジ日時 2023-09-09 11:21:48
合計ジャッジ時間 25,730 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
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,572 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 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 29 ms
6,772 KB
testcase_27 AC 186 ms
23,680 KB
testcase_28 AC 189 ms
23,588 KB
testcase_29 AC 182 ms
22,368 KB
testcase_30 AC 139 ms
13,848 KB
testcase_31 AC 114 ms
11,944 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 7 ms
12,444 KB
testcase_40 AC 7 ms
12,344 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 + 1);
    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] = 1;
        for(int &j = idx[v]; j < g[v].size(); j++){
            int u = g[v][j];
            int res = dfs(dfs, u);
            if(res != -1){
                if(res != v){
                    visited[v] = 0;
                    return res;
                }
            }else{
                ans.emplace_back(v, u);
            }
        }
        return -1;
    };
    for(int v = 1; v <= n; v++) dfs(dfs, v);
    cout << n << ' ' << ans.size() << '\n';
    for(auto &&pa : ans) cout << pa.first << ' ' << pa.second << '\n';
}
0