Submission #23735814


Source Code Expand

#include<bits/stdc++.h>
using namespace std;

using ll = long long;
const int mod = 1e9+7;

vector<vector<int>> edge;
vector<vector<vector<vector<int>>>> dp;

void dfs(int now){
	dp[now].resize(2,vector<vector<int>>(2,vector<int>(2)));
	dp[now][0][0][0] = dp[now][1][1][1] = 1;
	for(auto next: edge[now]){
		if(!dp[next].empty()) continue;
		dfs(next);
		int N = dp[now].size()-1, M = dp[next].size()-1;
		vector<vector<vector<int>>> nex(N+M+1,vector<vector<int>>(2,vector<int>(2)));
		for(int i=0; i<=N; i++){
			for(int j=0; j<=M; j++){
				for(int k=0; k<2; k++){
					for(int l=0; l<2; l++){
						for(int m=0; m<2; m++){
							for(int n=0; n<2; n++){
								if(dp[now][i][k][l]==0 || dp[next][j][m][n]==0) continue;
								int sum = i+j+(!l&m)+(k&!n);
								nex[sum][k][l|m] += ll(dp[now][i][k][l])*dp[next][j][m][n]%mod;
								nex[sum][k][l|m] %= mod;
							}
						}
					}
				}
			}
		}
		dp[now] = nex;
	}
}

int main(){
	int N; cin >> N;
	edge.resize(N);
	dp.resize(N);
	for(int i=1; i<N; i++){
		int U,V; cin >> U >> V;
		edge[--U].push_back(--V);
		edge[V].push_back(U);
	}
	dfs(0);
	for(int i=0; i<=N; i++){
		int ans = 0;
		for(int j=0; j<2; j++){
			for(int k=0; k<2; k++){
				ans += dp[0][i][j][k];
				ans %= mod;
			}
		}
		cout << ans << endl;
	}
}

Submission Info

Submission Time
Task F - Tree Patrolling
User penguinman
Language C++ (GCC 9.2.1)
Score 600
Code Size 1334 Byte
Status AC
Exec Time 802 ms
Memory 301772 KiB

Compile Error

./Main.cpp: In function ‘void dfs(int)’:
./Main.cpp:25:24: warning: suggest parentheses around operand of ‘!’ or change ‘&’ to ‘&&’ or ‘!’ to ‘~’ [-Wparentheses]
   25 |         int sum = i+j+(!l&m)+(k&!n);
      |                        ^~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 30
Set Name Test Cases
Sample example0.txt, example1.txt, example2.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, example0.txt, example1.txt, example2.txt
Case Name Status Exec Time Memory
000.txt AC 6 ms 3592 KiB
001.txt AC 99 ms 10204 KiB
002.txt AC 33 ms 6780 KiB
003.txt AC 71 ms 9188 KiB
004.txt AC 36 ms 7420 KiB
005.txt AC 72 ms 8024 KiB
006.txt AC 14 ms 4364 KiB
007.txt AC 16 ms 4844 KiB
008.txt AC 143 ms 13336 KiB
009.txt AC 34 ms 6020 KiB
010.txt AC 80 ms 9564 KiB
011.txt AC 62 ms 7584 KiB
012.txt AC 619 ms 5280 KiB
013.txt AC 609 ms 5144 KiB
014.txt AC 614 ms 5224 KiB
015.txt AC 63 ms 4164 KiB
016.txt AC 28 ms 3940 KiB
017.txt AC 802 ms 301772 KiB
018.txt AC 466 ms 154308 KiB
019.txt AC 460 ms 153128 KiB
020.txt AC 145 ms 56688 KiB
021.txt AC 216 ms 80448 KiB
022.txt AC 449 ms 79628 KiB
023.txt AC 546 ms 138288 KiB
024.txt AC 640 ms 79428 KiB
025.txt AC 230 ms 34376 KiB
026.txt AC 2 ms 3692 KiB
example0.txt AC 2 ms 3612 KiB
example1.txt AC 2 ms 3456 KiB
example2.txt AC 2 ms 3552 KiB