Submission #2550915


Source Code Expand

#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
const int inf=1e9;
int n,k,d[100010],v[100010],l[100010],r[100010];
bool used[100010];
int cnt,head[100010],to[200010],nxt[200010];
void add(int x,int y)
{
	cnt++;
	to[cnt]=y;
	nxt[cnt]=head[x];
	head[x]=cnt;
}
void dfs(int x,int fa)
{
	for (int i=head[x];i;i=nxt[i])
	{
		int y=to[i];
		if (y==fa)
		{
			continue;
		}
		dfs(y,x);
		d[y]=d[x]+1;
	}
}
void dfs2(int x,int fa)
{
	if (used[x])
	{
		l[x]=v[x];
		r[x]=v[x];
	}
	else
	{
		l[x]=-inf;
		r[x]=inf;
	}
	for (int i=head[x];i;i=nxt[i])
	{
		int y=to[i];
		if (y==fa)
		{
			continue;
		}
		dfs2(y,x);
		l[x]=max(l[x],l[y]-1);
		r[x]=min(r[x],r[y]+1);
	}
	if (l[x]>r[x])
	{
		puts("No");
		exit(0);
	}
}
void work(int x,int fa)
{
	if (!used[x])
	{
		if (v[fa]+1>=l[x] && v[fa]+1<=r[x])
		{
			v[x]=v[fa]+1;
		}
		else
		{
			v[x]=v[fa]-1;
		}
	}
	for (int i=head[x];i;i=nxt[i])
	{
		int y=to[i];
		if (y==fa)
		{
			continue;
		}
		work(y,x);
	}
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y);
		add(y,x);
	}
	d[1]=1;
	dfs(1,0);
	scanf("%d",&k);
	int tmp;
	for (int i=0;i<k;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		used[x]=true;
		v[x]=y;
		if (!i)
		{
			tmp=x;
			continue;
		}
		if (((v[x]-v[tmp])&1)!=((d[x]-d[tmp])&1))
		{
			puts("No");
			return 0;
		}
	}
	dfs2(1,0);
	if (!used[1])
	{
		v[1]=l[1];
		used[1]=true;
	}
	work(1,0);
	puts("Yes");
	for (int i=1;i<=n;i++)
	{
		printf("%d\n",v[i]);
	}
    return 0;
}
//白雪淡淡长安,梅香阵阵静庭。

Submission Info

Submission Time
Task E - Integers on a Tree
User Emma194
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2642 Byte
Status WA
Exec Time 41 ms
Memory 7296 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:135:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
./Main.cpp:139:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&x,&y);
                      ^
./Main.cpp:145:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&k);
                ^
./Main.cpp:150:22: 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 / 800
Status
AC × 3
AC × 26
WA × 13
Set Name Test Cases
sample sample_01.txt, sample_02.txt, sample_03.txt
All binary_01.txt, binary_02.txt, hand_01.txt, hand_02.txt, hand_03.txt, kary_01.txt, kary_02.txt, kary_03.txt, line_01.txt, line_02.txt, line_03.txt, line_04.txt, line_05.txt, line_06.txt, random0_01.txt, random1_01.txt, random1_02.txt, random1_03.txt, random1_04.txt, random1_05.txt, random1_06.txt, random1_07.txt, random1_08.txt, random2_01.txt, random2_02.txt, random2_03.txt, random2_04.txt, random2_05.txt, random2_06.txt, random3_01.txt, random3_02.txt, random4_01.txt, random4_02.txt, random4_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, star_01.txt, star_02.txt
Case Name Status Exec Time Memory
binary_01.txt WA 22 ms 4992 KB
binary_02.txt AC 22 ms 4992 KB
hand_01.txt AC 1 ms 256 KB
hand_02.txt AC 1 ms 256 KB
hand_03.txt AC 1 ms 256 KB
kary_01.txt AC 20 ms 2560 KB
kary_02.txt WA 19 ms 2560 KB
kary_03.txt AC 20 ms 2560 KB
line_01.txt AC 23 ms 7296 KB
line_02.txt WA 23 ms 7296 KB
line_03.txt WA 23 ms 7296 KB
line_04.txt WA 23 ms 7296 KB
line_05.txt AC 23 ms 7296 KB
line_06.txt AC 23 ms 7296 KB
random0_01.txt AC 23 ms 2560 KB
random1_01.txt WA 22 ms 2560 KB
random1_02.txt WA 22 ms 2560 KB
random1_03.txt WA 23 ms 2560 KB
random1_04.txt WA 23 ms 2560 KB
random1_05.txt WA 23 ms 2560 KB
random1_06.txt WA 24 ms 2560 KB
random1_07.txt WA 23 ms 2560 KB
random1_08.txt WA 23 ms 2560 KB
random2_01.txt AC 23 ms 2560 KB
random2_02.txt AC 23 ms 2560 KB
random2_03.txt AC 23 ms 2560 KB
random2_04.txt AC 23 ms 2560 KB
random2_05.txt AC 23 ms 2560 KB
random2_06.txt AC 23 ms 2560 KB
random3_01.txt AC 23 ms 2560 KB
random3_02.txt AC 23 ms 2560 KB
random4_01.txt AC 41 ms 4480 KB
random4_02.txt AC 41 ms 4480 KB
random4_03.txt AC 41 ms 4608 KB
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB
star_01.txt AC 37 ms 4480 KB
star_02.txt AC 28 ms 3840 KB