結果

問題 No.483 マッチ並べ
ユーザー kurenai3110
提出日時 2017-02-10 23:50:57
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,166 bytes
コンパイル時間 1,262 ms
コンパイル使用メモリ 77,584 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-29 11:22:55
合計ジャッジ時間 2,469 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <stack>
using namespace std;
bool A[10001];

int main()
{
	int n; cin >> n;
	vector<vector<int>>X(10001);
	X.reserve(n);
	vector<int>rc;
	for (int i = 0; i < n; i++) {
		int r0, r1, c0, c1;
		cin >> r0 >> c0 >> r1 >> c1;
		rc.push_back(r0 * 100 + c0);rc.push_back(r1 * 100 + c1);
		X[r0 * 100 + c0].push_back(r1 * 100 + c1);
		X[r1 * 100 + c1].push_back(r0 * 100 + c0);
	}

	stack<pair<int,int>>st;

	int cnt = 0;
	for (int j = 0; j < 2*n; j++) {
		if (A[rc[j]])continue;
		st.push(make_pair(rc[j],0));
		vector<int>B(10001);
		for (int i = 0; i < 10001; i++)B[i] = 1000;
		B[rc[j]] = 0;
		while (!st.empty() && cnt < 2) {
			pair<int,int> p = st.top(); st.pop();
			if (A[p.first])continue;
			A[p.first] = true;
			for (int i = 0; i < X[p.first].size(); i++) {
				if (B[X[p.first][i]] == p.second - 1)continue;
				if (!A[X[p.first][i]]) {
					B[X[p.first][i]] = p.second + 1;
					st.push(make_pair(X[p.first][i], B[X[p.first][i]]));
				}
				else{
					cnt++;
				}

			}
		}
	}

	if (cnt<2)cout << "YES" << endl;
	else cout << "NO" << endl;

    return 0;
}
0