Submission #1295125
Source Code Expand
import sys sys.setrecursionlimit(10**8) def dfs(now,par): for to in g[now]: if to==par:continue ans[now]+=dfs(to,now) if h[now]==1:return ans[now]+1 else: if ans[now]==0: return 0 else: return ans[now]+1 n,x=map(int,raw_input().split()) h=map(int,raw_input().split()) g=[[] for _ in xrange(n)] for i in xrange(n-1): a,b=map(int,raw_input().split()) a-=1;b-=1 g[a].append(b) g[b].append(a) ans=[0]*n print (max(dfs(x-1,-1)-1,0))*2
Submission Info
Submission Time | |
---|---|
Task | B - ツリーグラフ |
User | roto_37 |
Language | Python (2.7.6) |
Score | 100 |
Code Size | 536 Byte |
Status | AC |
Exec Time | 11 ms |
Memory | 2696 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 | 10 ms | 2692 KB |
subtask0_sample_02.txt | AC | 11 ms | 2692 KB |
subtask1_line01.txt | AC | 11 ms | 2692 KB |
subtask1_line02.txt | AC | 11 ms | 2692 KB |
subtask1_line03.txt | AC | 11 ms | 2696 KB |
subtask1_line04.txt | AC | 11 ms | 2692 KB |
subtask1_line05.txt | AC | 11 ms | 2692 KB |
subtask1_line06.txt | AC | 11 ms | 2692 KB |
subtask1_random01.txt | AC | 11 ms | 2692 KB |
subtask1_random02.txt | AC | 11 ms | 2692 KB |
subtask1_random03.txt | AC | 11 ms | 2692 KB |
subtask1_random04.txt | AC | 11 ms | 2692 KB |
subtask1_random05.txt | AC | 11 ms | 2692 KB |
subtask1_random06.txt | AC | 11 ms | 2692 KB |
subtask1_random07.txt | AC | 11 ms | 2696 KB |
subtask1_random08.txt | AC | 11 ms | 2692 KB |
subtask1_special01.txt | AC | 10 ms | 2692 KB |
subtask1_special02.txt | AC | 11 ms | 2692 KB |
subtask1_special03.txt | AC | 11 ms | 2692 KB |
subtask1_special04.txt | AC | 11 ms | 2692 KB |