結果

問題 No.1865 Make Cycle
ユーザー 蜜蜂蜜蜂
提出日時 2022-03-04 22:13:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,616 bytes
コンパイル時間 4,185 ms
コンパイル使用メモリ 228,932 KB
実行使用メモリ 8,008 KB
最終ジャッジ日時 2023-09-26 01:18:37
合計ジャッジ時間 5,903 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 1 ms
4,380 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:64:12: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   64 |       auto [a,b]=edge[i];
      |            ^

ソースコード

diff #

//g++ 2.cpp -std=c++14 -O2 -I .
#include <bits/stdc++.h>
using namespace std;

#include <atcoder/all>
using namespace atcoder;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vst = vector<string>;
using vvst = vector<vst>;

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end())

void dfs(vvi &g,vi &seen,int now,int par,int &flg){
  seen[now]=1;

  for(int next:g[now]){
    if(seen[next]==1){
      flg=0;
      return;
    }
    dfs(g,seen,next,now,flg);
  }
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n,q;
  cin>>n>>q;

  vector<pair<int,int>> edge(q);
  rep(i,0,q){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    edge[i]={a,b};
  }

  int ng=0,ok=q+1;
  while(ok-ng>1){
    int check=(ok+ng)/2;
    vvi g(n);
    rep(i,0,check){
      auto [a,b]=edge[i];
      g[a].emplace_back(b);
    }

    cerr<<check<<endl;

    int flg=1;
    vi seen(n,0);
    rep(i,0,n){
      if(seen[i]==0){
        dfs(g,seen,i,-1,flg);
      }
    }

    if(flg==1){
      ng=check;
    }
    else{
      ok=check;
    }
  }

  if(ok==q+1){
    cout<<-1<<endl;
    return 0;
  }
  cout<<ok<<endl;
}
0