Submission #286549


Source Code Expand

Copy
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<int> ed[114];
int out=0;
int h[114];
int dfs(int v,int u){
	int ret=h[v];
	rep(i,ed[v].size()){
		int w=ed[v][i];
		if(u==w) continue;
		if(dfs(w,v)>0){ret=1;out+=2;}
	}
	return ret;
}
int main()
{
	int n,x,a,b;
	cin>>n>>x;x--;
	rep(i,n) cin>>h[i];
	rep(i,n-1){
		cin>>a>>b;a--;b--;
		ed[a].pb(b);ed[b].pb(a);
	}
	dfs(x,-1);
	cout<<out<<endl;
}

Submission Info

Submission Time
Task B - ツリーグラフ
User sky58
Language C++ (G++ 4.6.4)
Score 100
Code Size 1070 Byte
Status AC
Exec Time 25 ms
Memory 924 KB

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 21 ms 800 KB
subtask0_sample_02.txt AC 21 ms 804 KB
subtask1_line01.txt AC 21 ms 800 KB
subtask1_line02.txt AC 21 ms 784 KB
subtask1_line03.txt AC 21 ms 796 KB
subtask1_line04.txt AC 23 ms 808 KB
subtask1_line05.txt AC 23 ms 672 KB
subtask1_line06.txt AC 23 ms 732 KB
subtask1_random01.txt AC 23 ms 920 KB
subtask1_random02.txt AC 23 ms 800 KB
subtask1_random03.txt AC 22 ms 804 KB
subtask1_random04.txt AC 23 ms 800 KB
subtask1_random05.txt AC 25 ms 796 KB
subtask1_random06.txt AC 23 ms 796 KB
subtask1_random07.txt AC 22 ms 804 KB
subtask1_random08.txt AC 23 ms 740 KB
subtask1_special01.txt AC 21 ms 796 KB
subtask1_special02.txt AC 23 ms 924 KB
subtask1_special03.txt AC 23 ms 676 KB
subtask1_special04.txt AC 24 ms 792 KB