結果

問題 No.2286 Join Hands
ユーザー lgswdnlgswdn
提出日時 2024-03-09 17:44:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,142 bytes
コンパイル時間 2,114 ms
コンパイル使用メモリ 204,468 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-03-09 17:44:13
合計ジャッジ時間 5,285 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 WA -
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 3 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 WA -
testcase_07 AC 2 ms
6,548 KB
testcase_08 AC 12 ms
6,548 KB
testcase_09 AC 14 ms
6,548 KB
testcase_10 AC 29 ms
6,548 KB
testcase_11 AC 20 ms
6,548 KB
testcase_12 AC 19 ms
6,548 KB
testcase_13 AC 26 ms
6,548 KB
testcase_14 AC 16 ms
6,548 KB
testcase_15 AC 16 ms
6,548 KB
testcase_16 AC 15 ms
6,548 KB
testcase_17 AC 11 ms
6,548 KB
testcase_18 AC 16 ms
6,548 KB
testcase_19 AC 15 ms
6,548 KB
testcase_20 AC 16 ms
6,548 KB
testcase_21 AC 14 ms
6,548 KB
testcase_22 AC 16 ms
6,548 KB
testcase_23 AC 14 ms
6,548 KB
testcase_24 AC 16 ms
6,548 KB
testcase_25 AC 16 ms
6,548 KB
testcase_26 AC 16 ms
6,548 KB
testcase_27 AC 15 ms
6,548 KB
testcase_28 AC 2 ms
6,548 KB
testcase_29 AC 2 ms
6,548 KB
testcase_30 AC 2 ms
6,548 KB
testcase_31 AC 2 ms
6,548 KB
testcase_32 AC 2 ms
6,548 KB
testcase_33 AC 2 ms
6,548 KB
testcase_34 AC 2 ms
6,548 KB
testcase_35 AC 2 ms
6,548 KB
testcase_36 WA -
testcase_37 AC 2 ms
6,548 KB
testcase_38 AC 2 ms
6,548 KB
testcase_39 AC 2 ms
6,548 KB
testcase_40 AC 2 ms
6,548 KB
testcase_41 AC 2 ms
6,548 KB
testcase_42 AC 2 ms
6,548 KB
testcase_43 AC 2 ms
6,548 KB
testcase_44 AC 2 ms
6,548 KB
testcase_45 AC 2 ms
6,548 KB
testcase_46 AC 2 ms
6,548 KB
testcase_47 AC 16 ms
6,548 KB
testcase_48 AC 16 ms
6,548 KB
testcase_49 AC 87 ms
6,548 KB
testcase_50 AC 90 ms
6,548 KB
testcase_51 AC 15 ms
6,548 KB
testcase_52 AC 10 ms
6,548 KB
testcase_53 AC 16 ms
6,548 KB
testcase_54 AC 11 ms
6,548 KB
testcase_55 AC 48 ms
6,548 KB
testcase_56 AC 88 ms
6,548 KB
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 AC 17 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define fi first
#define se second
#define eb emplace_back
#define popc __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef unsigned long long ull;
typedef long double ld;

int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
  return x*w;
}

const int N=10009;

int n,m,c[N],vst[N],ans,sp,sc,np;
vi e[N];

bool dfs(int u) {
  for(int v:e[u]) if(!vst[v]) {
    vst[v]=1;
    if(!c[v]||dfs(c[v])) return c[v]=u,1;
  } return 0;
}

signed main() {
  n=read(), m=read();
  rep(i,1,m) {
    int u=read(), v=read();
    e[u].eb(v+n), e[v].eb(u+n);
    e[v+n].eb(u), e[u+n].eb(v);
  }
  rep(i,1,2*n) memset(vst,0,sizeof(vst)), dfs(i);
  rep(i,1,n) {
    if(c[i]) ans++;
    else {
      if(!c[i+n]) sp++, np=i;
      else sc++;
    }
  }
  if(sp!=1||sc) printf("%d\n",ans-sp-sc);
  else if(e[np].size()) printf("%d\n",ans-sp-sc);
  return 0;
}
0