結果

問題 No.2403 "Eight" Bridges of Königsberg
ユーザー SSRSSSRS
提出日時 2023-08-04 22:18:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,277 bytes
コンパイル時間 1,937 ms
コンパイル使用メモリ 171,524 KB
実行使用メモリ 13,184 KB
最終ジャッジ日時 2024-04-22 20:35:37
合計ジャッジ時間 6,859 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 55 ms
5,888 KB
testcase_05 AC 131 ms
7,296 KB
testcase_06 AC 148 ms
8,192 KB
testcase_07 AC 69 ms
6,308 KB
testcase_08 AC 89 ms
6,784 KB
testcase_09 AC 143 ms
8,192 KB
testcase_10 AC 125 ms
7,680 KB
testcase_11 AC 100 ms
6,784 KB
testcase_12 AC 134 ms
8,064 KB
testcase_13 AC 96 ms
6,912 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 WA -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
権限があれば一括ダウンロードができます

ソースコード

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]);
    }
    cout << (a - 2) / 2 << endl;
  } else {
    assert(false);
    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);
    }
    ans -= 2 * (cc - 1);
    ans /= 2;
    cout << ans << endl;
  }
}
0