結果

問題 No.2403 "Eight" Bridges of Königsberg
ユーザー 👑 amentorimaruamentorimaru
提出日時 2023-06-29 22:42:06
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 587 bytes
コンパイル時間 3,143 ms
コンパイル使用メモリ 97,200 KB
実行使用メモリ 12,924 KB
最終ジャッジ日時 2023-10-12 05:52:24
合計ジャッジ時間 8,565 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 AC 44 ms
4,352 KB
testcase_05 AC 86 ms
4,348 KB
testcase_06 AC 93 ms
4,348 KB
testcase_07 AC 56 ms
4,348 KB
testcase_08 AC 65 ms
4,348 KB
testcase_09 AC 100 ms
4,348 KB
testcase_10 AC 94 ms
4,352 KB
testcase_11 AC 73 ms
4,352 KB
testcase_12 AC 100 ms
4,348 KB
testcase_13 AC 67 ms
4,352 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 WA -
testcase_17 AC 2 ms
4,348 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
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 <iostream>
#include <vector>
#include <unordered_map>
#include <atcoder/dsu.hpp>

using namespace std;
using namespace atcoder;
using ll = long long;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> in(n), out(n);
  dsu d(n);
  for (ll i = 0; i < m; i++) {
    ll u, v;
    cin >> u >> v;
    u--; v--;
    out[u]++;
    in[v]++;
    d.merge(u, v);
  }

  unordered_map<ll, ll> ind;
  for (ll i = 0; i < n; i++)
    ind[d.leader(i)] += max(0LL, in[i] - out[i]);

  ll ans = 0;
  for (auto& [k, v] : ind) {
    ans += max(1LL, v);
  }
  cout << max(0LL, ans - 1) << "\n";
}
0