Submission #2230315


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

int n, bel[100005];
set<int> edges[100005];
map<long long, int> cnt;
queue<pair<int, int> > Queue;
/*
template<typename T0, typename T1>
inline pair<T0, T1> get_id(T0 x, T1 y) {
	if (x > y) swap(x, y);
	return make_pair(x, y);
}
*/

long long get_id(int x, int y) {
	if (x > y) swap(x, y);
	return (long long)x * n + y;
}

inline void go_fail() {
	puts("NO");
	exit(0);
}

void link_edges(int x, int y) {
	edges[x].insert(y);
	edges[y].insert(x);
//	pair<int, int> id = get_id(x, y);
	long long id = get_id(x, y);
	++cnt[id];
	if (cnt[id] == 3) go_fail();
	if (cnt[id] == 2) Queue.push(make_pair(x, y));
}

inline int find(const int &x) {
	return bel[x] == x ? x : bel[x] = find(bel[x]);
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i < 2 * n - 1; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		link_edges(x, y);
	}
	for (int i = 1; i <= n; ++i) bel[i] = i;
	for (int i = 1; i < n; ++i) {
		static int x, y;
		for (;;) {
			if (Queue.empty()) go_fail();
			x = Queue.front().first;
			y = Queue.front().second;
			Queue.pop();
			if (x != y) break;
		}
		if (edges[x].size() > edges[y].size()) swap(x, y);
		bel[x] = y;
		cnt.erase(get_id(x, y));
		edges[y].erase(x);
		for (auto v : edges[x]) {
			v = find(v);
			if (v == y) continue;
			cnt.erase(get_id(x, v));
			link_edges(v, y);
			edges[v].erase(x);
			edges[x].erase(v);
		}
	}
	puts("YES");
}

Submission Info

Submission Time
Task E - Blue and Red Tree
User UglyAndPretty
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1474 Byte
Status WA
Exec Time 674 ms
Memory 38656 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:41:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
./Main.cpp:44:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &x, &y);
                        ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1400
Status
AC × 3
AC × 39
WA × 14
Set Name Test Cases
Sample sample1.txt, sample2.txt, sample3.txt
All sample1.txt, sample2.txt, sample3.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in3.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, in36.txt, in37.txt, in38.txt, in39.txt, in4.txt, in40.txt, in41.txt, in42.txt, in43.txt, in44.txt, in45.txt, in46.txt, in47.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt, sample3.txt
Case Name Status Exec Time Memory
in1.txt AC 3 ms 4992 KB
in10.txt AC 279 ms 36608 KB
in11.txt WA 378 ms 30976 KB
in12.txt WA 373 ms 30976 KB
in13.txt WA 370 ms 30976 KB
in14.txt WA 351 ms 30976 KB
in15.txt WA 356 ms 30976 KB
in16.txt WA 386 ms 30976 KB
in17.txt WA 378 ms 30976 KB
in18.txt WA 352 ms 30976 KB
in19.txt WA 316 ms 30976 KB
in2.txt AC 3 ms 4992 KB
in20.txt WA 396 ms 30976 KB
in21.txt AC 351 ms 31360 KB
in22.txt AC 385 ms 31360 KB
in23.txt AC 353 ms 31488 KB
in24.txt AC 319 ms 31488 KB
in25.txt AC 331 ms 31488 KB
in26.txt AC 374 ms 30976 KB
in27.txt WA 352 ms 30976 KB
in28.txt WA 394 ms 30976 KB
in29.txt WA 348 ms 30976 KB
in3.txt AC 3 ms 4992 KB
in30.txt WA 362 ms 30976 KB
in31.txt AC 641 ms 36608 KB
in32.txt AC 641 ms 36608 KB
in33.txt AC 674 ms 36608 KB
in34.txt AC 645 ms 36608 KB
in35.txt AC 626 ms 38656 KB
in36.txt AC 637 ms 36608 KB
in37.txt AC 655 ms 36608 KB
in38.txt AC 624 ms 36608 KB
in39.txt AC 572 ms 36608 KB
in4.txt AC 273 ms 36608 KB
in40.txt AC 614 ms 36608 KB
in41.txt AC 648 ms 36608 KB
in42.txt AC 658 ms 36608 KB
in43.txt AC 273 ms 36608 KB
in44.txt AC 618 ms 38656 KB
in45.txt AC 650 ms 36608 KB
in46.txt AC 584 ms 36608 KB
in47.txt AC 589 ms 36608 KB
in5.txt AC 270 ms 36608 KB
in6.txt AC 616 ms 36608 KB
in7.txt AC 274 ms 36608 KB
in8.txt AC 278 ms 36608 KB
in9.txt AC 270 ms 36608 KB
sample1.txt AC 3 ms 4992 KB
sample2.txt AC 3 ms 4992 KB
sample3.txt AC 3 ms 4992 KB