Submission #1689741


Source Code Expand

#include<bits/stdc++.h>
#define N 100005
using namespace std;
struct edge{
	int t,next;
}e[N*2];int ecnt,head[N];
void addedge(int f,int t){
	e[++ecnt]=(edge){t,head[f]};head[f]=ecnt;
	e[++ecnt]=(edge){f,head[t]};head[t]=ecnt;
}
int n,k,val[N];
priority_queue<pair<int,int> > pq;//ʵ¼ÊÉÏʹÓöÓÁо͹»ÁË 
int main(){
	scanf("%d",&n);
	for(int i=1,f,t;i<n;i++)
		scanf("%d%d",&f,&t),addedge(f,t);
	scanf("%d",&k);
	for(int i=1,v,p;i<=k;i++){
		scanf("%d%d",&v,&p);
		val[v]=p;
		pq.push(make_pair(p,v));
	}
	bool flag=true;
	while(!pq.empty()){
		int u=pq.top().second;pq.pop();
		for(int i=head[u];i;i=e[i].next){
			if(val[e[i].t]==0){
				val[e[i].t]=val[u]-1;
				pq.push(make_pair(val[u]-1,e[i].t));
			}else if(abs(val[e[i].t]-val[u])!=1) flag=false;
		}
	}
	if(!flag) puts("No");
	else{
		puts("Yes");
		for(int i=1;i<=n;i++) printf("%d\n",val[i]);
	}
	return 0;
} 

Submission Info

Submission Time
Task E - Integers on a Tree
User Wuvin
Language C++14 (GCC 5.4.1)
Score 0
Code Size 927 Byte
Status WA
Exec Time 67 ms
Memory 4212 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:14:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
./Main.cpp:16:35: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&f,&t),addedge(f,t);
                                   ^
./Main.cpp:17:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&k);
                ^
./Main.cpp:19:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&v,&p);
                      ^

Judge Result

Set Name sample All
Score / Max Score 0 / 0 0 / 800
Status
AC × 2
WA × 1
AC × 37
WA × 2
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 AC 49 ms 3704 KB
binary_02.txt AC 27 ms 2688 KB
hand_01.txt AC 1 ms 256 KB
hand_02.txt AC 1 ms 256 KB
hand_03.txt WA 1 ms 256 KB
kary_01.txt AC 29 ms 2940 KB
kary_02.txt AC 38 ms 3580 KB
kary_03.txt AC 30 ms 3196 KB
line_01.txt AC 33 ms 2944 KB
line_02.txt AC 30 ms 3200 KB
line_03.txt AC 30 ms 3200 KB
line_04.txt AC 46 ms 3580 KB
line_05.txt AC 22 ms 2560 KB
line_06.txt AC 38 ms 2944 KB
random0_01.txt AC 45 ms 3068 KB
random1_01.txt AC 42 ms 3328 KB
random1_02.txt AC 44 ms 3328 KB
random1_03.txt AC 47 ms 3456 KB
random1_04.txt AC 57 ms 3832 KB
random1_05.txt AC 41 ms 3328 KB
random1_06.txt AC 41 ms 3328 KB
random1_07.txt AC 44 ms 3328 KB
random1_08.txt AC 67 ms 4212 KB
random2_01.txt AC 33 ms 2688 KB
random2_02.txt AC 32 ms 2560 KB
random2_03.txt AC 34 ms 2688 KB
random2_04.txt AC 37 ms 2688 KB
random2_05.txt AC 47 ms 3068 KB
random2_06.txt AC 56 ms 3576 KB
random3_01.txt AC 33 ms 2688 KB
random3_02.txt AC 48 ms 3068 KB
random4_01.txt AC 41 ms 3328 KB
random4_02.txt AC 41 ms 3328 KB
random4_03.txt AC 42 ms 3328 KB
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt WA 1 ms 256 KB
star_01.txt AC 48 ms 3956 KB
star_02.txt AC 40 ms 3704 KB