結果

問題 No.1605 Matrix Shape
ユーザー Nzt3Nzt3
提出日時 2021-07-17 20:28:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,105 bytes
コンパイル時間 2,152 ms
コンパイル使用メモリ 184,492 KB
実行使用メモリ 38,980 KB
最終ジャッジ日時 2023-09-21 17:35:22
合計ジャッジ時間 9,497 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
21,024 KB
testcase_01 AC 12 ms
13,844 KB
testcase_02 AC 9 ms
14,216 KB
testcase_03 AC 11 ms
13,788 KB
testcase_04 AC 8 ms
13,904 KB
testcase_05 AC 12 ms
13,988 KB
testcase_06 AC 13 ms
13,872 KB
testcase_07 AC 8 ms
13,980 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 12 ms
13,868 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 12 ms
14,004 KB
testcase_14 AC 12 ms
14,048 KB
testcase_15 AC 12 ms
14,048 KB
testcase_16 AC 12 ms
13,908 KB
testcase_17 AC 13 ms
13,796 KB
testcase_18 AC 12 ms
13,836 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 198 ms
27,320 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const int msize=200001;
int getroot(int n,vector<int> &root){
  if(root[n]==-1)return n;
  else return root[n]=getroot(root[n],root);
}
int main(){
  int N;
  cin>>N;
  vector<int>cnt(msize);
  vector<set<int>>V(msize);
  vector<array<int,2>>E(N);
  for(int i=0;i<N;i++){
    cin>>E[i][0]>>E[i][1];
    cnt[E[i][0]]++,cnt[E[i][1]]--;
    V[E[i][0]].insert(E[i][1]);
  }
  vector<int>root(msize,-1);
  bool ans=0;
  for(int i=0;i<msize;i++){
    int r=getroot(i,root);
    for(auto j:V[i]){
      int r1=getroot(j,root);
      if(r1!=r){
        root[r1]=r;
      }
    }
  }
  set<int>check;
  check.insert(-1);
  for(int i=0;i<msize;i++){
    check.insert(root[i]);
  }
  if(check.size()>2){
    cout<<"0\n";
    return 0;
  }
  sort(cnt.begin(),cnt.end());
  if(cnt[0]==0&&cnt[msize-1]==0){
    set<array<int,2>>ans;
    for(int i=0;i<N;i++){
      for(auto j:V[E[i][1]]){
        ans.insert({E[i][0],j});
      }
    }
    cout<<ans.size()<<'\n';
  }else{
    int ans=1;
    for(int i=1;i<N-1;i++){
      if(cnt[i]!=0)ans=0;
    }
    cout<<ans<<'\n';
  }
}
0