Submission #1604769
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const int MAX_N = 110;
vi es[MAX_N];
vector<int> h;
int dfs(int cur, int par) {
int ret = 0;
for(auto& to : es[cur]) {
if(to == par) continue;
ret += dfs(to, cur);
}
if(par == -1) return ret;
if(ret != 0 || h[cur] == 1) ret += 2;
return ret;
}
int main(){
#ifdef LOCAL_TEST
freopen("in", "r", stdin);
freopen("out", "w", stdout);
#endif
int n, x;
cin >> n >> x;
x--;
h.resize(n);
rep(i, n) cin >> h[i];
rep(i, n-1) {
int a, b;
cin >> a >> b;
a--; b--;
es[a].pb(b);
es[b].pb(a);
}
cout << dfs(x, -1) << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
B - ツリーグラフ |
User |
T1610 |
Language |
C++14 (GCC 5.4.1) |
Score |
100 |
Code Size |
1257 Byte |
Status |
AC |
Exec Time |
1 ms |
Memory |
256 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
100 / 100 |
Status |
|
|
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 |
1 ms |
256 KB |
subtask0_sample_02.txt |
AC |
1 ms |
256 KB |
subtask1_line01.txt |
AC |
1 ms |
256 KB |
subtask1_line02.txt |
AC |
1 ms |
256 KB |
subtask1_line03.txt |
AC |
1 ms |
256 KB |
subtask1_line04.txt |
AC |
1 ms |
256 KB |
subtask1_line05.txt |
AC |
1 ms |
256 KB |
subtask1_line06.txt |
AC |
1 ms |
256 KB |
subtask1_random01.txt |
AC |
1 ms |
256 KB |
subtask1_random02.txt |
AC |
1 ms |
256 KB |
subtask1_random03.txt |
AC |
1 ms |
256 KB |
subtask1_random04.txt |
AC |
1 ms |
256 KB |
subtask1_random05.txt |
AC |
1 ms |
256 KB |
subtask1_random06.txt |
AC |
1 ms |
256 KB |
subtask1_random07.txt |
AC |
1 ms |
256 KB |
subtask1_random08.txt |
AC |
1 ms |
256 KB |
subtask1_special01.txt |
AC |
1 ms |
256 KB |
subtask1_special02.txt |
AC |
1 ms |
256 KB |
subtask1_special03.txt |
AC |
1 ms |
256 KB |
subtask1_special04.txt |
AC |
1 ms |
256 KB |