結果
問題 |
No.1865 Make Cycle
|
ユーザー |
![]() |
提出日時 | 2022-03-04 22:03:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,612 bytes |
コンパイル時間 | 3,219 ms |
コンパイル使用メモリ | 231,212 KB |
実行使用メモリ | 816,468 KB |
最終ジャッジ日時 | 2024-07-18 20:30:13 |
合計ジャッジ時間 | 8,642 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 4 |
other | MLE * 1 -- * 19 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:64:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 64 | auto [a,b]=edge[i]; | ^
ソースコード
//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(next==par){ 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; }