Submission #1258902
Source Code Expand
/* #pragma region GNUC //https://yukicoder.me/wiki/auto_vectorization #ifdef __GNUC__ #pragma GCC optimize ("O3") #pragma GCC target ("avx") #endif #pragma endregion */ #define _USE_MATH_DEFINES #pragma region include #include <iostream> #include <iomanip> #include <stdio.h> #include <sstream> #include <algorithm> #include <cmath> #include <string> #include <cstring> #include <vector> #include <tuple> #include <queue> #include <complex> #include <set> #include <map> #include <stack> #include <list> #include <fstream> #include <random> //#include <time.h> #include <ctime> #pragma endregion //#include ///////// #define REP(i, x, n) for(int i = x; i < n; ++i) #define rep(i,n) REP(i,0,n) ///////// #pragma region typedef typedef long long LL; typedef long double LD; typedef unsigned long long ULL; #pragma endregion //typedef ////定数 const int INF = (int)1e9; const LL MOD = (LL)1e9+7; const LL LINF = (LL)1e18; const double PI = acos(-1.0); const double EPS = 1e-9; ///////// using namespace::std; vector<int> dist(100,-1); vector<bool> visit(100,false); vector<int> H(100); vector< vector<int> > Gra(100); int dfs(int v,int D){ int ans = 0; visit[v] = true; bool flag = false; if( H[v] == 1 ){ flag = true;//往復分,スタート地点は消しておく } int size = Gra[v].size(); int res = 0; for(int i=0;i<size;++i){ int to = Gra[v][i]; if( visit[to] ) continue; res = dfs(to,D+1); if(res){ flag = true; } ans += res; } if( flag ){ ans += 2; } return ans; } void solve(){ int N,start; cin >> N >> start; --start; for(int i=0;i<N;++i){ cin >> H[i]; } H[start] = 0; for(int i=0;i<N-1;++i){ int a,b; cin >> a >> b; --a;--b; Gra[a].push_back(b); Gra[b].push_back(a); } int ans = dfs(start,0); if( ans > 0 ){ ans -=2; } cout << ans << endl; } #pragma region main signed main(void){ std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed;//小数を10進数表示 cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別 solve(); } #pragma endregion //main()
Submission Info
Submission Time | |
---|---|
Task | B - ツリーグラフ |
User | akarin55 |
Language | C++14 (GCC 5.4.1) |
Score | 100 |
Code Size | 2206 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 |