結果
問題 | No.583 鉄道同好会 |
ユーザー | Lepton_s |
提出日時 | 2017-10-27 22:37:59 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 51 ms / 2,000 ms |
コード長 | 1,958 bytes |
コンパイル時間 | 700 ms |
コンパイル使用メモリ | 84,228 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-21 22:32:15 |
合計ジャッジ時間 | 1,538 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <iostream> #include <sstream> #include <functional> #include <map> #include <string> #include <cstring> #include <vector> #include <queue> #include <stack> #include <deque> #include <set> #include <list> #include <numeric> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll,ll> P; const double PI = 3.14159265358979323846; const double EPS = 1e-12; const ll INF = 1LL<<29; const ll mod = 1e9+7; #define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i)) #define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d)) #define all(v) (v).begin(), (v).end() #define pb(x) push_back(x) #define mp(x,y) make_pair((x),(y)) #define mset(m,v) memset((m),(v),sizeof(m)) #define chmin(X,Y) ((X)>(Y)?X=(Y),true:false) #define chmax(X,Y) ((X)<(Y)?X=(Y),true:false) #define fst first #define snd second #define UNIQUE(x) (x).erase(unique(all(x)),(x).end()) template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;} #define N 600 #define MAX_N 600 int d[N]; struct UF { int par[MAX_N],rank[MAX_N]; void init(int n){ for(int i = 0; i < n; i++){ par[i] = i; rank[i] = 0; } } int find(int x){ if(par[x] == x){ return x; }else{ return par[x] = find(par[x]); } } void unite(int x, int y){ x = find(x); y = find(y); if(x == y) return; if(rank[x] < rank[y]){ par[x] = y; }else{ par[y] = par[x]; if(rank[x] == rank[y]) rank[y]++; } } bool same(int x, int y){ return find(x) == find(y); } }; int main(){ int n, m; cin>>n>>m; UF uf; uf.init(n); rep(i, m){ int a, b; cin>>a>>b; d[a]++; d[b]++; uf.unite(a, b); } int odd = 0; rep(i, n) if(d[i]%2) odd++; rep(i, n) rep(j, n) if(d[i]&&d[j]&&!uf.same(i, j)) odd += 3; if(odd>2) cout<<"NO"<<endl; else cout<<"YES"<<endl; return 0; }