結果

問題 No.1865 Make Cycle
ユーザー hitonanode
提出日時 2023-05-10 07:11:27
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 185 ms / 3,000 ms
コード長 541 bytes
コンパイル時間 1,439 ms
コンパイル使用メモリ 107,364 KB
実行使用メモリ 12,184 KB
最終ジャッジ日時 2024-11-26 12:31:40
合計ジャッジ時間 6,236 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

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