結果
問題 |
No.1865 Make Cycle
|
ユーザー |
![]() |
提出日時 | 2023-08-14 10:23:19 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 129 ms / 3,000 ms |
コード長 | 917 bytes |
コンパイル時間 | 5,205 ms |
コンパイル使用メモリ | 313,000 KB |
実行使用メモリ | 7,936 KB |
最終ジャッジ日時 | 2024-11-22 06:24:15 |
合計ジャッジ時間 | 9,357 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 20 |
ソースコード
#include<bits/stdc++.h> using namespace std; #include <atcoder/all> using namespace atcoder; using mint=modint998244353; //1000000007; using ll=long long; using pp=pair<int,int>; #define sr string #define vc vector #define fi first #define se second #define rep(i,n) for(int i=0;i<(int)n;i++) #define pb push_back #define all(v) v.begin(),v.end() #define pque priority_queue #define bpc(a) __builtin_popcount(a) int main(){ int n,q;cin>>n>>q; vc v(n,vc<pp>(0)); rep(i,q){ int a,b;cin>>a>>b; a--; b--; v[a].pb({b,i}); } int ac=q+1,wa=0; while(ac-wa>1){ int x=(ac+wa)/2; vc<int>c(n,0); bool ok=false; auto f=[&](auto f,int a)->void{ c[a]=1; for(auto [au,i]:v[a])if(i<x){ if(c[au]==1)ok=true; if(c[au]==0)f(f,au); } c[a]=-1; }; rep(i,n)if(c[i]==0)f(f,i); if(ok)ac=x; else wa=x; } if(ac==q+1)cout<<-1; else cout<<ac; }