Submission #286824
Source Code Expand
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#define M_PI 3.14159265358979323846
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
//container util
//------------------------------------------
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
VVI g;
int a[111];
int v[111];
int DFS1(int node){
int ret = 0;
v[node]=1;
REP(i, g[node].size()){
if(v[g[node][i]])continue;
ret += DFS1(g[node][i]);
}
if(ret == 0){
if(a[node])return 2;
else return 0;
}
else return ret+2;
}
int main(){
int n,x;
cin >> n>>x;
x--;
REP(i,n)scanf("%d", a+i);
g = VVI(n);
REP(i,n-1){
int s,t;
scanf("%d%d", &s, &t);
s--, t--;
g[s].PB(t);
g[t].PB(s);
}
cout <<max(DFS1(x)-2, 0)<<endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
B - ツリーグラフ |
User |
UminchuR |
Language |
C++11 (GCC 4.8.1) |
Score |
100 |
Code Size |
2233 Byte |
Status |
AC |
Exec Time |
205 ms |
Memory |
932 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:92:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
REP(i,n)scanf("%d", a+i);
^
./Main.cpp:96:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &s, &t);
^
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 |
23 ms |
924 KB |
subtask0_sample_02.txt |
AC |
22 ms |
800 KB |
subtask1_line01.txt |
AC |
22 ms |
800 KB |
subtask1_line02.txt |
AC |
24 ms |
796 KB |
subtask1_line03.txt |
AC |
23 ms |
796 KB |
subtask1_line04.txt |
AC |
21 ms |
788 KB |
subtask1_line05.txt |
AC |
205 ms |
688 KB |
subtask1_line06.txt |
AC |
25 ms |
804 KB |
subtask1_random01.txt |
AC |
23 ms |
924 KB |
subtask1_random02.txt |
AC |
23 ms |
924 KB |
subtask1_random03.txt |
AC |
22 ms |
748 KB |
subtask1_random04.txt |
AC |
21 ms |
932 KB |
subtask1_random05.txt |
AC |
20 ms |
924 KB |
subtask1_random06.txt |
AC |
22 ms |
920 KB |
subtask1_random07.txt |
AC |
23 ms |
784 KB |
subtask1_random08.txt |
AC |
22 ms |
796 KB |
subtask1_special01.txt |
AC |
21 ms |
792 KB |
subtask1_special02.txt |
AC |
20 ms |
924 KB |
subtask1_special03.txt |
AC |
22 ms |
916 KB |
subtask1_special04.txt |
AC |
21 ms |
804 KB |