Submission #1773089
Source Code Expand
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
int n;
queue<pii> q;
multiset<int> adj[233333];
map<pii,int> edg;
template<class T>
void ers(T&x,int g) {x.erase(x.find(g));}
int main()
{
scanf("%d",&n);
for(int i=1,a,b;i<=(n-1)*2;++i)
scanf("%d%d",&a,&b),adj[a].insert(b),
adj[b].insert(a),++edg[pii(min(a,b),max(a,b))];
for(auto e:edg) if(e.se>=2) q.push(e.fi);
int cnt=0;
while(!q.empty())
{
pii x=q.front(); q.pop();
if(edg[x]<2) continue;
int a=x.fi,b=x.se;
if(adj[a].size()<adj[b].size()) swap(a,b);
edg[x]-=2; ++cnt;
while(adj[a].find(b)!=adj[a].end())
ers(adj[a],b);
for(auto s:adj[b])
{
if(s==a) continue;
int&pp=edg[pii(min(s,a),max(s,a))];
++pp,--edg[pii(min(s,b),max(s,b))],
ers(adj[s],b),adj[s].insert(a),adj[a].insert(s);
if(pp>=2) q.push(pii(min(s,a),max(s,a)));
}
adj[b].clear();
}
if(cnt+1==n) puts("YES"); else puts("NO");
}
Submission Info
Submission Time
2017-11-14 21:49:44+0900
Task
E - Blue and Red Tree
User
fjzzq2002
Language
C++14 (GCC 5.4.1)
Score
1400
Code Size
1917 Byte
Status
AC
Exec Time
853 ms
Memory
46208 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:40:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
./Main.cpp:43:49: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
adj[b].insert(a),++edg[pii(min(a,b),max(a,b))];
^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
1400 / 1400
Status
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
6 ms
11136 KB
in10.txt
AC
284 ms
42368 KB
in11.txt
AC
605 ms
41216 KB
in12.txt
AC
622 ms
40832 KB
in13.txt
AC
620 ms
41216 KB
in14.txt
AC
618 ms
41344 KB
in15.txt
AC
622 ms
41216 KB
in16.txt
AC
621 ms
40960 KB
in17.txt
AC
611 ms
41216 KB
in18.txt
AC
622 ms
41216 KB
in19.txt
AC
633 ms
41216 KB
in2.txt
AC
6 ms
11136 KB
in20.txt
AC
676 ms
41344 KB
in21.txt
AC
724 ms
41344 KB
in22.txt
AC
617 ms
41472 KB
in23.txt
AC
615 ms
41600 KB
in24.txt
AC
622 ms
41344 KB
in25.txt
AC
642 ms
41600 KB
in26.txt
AC
625 ms
41344 KB
in27.txt
AC
624 ms
41088 KB
in28.txt
AC
621 ms
41600 KB
in29.txt
AC
635 ms
41216 KB
in3.txt
AC
6 ms
11136 KB
in30.txt
AC
619 ms
41216 KB
in31.txt
AC
853 ms
44800 KB
in32.txt
AC
728 ms
44800 KB
in33.txt
AC
792 ms
44672 KB
in34.txt
AC
726 ms
44928 KB
in35.txt
AC
738 ms
44928 KB
in36.txt
AC
762 ms
44928 KB
in37.txt
AC
772 ms
45056 KB
in38.txt
AC
737 ms
44672 KB
in39.txt
AC
701 ms
44544 KB
in4.txt
AC
277 ms
42496 KB
in40.txt
AC
710 ms
44544 KB
in41.txt
AC
801 ms
44672 KB
in42.txt
AC
717 ms
46208 KB
in43.txt
AC
762 ms
44800 KB
in44.txt
AC
751 ms
44800 KB
in45.txt
AC
781 ms
45056 KB
in46.txt
AC
744 ms
44544 KB
in47.txt
AC
661 ms
44544 KB
in5.txt
AC
291 ms
42496 KB
in6.txt
AC
654 ms
44544 KB
in7.txt
AC
281 ms
42496 KB
in8.txt
AC
278 ms
42496 KB
in9.txt
AC
290 ms
42496 KB
sample1.txt
AC
6 ms
11136 KB
sample2.txt
AC
5 ms
11136 KB
sample3.txt
AC
6 ms
11136 KB