結果

問題 No.1865 Make Cycle
ユーザー 👑 hitonanodehitonanode
提出日時 2023-05-10 07:11:27
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 208 ms / 3,000 ms
コード長 541 bytes
コンパイル時間 1,128 ms
コンパイル使用メモリ 106,800 KB
実行使用メモリ 12,280 KB
最終ジャッジ日時 2023-08-17 15:26:27
合計ジャッジ時間 6,612 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
8,340 KB
testcase_01 AC 110 ms
7,392 KB
testcase_02 AC 178 ms
8,912 KB
testcase_03 AC 94 ms
8,464 KB
testcase_04 AC 146 ms
9,960 KB
testcase_05 AC 188 ms
9,500 KB
testcase_06 AC 165 ms
8,592 KB
testcase_07 AC 151 ms
8,292 KB
testcase_08 AC 173 ms
10,100 KB
testcase_09 AC 154 ms
9,800 KB
testcase_10 AC 195 ms
9,344 KB
testcase_11 AC 152 ms
9,464 KB
testcase_12 AC 150 ms
8,488 KB
testcase_13 AC 146 ms
8,320 KB
testcase_14 AC 113 ms
8,260 KB
testcase_15 AC 188 ms
8,988 KB
testcase_16 AC 176 ms
12,280 KB
testcase_17 AC 146 ms
7,860 KB
testcase_18 AC 202 ms
9,988 KB
testcase_19 AC 208 ms
11,232 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/scc>
#include <iostream>
using namespace std;

int A[100000];
int B[100000];

int main() {
    cin.tie(nullptr), ios::sync_with_stdio(false);
    int N, Q;
    cin >> N >> Q;
    for (int q = 0; q < Q; ++q) cin >> A[q] >> B[q];

    int ng = 0, ok = Q + 1;
    while (ok - ng > 1) {
        const int c = (ok + ng) / 2;
        atcoder::scc_graph g(N + 1);
        for (int e = 0; e < c; ++e) g.add_edge(A[e], B[e]);
        (int(g.scc().size()) < N + 1 ? ok : ng) = c;
    }
    cout << (ok == Q + 1 ? -1 : ok) << '\n';
}
0