結果

問題 No.1865 Make Cycle
ユーザー 👑 colognecologne
提出日時 2022-03-04 21:22:53
言語 C++23(draft)
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 241 ms / 3,000 ms
コード長 604 bytes
コンパイル時間 4,131 ms
コンパイル使用メモリ 258,920 KB
実行使用メモリ 11,760 KB
最終ジャッジ日時 2023-09-25 23:25:20
合計ジャッジ時間 9,426 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 170 ms
8,028 KB
testcase_01 AC 116 ms
7,232 KB
testcase_02 AC 226 ms
8,776 KB
testcase_03 AC 117 ms
8,020 KB
testcase_04 AC 209 ms
9,556 KB
testcase_05 AC 218 ms
9,364 KB
testcase_06 AC 170 ms
8,436 KB
testcase_07 AC 152 ms
8,040 KB
testcase_08 AC 203 ms
9,880 KB
testcase_09 AC 172 ms
9,416 KB
testcase_10 AC 224 ms
9,388 KB
testcase_11 AC 212 ms
9,180 KB
testcase_12 AC 154 ms
8,076 KB
testcase_13 AC 164 ms
8,104 KB
testcase_14 AC 130 ms
7,892 KB
testcase_15 AC 221 ms
8,860 KB
testcase_16 AC 209 ms
11,760 KB
testcase_17 AC 170 ms
7,772 KB
testcase_18 AC 223 ms
9,836 KB
testcase_19 AC 241 ms
10,812 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<atcoder/scc>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N, Q;
    cin >> N >> Q;
    vector<pair<int, int>> V(Q);
    for(auto&[a, b]: V) cin >> a >> b;
    int ok = Q+1, ng = 0;
    auto can = [&](int x)
    {
        atcoder::scc_graph G(N);
        for(int i=0; i<x; ++i)
        {
            auto [a, b] = V[i];
            G.add_edge(a-1, b-1);
        }
        return (int)G.scc().size() != N;
    };
    while(ng+1!=ok)
    {
        int mi = (ok+ng)/2;
        if(can(mi)) ok = mi;
        else ng = mi;
    }
    if(ok == Q+1) ok = -1;
    cout << ok << endl;
}
0