Submission #2162263


Source Code Expand

#include <bits/stdc++.h>

#define FOR(i,a,b) for(i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;
typedef pair<int,bool> P;

const int MAX_N=1e5;

set<P> G[MAX_N];

int main(){
	int N;
	int i;
	scanf("%d",&N);
	REP(i,N-1){
		int a,b;
		scanf("%d %d",&a,&b);
		a--;
		b--;
		G[a].insert(P(b,false));
		G[b].insert(P(a,false));
	}
	REP(i,N-1){
		int a,b;
		scanf("%d %d",&a,&b);
		a--;
		b--;
		G[a].insert(P(b,true));
		G[b].insert(P(a,true));
	}
	int c=0;
	REP(i,N){
		int v=i,v2;
		while(1){
			v2=-1;
			for(auto ite=G[v].begin();ite!=G[v].end();){
				auto ite2=ite;
				ite2++;
				if (ite2==G[v].end()) break;
				if (ite->first==ite2->first){
					v2=ite->first;
					if (G[v].size()<G[v2].size()){
						swap(v,v2);
					}
					break;
				}
				ite++;
				if (ite->second){
					ite++;
				}
			}
			if (v2!=-1){
				c++;
				G[v].erase(P(v2,false));
				G[v].erase(P(v2,true));
				G[v2].erase(P(v,false));
				G[v2].erase(P(v,true));
				for(auto ite2=G[v2].begin();ite2!=G[v2].end();){
					G[ite2->first].erase(P(v2,ite2->second));
					G[ite2->first].insert(P(v,ite2->second));
					G[v].insert(*ite2);
					ite2=G[v2].erase(ite2);
				}
			}else{
				break;
			}
		}
	}
	if (c==N-1){
		printf("YES\n");
	}else{
		printf("NO\n");
	}
	return 0;
}

Submission Info

Submission Time
Task E - Blue and Red Tree
User addeight
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1353 Byte
Status TLE
Exec Time 6305 ms
Memory 25728 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:16:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&N);
                ^
./Main.cpp:19:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&a,&b);
                       ^
./Main.cpp:27:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&a,&b);
                       ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1400
Status
AC × 3
AC × 35
TLE × 18
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 4864 KB
in10.txt AC 156 ms 23680 KB
in11.txt AC 1119 ms 23680 KB
in12.txt AC 516 ms 23680 KB
in13.txt AC 896 ms 23680 KB
in14.txt AC 916 ms 23680 KB
in15.txt AC 846 ms 23680 KB
in16.txt AC 767 ms 23680 KB
in17.txt AC 970 ms 23680 KB
in18.txt AC 664 ms 23680 KB
in19.txt AC 1057 ms 23680 KB
in2.txt AC 3 ms 4992 KB
in20.txt AC 895 ms 23680 KB
in21.txt AC 963 ms 23680 KB
in22.txt AC 766 ms 23680 KB
in23.txt AC 1118 ms 23680 KB
in24.txt AC 1107 ms 23680 KB
in25.txt AC 942 ms 23680 KB
in26.txt AC 695 ms 23680 KB
in27.txt AC 965 ms 23680 KB
in28.txt AC 602 ms 23680 KB
in29.txt AC 926 ms 23680 KB
in3.txt AC 3 ms 4992 KB
in30.txt AC 1093 ms 23680 KB
in31.txt TLE 6304 ms 23680 KB
in32.txt TLE 6304 ms 23680 KB
in33.txt TLE 6304 ms 23680 KB
in34.txt TLE 6305 ms 23680 KB
in35.txt TLE 6304 ms 23680 KB
in36.txt TLE 6304 ms 25728 KB
in37.txt TLE 6304 ms 25728 KB
in38.txt TLE 6304 ms 25728 KB
in39.txt TLE 6304 ms 25728 KB
in4.txt AC 182 ms 23680 KB
in40.txt TLE 6304 ms 25728 KB
in41.txt TLE 6304 ms 25728 KB
in42.txt TLE 6304 ms 23680 KB
in43.txt TLE 6304 ms 25728 KB
in44.txt TLE 6304 ms 25728 KB
in45.txt TLE 6304 ms 25728 KB
in46.txt TLE 6304 ms 25728 KB
in47.txt TLE 6304 ms 25728 KB
in5.txt AC 157 ms 23680 KB
in6.txt TLE 6304 ms 25728 KB
in7.txt AC 177 ms 23680 KB
in8.txt AC 189 ms 23680 KB
in9.txt AC 170 ms 23680 KB
sample1.txt AC 3 ms 4864 KB
sample2.txt AC 3 ms 4864 KB
sample3.txt AC 3 ms 4992 KB