Submission #286697


Source Code Expand

Copy
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define mp1(a,b,c) P1(a,P(b,c))
#define pque(a) priority_queue<a>
#define rpque(a) priority_queue<a,vector<a>,greater<a>>

const int INF=1000000000;
const int dre_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dre_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
const int kaijou[10]={1,1,2,6,24,120,720,5040,40320,362880};

int n,x;
int h[102];
vector<int> G[102];

int dfs(int v,int p){
	int ret = 0;
	rep(i,G[v].size()){
		if(G[v][i] == p)continue;
		ret += dfs(G[v][i],v);
	}
	if(h[v] == 1 || ret > 0)ret += 2;
	return ret;
}

int main(){	
	scanf("%d%d",&n,&x);
	rep1(i,n){
		scanf("%d",&h[i]);
	}
	rep(i,n-1){
		int a,b;
		scanf("%d%d",&a,&b);
		G[a].pb(b);
		G[b].pb(a);
	}
	
	printf("%d\n",max(dfs(x,-1) - 2,0));
}

Submission Info

Submission Time
Task B - ツリーグラフ
User yokozuna57
Language C++11 (GCC 4.8.1)
Score 100
Code Size 1662 Byte
Status AC
Exec Time 24 ms
Memory 928 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:57:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&x);
                     ^
./Main.cpp:59:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&h[i]);
                    ^
./Main.cpp:63:22: 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 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 22 ms 676 KB
subtask0_sample_02.txt AC 22 ms 924 KB
subtask1_line01.txt AC 22 ms 732 KB
subtask1_line02.txt AC 21 ms 860 KB
subtask1_line03.txt AC 21 ms 796 KB
subtask1_line04.txt AC 21 ms 920 KB
subtask1_line05.txt AC 23 ms 736 KB
subtask1_line06.txt AC 23 ms 728 KB
subtask1_random01.txt AC 22 ms 924 KB
subtask1_random02.txt AC 23 ms 800 KB
subtask1_random03.txt AC 21 ms 928 KB
subtask1_random04.txt AC 21 ms 800 KB
subtask1_random05.txt AC 24 ms 772 KB
subtask1_random06.txt AC 22 ms 800 KB
subtask1_random07.txt AC 23 ms 796 KB
subtask1_random08.txt AC 22 ms 676 KB
subtask1_special01.txt AC 22 ms 672 KB
subtask1_special02.txt AC 24 ms 768 KB
subtask1_special03.txt AC 22 ms 804 KB
subtask1_special04.txt AC 22 ms 712 KB