結果
問題 | No.2202 贅沢てりたまチキン |
ユーザー | |
提出日時 | 2023-02-03 21:39:08 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 220 ms / 2,000 ms |
コード長 | 4,413 bytes |
コンパイル時間 | 3,089 ms |
コンパイル使用メモリ | 254,816 KB |
実行使用メモリ | 16,572 KB |
最終ジャッジ日時 | 2024-07-02 19:28:28 |
合計ジャッジ時間 | 6,075 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ull = uint64_t; using ll = int64_t; using vi = vector<int>; using vll = vector<ll>; using vs = vector<string>; using ld = long double; using P = pair<ll,ll>; using G = vector<vector<int>>; #define LO(...) (void)0 #define debug(x) (void)0 #define reps(i,a,n) for(ll i##_len = (ll)(n), i = (a); i < i##_len; ++i) #define rep(i,n) reps(i,0,(n)) #define rrep(i,n) reps(i,1,(n)+1) #define repd(i,n) for(ll i=(n)-1;i>=0;i--) #define rrepd(i,n) for(ll i=(n);i>=1;i--) #define inp(i) ll i; cin >> i; #define inps(s) string s; cin >> s; #define inpp(p) cin >> (p).first >> (p).second #define inpv(v,N) vll v(N);rep(i,N)cin>>v[i]; #define inpvs(v,N) vs v(N);rep(i,N)cin>>v[i]; #define all(v) begin(v),end(v) #define Yes cout<<"Yes\n" #define No cout<<"No\n" #define allok(i,N,pred) [&]()->bool{bool allok_=1;rep(i,N)if(!(pred))allok_=0;return allok_;}() #define anyok(i,N,pred) [&]()->bool{bool anyok_=0;rep(i,N)if(pred)anyok_=1;return anyok_;}() void YESNO(bool b){cout<<(b?"YES\n":"NO\n");}void yesno(bool b){cout<<(b?"yes\n":"no\n");}void YesNo(bool b){cout<<(b?"Yes\n":"No\n");} #define SP cout << " " #define ENDL cout << "\n" #define setfp cout << fixed << setprecision(16) template<typename C>void ou(const C&v){cout<<v;} template<typename C>void ous(const C&v){cout<<v<<" ";} template<typename C>void oul(const C&v){cout<<v<<"\n";} template<typename C>void ouv(const C &v){for(auto &&e:v){cout << e;if(&e != &v.back()) cout << ' ';}cout << "\n";} template<typename C>void ouvadd(const C &v){for(auto &&e:v){cout << e+1;if(&e != &v.back()) cout << ' ';}cout << "\n";} template<typename T>bool chmax(T &a, const T &b){return a<b?(a=b,1):0;} template<typename T>bool chmin(T &a, const T &b){return b<a?(a=b,1):0;} template<typename T>void so(T &a){sort(begin(a),end(a));} template<typename T,typename C>void so(T &a,C c){sort(begin(a),end(a),c);} template<typename T>void rso(T &a){sort(rbegin(a),rend(a));} template<typename T,typename C>void rso(T &a,C c){sort(rbegin(a),rend(a),c);} constexpr ll INF = 1e18; #ifndef ATCODER_DSU_HPP #define ATCODER_DSU_HPP 1 #include <algorithm> #include <cassert> #include <vector> namespace atcoder { // Implement (union by size) + (path compression) // Reference: // Zvi Galil and Giuseppe F. Italiano, // Data structures and algorithms for disjoint set union problems struct dsu { public: dsu() : _n(0) {} explicit dsu(int n) : _n(n), parent_or_size(n, -1) {} int merge(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); int x = leader(a), y = leader(b); if (x == y) return x; if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y); parent_or_size[x] += parent_or_size[y]; parent_or_size[y] = x; return x; } bool same(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); return leader(a) == leader(b); } int leader(int a) { assert(0 <= a && a < _n); if (parent_or_size[a] < 0) return a; return parent_or_size[a] = leader(parent_or_size[a]); } int size(int a) { assert(0 <= a && a < _n); return -parent_or_size[leader(a)]; } std::vector<std::vector<int>> groups() { std::vector<int> leader_buf(_n), group_size(_n); for (int i = 0; i < _n; i++) { leader_buf[i] = leader(i); group_size[leader_buf[i]]++; } std::vector<std::vector<int>> result(_n); for (int i = 0; i < _n; i++) { result[i].reserve(group_size[i]); } for (int i = 0; i < _n; i++) { result[leader_buf[i]].push_back(i); } result.erase( std::remove_if(result.begin(), result.end(), [&](const std::vector<int>& v) { return v.empty(); }), result.end()); return result; } private: int _n; // root node: -1 * component size // otherwise: parent std::vector<int> parent_or_size; }; } // namespace atcoder #endif // ATCODER_DSU_HPP int main() { inp(N); inp(M); G g; g.resize(N); atcoder::dsu ds(N*2); rep(i,M){ inp(a); inp(b); a--,b--; g[a].push_back(b); g[b].push_back(a); ds.merge(a, b+N); ds.merge(a+N, b); } YesNo(allok(i,N,ds.same(i,i+N))); }