結果
| 問題 |
No.483 マッチ並べ
|
| コンテスト | |
| ユーザー |
IL_msta
|
| 提出日時 | 2017-02-10 23:50:45 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,728 bytes |
| コンパイル時間 | 1,781 ms |
| コンパイル使用メモリ | 122,548 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-12-29 11:22:46 |
| 合計ジャッジ時間 | 3,191 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 44 WA * 9 |
ソースコード
#ifdef __GNUC__
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#endif
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <valarray>
//#include <array>//x C++ (G++ 4.6.4)
#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>
#include <cassert>//assert();
#include <fstream>
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#define PII pair<int,int>
/////////
using namespace::std;
// 最大公約数
template<class T>
inline T gcd(T a, T b){return b == 0 ? a : gcd(b, a % b);}
// 最小公倍数
template<class T>
inline T lcm(T a, T b){return a * b / gcd(a, b);}
////////////////////////////////
class UnionFind{
public:
int cNum;//要素数
vector<int> parent;
UnionFind(int n){
cNum = n;
parent = vector<int>(n);
for(int i=0;i<n;++i){parent[i] = i;}
}
int find(int x){
if( parent[x] == x ){return x;}
return parent[x] = find( parent[x] );
}
bool same(int x,int y){return find(x) == find(y);}
void add(int x,int y){//union
x = find(x);
y = find(y);
if( x==y )return;
parent[x] = y;
}
};
inline void solve(){
int N;
cin >> N;
int R,C,RR,CC;
vector< vector<int> > G(10000);
vector< bool > used(10001,false);
set<int> nodeSet;
UnionFind uf(10001);
int A,B;
for(int i=0;i<N;++i){
cin >> R >> C >> RR >> CC;
--R;--C;--RR;--CC;
//[0,99]100個
A = R+C*100;
B = RR+CC*100;
G[ A ].push_back(B);
G[ B ].push_back(A);
nodeSet.insert(A);
nodeSet.insert(B);
}
set<int>::iterator setPos,setEnd;
setPos = nodeSet.begin();
setEnd = nodeSet.end();
vector<int>::iterator itr,end;
int nodeNo;
queue<int> queNodeNo;
int closeCount;
for(;setPos != setEnd;++setPos){
nodeNo = *setPos;
if( used[nodeNo] ) continue;
closeCount = 0;//1許容、2ダメ
queNodeNo.push(nodeNo);
while( !queNodeNo.empty() ){
nodeNo = queNodeNo.front();queNodeNo.pop();
used[nodeNo] = true;
itr = G[nodeNo].begin();
end = G[nodeNo].end();
A = nodeNo;
for(;itr != end;++itr){
B = *itr;
if( used[B] == true ) continue;
if( uf.same(A,B) ){
++closeCount;
if( closeCount >= 2 ){
cout << "NO" << endl;
return;
}
}
uf.add(A,B);
queNodeNo.push(B);
}
}
}
cout << "YES" << endl;
}
signed main(void){
std::cin.tie(0);
std::ios::sync_with_stdio(false);
//std::cout << std::fixed;//小数を10進数表示
//cout << setprecision(16);//小数をいっぱい表示する。16?
solve();
}
IL_msta