結果

問題 No.2403 "Eight" Bridges of Königsberg
ユーザー SSRSSSRS
提出日時 2023-08-04 22:24:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,292 bytes
コンパイル時間 2,039 ms
コンパイル使用メモリ 172,032 KB
実行使用メモリ 13,000 KB
最終ジャッジ日時 2024-04-22 20:41:31
合計ジャッジ時間 3,736 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 46 ms
6,940 KB
testcase_05 AC 97 ms
7,296 KB
testcase_06 AC 107 ms
8,192 KB
testcase_07 AC 62 ms
6,940 KB
testcase_08 AC 74 ms
6,940 KB
testcase_09 AC 118 ms
8,192 KB
testcase_10 AC 110 ms
7,680 KB
testcase_11 AC 87 ms
6,940 KB
testcase_12 AC 120 ms
8,064 KB
testcase_13 AC 80 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 8 ms
13,000 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 5 ms
8,320 KB
testcase_22 AC 6 ms
11,984 KB
testcase_23 AC 7 ms
11,592 KB
testcase_24 AC 7 ms
10,184 KB
testcase_25 AC 5 ms
9,852 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> E(N);
  vector<vector<int>> E2(N);
  for (int i = 0; i < M; i++){
    int U, V;
    cin >> U >> V;
    U--;
    V--;
    E[U].push_back(V);
    E2[U].push_back(V);
    E2[V].push_back(U);
  }
  int cc = 0;
  vector<int> c(N, -1);
  for (int i = 0; i < N; i++){
    if (c[i] == -1 && !E2[i].empty()){
      c[i] = cc;
      queue<int> Q;
      Q.push(i);
      while (!Q.empty()){
        int v = Q.front();
        Q.pop();
        for (int w : E2[v]){
          if (c[w] == -1){
            c[w] = c[v];
            Q.push(w);
          }
        }
      }
      cc++;
    }
  }
  vector<int> in(N, 0), out(N, 0);
  for (int i = 0; i < N; i++){
    for (int j : E[i]){
      out[i]++;
      in[j]++;
    }
  }
  if (cc == 1){
    int a = 0;
    for (int i = 0; i < N; i++){
      a += abs(in[i] - out[i]);
    }
    if (a == 0){
      cout << 0 << endl;
    } else {
      cout << (a - 2) / 2 << endl;
    }
  } else {
    vector<int> D(cc, 0);
    for (int i = 0; i < N; i++){
      if (!E[i].empty()){
        D[c[i]] += abs(in[i] - out[i]);
      }
    }
    int ans = 0;
    for (int i = 0; i < cc; i++){
      ans += max(D[i], 2);
    }
    cout << (ans - 2) / 2 << endl;
  }
}
0