結果
問題 | No.583 鉄道同好会 |
ユーザー |
👑 |
提出日時 | 2023-03-26 00:46:16 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 69 ms / 2,000 ms |
コード長 | 1,188 bytes |
コンパイル時間 | 834 ms |
コンパイル使用メモリ | 84,064 KB |
最終ジャッジ日時 | 2025-02-11 18:08:59 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:63:29: warning: ‘x’ may be used uninitialized [-Wmaybe-uninitialized] 63 | if((odd == 0 || odd == 2) && d == x)cout << "YES" << endl; | ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~ main.cpp:58:14: note: ‘x’ was declared here 58 | int d = n, x; | ^
ソースコード
#include <iostream> #include <vector> #include <map> using namespace std; struct UnionFind { int n; vector<int> par; vector<int> size_; UnionFind(int n_) : n(n_), par((size_t)n_), size_((size_t)n_,1){ for(int i = 0; n > i; i++)par[i] = i; } int root(int x){ if(par[x] == x)return x; return par[x] = root(par[x]); } void unite(int a,int b){ int ra = root(a); int rb = root(b); if(ra==rb)return; if(size(ra) > size(rb)) swap(ra,rb); par[ra] = rb; size_[rb] += size_[ra]; } bool same(int a, int b){ return root(a) == root(b); } int size(int a){ return size_[root(a)]; } void debug(){ for(int i = 0; n > i; i++){ cout << size_[root(i)] << " "; } cout << endl; return; } }; int main(){ int n,m;cin>>n>>m; map<int,int> A; UnionFind B(n); for(int i = 0; m > i; i++){ int a,b;cin>>a>>b; A[a]++;A[b]++; B.unite(a,b); } int odd = 0; for(auto x: A){ odd += x.second%2; } int d = n, x; for(int i = 0; n > i; i++){ if(B.size(i) == 1)d--; else x = B.size(i); } if((odd == 0 || odd == 2) && d == x)cout << "YES" << endl; else cout << "NO" << endl; }