結果
問題 |
No.1865 Make Cycle
|
ユーザー |
![]() |
提出日時 | 2025-05-14 12:47:20 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 181 ms / 3,000 ms |
コード長 | 729 bytes |
コンパイル時間 | 5,206 ms |
コンパイル使用メモリ | 335,108 KB |
実行使用メモリ | 12,064 KB |
最終ジャッジ日時 | 2025-05-14 12:47:32 |
合計ジャッジ時間 | 10,164 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 20 |
ソースコード
#include <atcoder/all> #include <bits/stdc++.h> #define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++) using namespace atcoder; using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vector<int> u(m), v(m); rep(i, 0, m) cin >> u[i] >> v[i], u[i]--, v[i]--; int ac = 0, wa = m + 1; while (wa - ac > 1) { scc_graph gr(n); int mid = (ac + wa) / 2; rep(i, 0, mid) gr.add_edge(u[i], v[i]); auto scc = gr.scc(); if ((int)scc.size() == n) { ac = mid; } else { wa = mid; } } int ans = (wa == m + 1) ? -1 : wa; cout << ans << endl; }