結果
問題 | No.583 鉄道同好会 |
ユーザー | tubo28 |
提出日時 | 2017-10-27 22:44:55 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 31 ms / 2,000 ms |
コード長 | 3,703 bytes |
コンパイル時間 | 1,896 ms |
コンパイル使用メモリ | 175,700 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-21 22:37:42 |
合計ジャッジ時間 | 2,463 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 1 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 10 ms
5,248 KB |
testcase_12 | AC | 12 ms
5,248 KB |
testcase_13 | AC | 12 ms
5,248 KB |
testcase_14 | AC | 12 ms
5,248 KB |
testcase_15 | AC | 15 ms
5,248 KB |
testcase_16 | AC | 26 ms
5,248 KB |
testcase_17 | AC | 31 ms
5,248 KB |
testcase_18 | AC | 31 ms
5,248 KB |
ソースコード
#include <bits/stdc++.h> using ll = long long; #define FOR(i, a, b) for (int i = (a); i < int(b); ++i) #define RFOR(i, a, b) for (int i = (b) - 1; i >= int(a); --i) #define rep(i, n) FOR(i, 0, n) #define rep1(i, n) FOR(i, 1, int(n) + 1) #define rrep(i, n) RFOR(i, 0, n) #define rrep1(i, n) RFOR(i, 1, int(n) + 1) #define all(c) begin(c), end(c) std::string highlight(std::string s) { #ifdef _MSC_VER return s; #else return "\033[33m" + s + "\033[0m"; #endif } #ifdef LOCAL #define dump(...) \ do { \ std::ostringstream os; \ os << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \ print_to(os, ", ", "\n", __VA_ARGS__); \ std::cerr << highlight(os.str()); \ } while (0) #define dump_(a) \ do { \ std::ostringstream os; \ os << __LINE__ << ":\t" << #a << " = ["; \ print_to_(os, ", ", "]\n", all(a)); \ std::cerr << highlight(os.str()); \ } while (0) #else #define dump(...) #define dump_(...) #endif template <typename T> void print_to(std::ostream &os, const char *, const char *tail, const T &fst) { os << fst << tail; } template <typename Fst, typename... Rst> void print_to(std::ostream &os, const char *del, const char *tail, const Fst &fst, const Rst &... rst) { os << fst << del; print_to(os, del, tail, rst...); } template <typename Iter> void print_to_(std::ostream &os, const char *del, const char *tail, Iter bgn, Iter end) { for (Iter it = bgn; it != end;) { os << *it; if (++it != end) { os << del; } else { os << tail; } } } template <typename Fst, typename... Rst> void println(const Fst &fst, const Rst &... rst) { print_to(std::cout, "\n", "\n", fst, rst...); } template <typename Fst, typename... Rst> void print(const Fst &fst, const Rst &... rst) { print_to(std::cout, " ", "\n", fst, rst...); } template <typename Iter> void println_(Iter bgn, Iter end) { print_to_(std::cout, "\n", "\n", bgn, end); } template <typename Iter> void print_(Iter bgn, Iter end) { print_to_(std::cout, " ", "\n", bgn, end); } // const int MOD = 1000000007; namespace trush { int _ = (std::cout.precision(10), std::cout.setf(std::ios::fixed), std::cin.tie(0), std::ios::sync_with_stdio(0), 0); } using namespace std; struct uf_tree { std::vector<int> parent; int __size; uf_tree(int size_) : parent(size_, -1), __size(size_) {} void unite(int x, int y) { if ((x = find(x)) != (y = find(y))) { if (parent[y] < parent[x]) std::swap(x, y); parent[x] += parent[y]; parent[y] = x; __size--; } } bool is_same(int x, int y) { return find(x) == find(y); } int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); } int size(int x) { return -parent[find(x)]; } int size() { return __size; } }; int main() { int n, m; while (cin >> n >> m) { vector<int> deg(n); uf_tree ut(n); set<int> s; rep(i, m) { int a, b; cin >> a >> b; ++deg[a]; ++deg[b]; ut.unite(a, b); s.insert(a); s.insert(b); } int odd = 0; rep(i, n) if (deg[i] & 1) ++odd; bool yes = odd <= 2 && ut.size(*s.begin()) == (int)s.size(); print(yes ? "YES" : "NO"); } }