Submission #287308


Source Code Expand

Copy
#include<stdio.h>

int main(void)
{
	int n,m,i,j,k,x,h[101],p[101][101],flg,flg2,flag[101],a,b;
	
	scanf("%d %d" ,&n ,&x);
	x--;
	for(i=0;i<n;i++){
		scanf("%d " ,&h[i]);
		flag[i]=0;
	}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			p[i][j]=0;
		}
	}
	for(i=0;i<n-1;i++){
		scanf("%d %d" ,&a ,&b);
		a--,b--;
		p[a][b]=1;
		p[b][a]=1;
	}
	while(1){
		flg=0;
		for(i=0;i<n;i++){
			if(i!=x){
			flg2=0;
			for(j=0;j<n;j++){
				if(p[i][j]){
			//		printf("%d %d\n",i,j);
					if(flg2)	break;
					else flg2=1;
				}
			}
			if(flg2==1 && j>=n){
		//		printf("%d\n",i);
				for(j=0;j<n;j++){
					if(p[i][j]){
						p[i][j]=0;
						p[j][i]=0;
						flag[j]+=flag[i];
						if(h[i])	flag[j]+=2;
						else if(flag[i])	flag[j]+=2;
					}
				}
				flg=1;
			}
			}
		}
		if(!flg)	break;
	}
	//for(i=0;i<n;i++)	printf("flaf%d\n" ,flag[i]);
	printf("%d\n",flag[x]);
	return 0;
}

Submission Info

Submission Time
Task B - ツリーグラフ
User haru
Language C++ (G++ 4.6.4)
Score 100
Code Size 928 Byte
Status AC
Exec Time 22 ms
Memory 812 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:7:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:10:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:19:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 2
AC × 20
Set Name Test Cases
Sample subtask0_sample_01.txt, subtask0_sample_02.txt
All subtask0_sample_01.txt, subtask0_sample_02.txt, subtask1_line01.txt, subtask1_line02.txt, subtask1_line03.txt, subtask1_line04.txt, subtask1_line05.txt, subtask1_line06.txt, subtask1_random01.txt, subtask1_random02.txt, subtask1_random03.txt, subtask1_random04.txt, subtask1_random05.txt, subtask1_random06.txt, subtask1_random07.txt, subtask1_random08.txt, subtask1_special01.txt, subtask1_special02.txt, subtask1_special03.txt, subtask1_special04.txt
Case Name Status Exec Time Memory
subtask0_sample_01.txt AC 20 ms 700 KB
subtask0_sample_02.txt AC 21 ms 656 KB
subtask1_line01.txt AC 20 ms 692 KB
subtask1_line02.txt AC 20 ms 796 KB
subtask1_line03.txt AC 20 ms 812 KB
subtask1_line04.txt AC 22 ms 736 KB
subtask1_line05.txt AC 19 ms 796 KB
subtask1_line06.txt AC 21 ms 672 KB
subtask1_random01.txt AC 20 ms 800 KB
subtask1_random02.txt AC 19 ms 796 KB
subtask1_random03.txt AC 21 ms 804 KB
subtask1_random04.txt AC 19 ms 800 KB
subtask1_random05.txt AC 20 ms 668 KB
subtask1_random06.txt AC 21 ms 668 KB
subtask1_random07.txt AC 21 ms 660 KB
subtask1_random08.txt AC 19 ms 732 KB
subtask1_special01.txt AC 20 ms 692 KB
subtask1_special02.txt AC 21 ms 672 KB
subtask1_special03.txt AC 20 ms 668 KB
subtask1_special04.txt AC 21 ms 680 KB