結果
| 問題 |
No.483 マッチ並べ
|
| コンテスト | |
| ユーザー |
gigime
|
| 提出日時 | 2017-03-12 01:20:32 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,210 bytes |
| コンパイル時間 | 2,360 ms |
| コンパイル使用メモリ | 169,364 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-24 14:33:34 |
| 合計ジャッジ時間 | 3,271 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 53 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
#define ALL(x) x.begin(),x.end()
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;
struct UnionFind{
vector<int> par,rank;
UnionFind(int n) :par(n + 1),rank(n + 1,1){
for(int i = 1;i <= n;i++) par [i] = i;
}
int find(int x){
return par [x] == x ? x : par [x] = find(par [x]);
}
bool connect(int x,int y){
x = find(x);
y = find(y);
if(x == y) return false;
if(rank [x] < rank [y]) swap(x,y);
rank [x] += rank [x] == rank [y];
par [y] = x;
return true;
}
bool same(int x,int y){
return find(x) == find(y);
}
};
int N;
int A [10001];
int main()
{
scanf("%d",&N);
UnionFind uf(10000);
FOR(i,0,N){
int r1,c1,r2,c2;
scanf("%d%d%d%d",&r1,&c1,&r2,&c2);
int x = uf.find(r1 * 100 + c1),y = uf.find(r2 * 100 + c2);
if(x == y){
A [x]++;
}
else{
uf.connect(x,y);
A [uf.find(x)] = A [x] + A [y];
}
}
FOR(i,1,10001){
if(A [i] >= 2){
printf("NO\n");
return 0;
}
}
printf("YES\n");
return 0;
}
gigime