結果

問題 No.1865 Make Cycle
ユーザー たたき@競プロたたき@競プロ
提出日時 2023-08-14 10:23:19
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 113 ms / 3,000 ms
コード長 917 bytes
コンパイル時間 4,881 ms
コンパイル使用メモリ 313,004 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-05-01 22:50:59
合計ジャッジ時間 8,255 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
6,528 KB
testcase_01 AC 60 ms
5,888 KB
testcase_02 AC 100 ms
6,776 KB
testcase_03 AC 59 ms
6,636 KB
testcase_04 AC 76 ms
7,320 KB
testcase_05 AC 69 ms
6,912 KB
testcase_06 AC 70 ms
6,528 KB
testcase_07 AC 82 ms
6,656 KB
testcase_08 AC 102 ms
7,296 KB
testcase_09 AC 65 ms
7,040 KB
testcase_10 AC 101 ms
7,188 KB
testcase_11 AC 84 ms
6,940 KB
testcase_12 AC 77 ms
6,544 KB
testcase_13 AC 98 ms
6,528 KB
testcase_14 AC 61 ms
6,400 KB
testcase_15 AC 95 ms
7,044 KB
testcase_16 AC 93 ms
7,180 KB
testcase_17 AC 69 ms
6,144 KB
testcase_18 AC 68 ms
7,296 KB
testcase_19 AC 113 ms
8,064 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
      
0