結果

問題 No.483 マッチ並べ
ユーザー kotamanegi
提出日時 2017-02-10 23:03:35
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,776 bytes
コンパイル時間 869 ms
コンパイル使用メモリ 95,820 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-29 08:20:14
合計ジャッジ時間 2,271 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24 WA * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define LONG_INF 800000000000000000
vector<int> vertexs[200];
map<pair<int, int>, vector<int>> hogee;
int already_visited[200] = {};
int search(int now, int back) {
	int way_of_count = 0;
	already_visited[now] = true;
	for (int i = 0;i < vertexs[now].size();++i) {
		if (vertexs[now][i] != back) {
			if (already_visited[vertexs[now][i]] == true) {
				way_of_count += 1;
				if (way_of_count >= 2) return -1;
			}
			else {
				int hogehoge = search(vertexs[now][i], now);
				if (hogehoge == -1) return -1;
				way_of_count += hogehoge;
				if (way_of_count >= 2) return -1;
			}
		}
	}
	return way_of_count;
}
int main() {
	int n;
	cin >> n;
	for (int j = 0;j < n;++j) {
		int a[2], b[2];
		REP(i, 2) {
			cin >> a[i] >> b[i];
		}
		for (int i = 0;i < 2;++i) {
			for (int q = 0;q < hogee[make_pair(a[i], b[i])].size();++q) {
				vertexs[j].push_back(hogee[make_pair(a[i], b[i])][q]);
				vertexs[hogee[make_pair(a[i], b[i])][q]].push_back(j);
			}
			hogee[make_pair(a[i], b[i])].push_back(j);
		}
	}
	//閉路が連結グラフ上に2つ以上あったら負け
	for (int i = 0;i < n;++i) {
		if (already_visited[i] == 0) {
			int nya = search(i, -1);
			if (nya == -1) {
				cout << "NO" << endl;
				return 0;
			}
		}
	}
	cout << "YES" << endl;
	return 0;
}
0