結果
問題 |
No.2403 "Eight" Bridges of Königsberg
|
ユーザー |
![]() |
提出日時 | 2023-08-04 22:03:46 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,967 bytes |
コンパイル時間 | 1,055 ms |
コンパイル使用メモリ | 117,840 KB |
最終ジャッジ日時 | 2025-02-15 22:45:46 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 WA * 10 |
ソースコード
#include <algorithm> #include <bit> #include <bitset> #include <cassert> #include <cstdio> #include <cstdlib> #include <cmath> #include <deque> #include <iostream> #include <map> #include <random> #include <unordered_set> #include <unordered_map> #include <vector> #include <set> #include <string> using namespace::std; template<typename T, typename U> ostream& operator<< (ostream& o, const pair<T, U>& p) { o << "<" << p.first << ", " << p.second << ">"; return o; } template <typename T> ostream& operator<< (ostream& o, const vector<T>& v) { for (const auto& x : v) o << x << " "; return o; } template <typename T> ostream& operator<< (ostream& o, const set<T>& v) { for (const auto& x : v) o << x << " "; return o; } template <typename T> ostream& operator<< (ostream& o, const deque<T>& v) { for (const auto& x : v) o << x << " "; return o; } template <typename K, typename V> ostream& operator<<(ostream& o, const unordered_map<K, V>& m) { o << "{"; for (const auto& [k, v] : m) o << " " << k << ": " << v << ","; o << "}"; return o; } template <typename T> ostream& operator<< (ostream& o, const vector<vector<T>>& v) { for (const auto& x : v) o << x << endl; return o; } ostream& operator<< (ostream& o, const vector<string>& v) { for (const auto& x : v) o << x << endl; return o; } template <typename T> istream& operator>> (istream& i, vector<T>& v) { for (auto& x : v) i >> x; return i; } istream& operator>> (istream& i, pair<int, int>& p) { i >> p.first >> p.second; return i; } int main() { ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector<int> in(n + 1), out(n + 1); for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; ++out[u]; ++in[v]; } long long hi = 0, lo = 0; for (int i = 1; i <= n; ++i) { if (in[i] > out[i]) hi += in[i] - out[i]; if (out[i] > in[i]) lo += out[i] - in[i]; } cout << max(0ll, max(hi, lo) - 1) << endl; return 0; }