結果

問題 No.1605 Matrix Shape
ユーザー umezoumezo
提出日時 2021-07-17 04:58:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,425 bytes
コンパイル時間 4,682 ms
コンパイル使用メモリ 266,744 KB
実行使用メモリ 56,228 KB
最終ジャッジ日時 2023-09-20 21:03:15
合計ジャッジ時間 10,079 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,840 KB
testcase_01 AC 4 ms
8,728 KB
testcase_02 AC 4 ms
8,704 KB
testcase_03 WA -
testcase_04 AC 4 ms
8,748 KB
testcase_05 AC 4 ms
8,812 KB
testcase_06 WA -
testcase_07 AC 4 ms
8,688 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 4 ms
8,688 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 3 ms
8,684 KB
testcase_14 WA -
testcase_15 AC 4 ms
8,752 KB
testcase_16 WA -
testcase_17 AC 4 ms
8,696 KB
testcase_18 AC 4 ms
8,780 KB
testcase_19 AC 213 ms
56,228 KB
testcase_20 WA -
testcase_21 AC 172 ms
35,280 KB
testcase_22 AC 217 ms
40,164 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 84 ms
15,268 KB
testcase_28 AC 86 ms
15,256 KB
testcase_29 AC 84 ms
15,384 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 141 ms
22,020 KB
testcase_34 WA -
testcase_35 AC 159 ms
34,192 KB
testcase_36 AC 99 ms
32,200 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<<n<<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,n){
      if(seen[i]==0) b=false;
    }
    if(b) cout<<1<<endl;
    else cout<<0<<endl;
  }
    
  return 0;
}
0