結果

問題 No.2464 To DAG
ユーザー 鴨志田卓鴨志田卓
提出日時 2023-12-15 03:15:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,290 bytes
コンパイル時間 2,598 ms
コンパイル使用メモリ 212,568 KB
実行使用メモリ 65,548 KB
最終ジャッジ日時 2023-12-15 03:15:53
合計ジャッジ時間 29,152 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
12,372 KB
testcase_01 WA -
testcase_02 AC 704 ms
65,548 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 474 ms
31,060 KB
testcase_16 AC 230 ms
22,612 KB
testcase_17 AC 23 ms
13,908 KB
testcase_18 AC 113 ms
18,644 KB
testcase_19 AC 5 ms
12,372 KB
testcase_20 AC 5 ms
12,372 KB
testcase_21 AC 5 ms
12,372 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 70 ms
16,468 KB
testcase_27 AC 494 ms
33,236 KB
testcase_28 AC 520 ms
33,236 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,884 KB
testcase_40 AC 7 ms
12,884 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, vis[N], dep[N];
vector<int> g[N], stk;

set<pii> s;

void dfs(int u) {
    vis[u] = 1;
    stk.push_back(u);
    for(int v : g[u]) {
        if(!vis[v]) {
            dep[v] = dep[u] + 1;
            dfs(v);
        }else if(vis[u] == 1 && vis[v] == 1 && stk.size() > dep[u] - dep[v] && stk[stk.size() + dep[v] - dep[u] - 1] == v) {
            s.erase({u, v});
            while(stk.back() != v) {
                int x = stk.back();
                vis[stk.back()] = -1;
                stk.pop_back();
                s.erase({stk.back(), x});
            }
        }
    }
    if(stk.back() == u) {
        vis[u] = -1;
        stk.pop_back();
    }
}

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(!vis[i])
            dfs(i);

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