Submission #1709314
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;
int n, x;
int h[110];
int a[110], b[110];
vector<int> G[110];
bool used[110];
bool dfs(int u, int p) {
// printf("%d %d\n", u, p);
bool flag = false;
for(auto v : G[u]) {
if(p == v) continue;
flag |= dfs(v, u);
}
return used[u] = flag | h[u];
}
int ans = 0;
void dfs2(int u, int p) {
for(auto v : G[u]) {
if(p == v) continue;
if(!used[v]) continue;
ans += 2;
dfs2(v, u);
}
}
int main(void) {
cin >> n >> x;
rep(i, n) cin >> h[i];
rep(i, n - 1) cin >> a[i] >> b[i];
rep(i, n - 1) a[i]--, b[i]--;
rep(i, n - 1) G[a[i]].pb(b[i]), G[b[i]].pb(a[i]);
x--;
dfs(x, -1);
dfs2(x, -1);
printf("%d\n", ans);
return 0;
}
Submission Info
Submission Time |
|
Task |
B - ツリーグラフ |
User |
mmxsrup |
Language |
C++14 (GCC 5.4.1) |
Score |
100 |
Code Size |
1377 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 |