結果

問題 No.2464 To DAG
ユーザー 鴨志田卓鴨志田卓
提出日時 2023-12-15 03:32:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,253 bytes
コンパイル時間 2,456 ms
コンパイル使用メモリ 212,536 KB
実行使用メモリ 69,080 KB
最終ジャッジ日時 2023-12-15 03:33:02
合計ジャッジ時間 23,550 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
12,376 KB
testcase_01 WA -
testcase_02 AC 715 ms
69,080 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 WA -
testcase_15 AC 480 ms
31,064 KB
testcase_16 AC 204 ms
22,616 KB
testcase_17 AC 21 ms
13,912 KB
testcase_18 AC 98 ms
18,648 KB
testcase_19 AC 5 ms
12,376 KB
testcase_20 AC 5 ms
12,376 KB
testcase_21 AC 5 ms
12,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 67 ms
16,472 KB
testcase_27 AC 540 ms
33,240 KB
testcase_28 AC 506 ms
33,240 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
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,888 KB
testcase_40 AC 7 ms
12,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

void fileIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

using pii = pair<int, int>;
const int N = 3e5 + 10;

int n, m, low[N], dfn[N], dcnt;
vector<int> g[N], stk;

set<pii> s;

void dfs(int u) {
    low[u] = dfn[u] = ++dcnt;
    for(int v : g[u]) {
        if(!dfn[v]) {
            dfs(v);
            if(low[v] <= dfn[u]) s.erase({u, v});
            low[u] = min(low[u], low[v]);
        }
    }
    if(low[u] >= dfn[u]) {
        for(int v : g[u]) {
            low[u] = min(low[u], dfn[v]);
        }
        if(low[u] < dfn[u]) {
            for(int v : g[u]) {
                if(dfn[v] == low[u]) {
                    s.erase({u, v});
                    break;
                }
            }
        }
    }
    dfn[u] = N;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m;
    for(int i = 1, u, v; i <= m; i ++) {
        cin >> u >> v;
        g[u].push_back(v);
        s.insert({u, v});
    }

    for(int i = 1; i <= n; i ++)
        if(!dfn[i])
            dfs(i);

    cout << n << " " << s.size() << '\n';
    for(auto &[u, v] : s)
        cout << u << " " << v << "\n";
    return 0;
}
0