結果

問題 No.1605 Matrix Shape
ユーザー umezoumezo
提出日時 2021-07-17 05:08:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,437 bytes
コンパイル時間 4,698 ms
コンパイル使用メモリ 268,064 KB
実行使用メモリ 56,280 KB
最終ジャッジ日時 2023-09-20 21:12:20
合計ジャッジ時間 9,107 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,756 KB
testcase_01 AC 3 ms
8,856 KB
testcase_02 AC 4 ms
8,780 KB
testcase_03 AC 3 ms
8,832 KB
testcase_04 AC 3 ms
8,620 KB
testcase_05 AC 3 ms
8,908 KB
testcase_06 AC 3 ms
8,716 KB
testcase_07 AC 3 ms
8,716 KB
testcase_08 AC 3 ms
8,624 KB
testcase_09 AC 3 ms
8,840 KB
testcase_10 AC 3 ms
8,712 KB
testcase_11 WA -
testcase_12 AC 3 ms
8,724 KB
testcase_13 AC 3 ms
8,616 KB
testcase_14 AC 3 ms
8,708 KB
testcase_15 AC 4 ms
8,644 KB
testcase_16 WA -
testcase_17 AC 3 ms
8,732 KB
testcase_18 WA -
testcase_19 AC 203 ms
56,280 KB
testcase_20 AC 165 ms
35,364 KB
testcase_21 AC 163 ms
35,372 KB
testcase_22 AC 203 ms
40,172 KB
testcase_23 AC 198 ms
49,240 KB
testcase_24 AC 222 ms
43,476 KB
testcase_25 AC 82 ms
15,404 KB
testcase_26 AC 82 ms
15,456 KB
testcase_27 AC 82 ms
15,212 KB
testcase_28 AC 83 ms
15,360 KB
testcase_29 AC 82 ms
15,220 KB
testcase_30 AC 150 ms
19,844 KB
testcase_31 AC 153 ms
20,076 KB
testcase_32 AC 136 ms
22,028 KB
testcase_33 AC 136 ms
21,972 KB
testcase_34 AC 49 ms
15,088 KB
testcase_35 AC 154 ms
33,928 KB
testcase_36 AC 93 ms
32,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;

int deg[200200];
vector<int> G[200200];
int seen[200200];

template <typename T>
vector<T> compress(vector<T> &X){
  vector<T> vals=X;
  sort(vals.begin(),vals.end());
  vals.erase(unique(vals.begin(), vals.end()),vals.end());
  for(int i=0;i<(int)X.size(); i++){
    X[i]=lower_bound(vals.begin(),vals.end(),X[i])-vals.begin();
  }
  return vals;
}

void dfs(int v){
  seen[v]=1;
  for(auto nv:G[v]){
    if(seen[nv]) continue;
    dfs(nv);
  }
}
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int n;
  cin>>n;
  
  vector<int> A(2*n);
  rep(i,2*n) cin>>A[i];
  compress(A);
  vector<int> H(n),W(n);
  int manum=0;
  rep(i,n){
    H[i]=A[2*i],W[i]=A[2*i+1];
    manum=max({manum,H[i],W[i]});
  }

  scc_graph g(manum+1);
  rep(i,n){
    g.add_edge(H[i],W[i]);
    deg[H[i]]++;
    deg[W[i]]++;
    G[H[i]].push_back(W[i]);
  }

  auto scc=g.scc();
  int cnt=0;
  rep(i,n){
    if(deg[i]%2==1) cnt++;
  }
  
  if(scc.size()==1){
    if(cnt==0) cout<<manum+1<<endl;
    else if(cnt==2) cout<<1<<endl;
    else cout<<0<<endl;
  }
  else{
    int s=scc[0][0];
    dfs(s);
    bool b=true;
    rep(i,manum+1){
      if(seen[i]==0) b=false;
    }
    if(b) cout<<1<<endl;
    else cout<<0<<endl;
  }
    
  return 0;
}
0