Submission #1294538


Source Code Expand

#include <iostream>
#include <vector>
#define MOD 1000000007
using namespace std;

vector<int> G[100000];
int dp[100000][2];

int dfs(int v,int prev,int pcolor){
	if(dp[v][pcolor] != -1) return dp[v][pcolor];
	int white = 1,black = 1;
	for(int i = 0;i < G[v].size();i++){
		int to = G[v][i];
		if(to == prev) continue;
		white = white * dfs(to,v,0) % MOD;
		if(!pcolor) black = black * dfs(to,v,1) % MOD;
	}
	if(pcolor) black = 0;
	return (white + black) % MOD;
}

int main(){
	int n;
	cin >> n;
	for(int i = 0;i < n;i++){
		dp[i][0] = -1;
		dp[i][1] = -1;
	}
	for(int i = 0;i < n - 1;i++){
		int a,b;
		cin >> a >> b; a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	cout << dfs(0,-1,0) << endl;
	return 0;
}

Submission Info

Submission Time
Task D - 塗り絵
User hoget157
Language C++14 (GCC 5.4.1)
Score 0
Code Size 752 Byte
Status TLE
Exec Time 2107 ms
Memory 8576 KB

Judge Result

Set Name All
Score / Max Score 0 / 100
Status
AC × 2
TLE × 20
Set Name Test Cases
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
Case Name Status Exec Time Memory
000.txt AC 2 ms 2560 KB
001.txt AC 2 ms 2560 KB
002.txt TLE 2104 ms 5632 KB
003.txt TLE 2104 ms 6528 KB
004.txt TLE 2103 ms 5248 KB
005.txt TLE 2103 ms 8576 KB
006.txt TLE 2104 ms 6272 KB
007.txt TLE 2104 ms 6528 KB
008.txt TLE 2103 ms 5376 KB
009.txt TLE 2103 ms 8576 KB
010.txt TLE 2104 ms 5376 KB
011.txt TLE 2104 ms 6528 KB
012.txt TLE 2103 ms 4992 KB
013.txt TLE 2104 ms 6528 KB
014.txt TLE 2104 ms 4480 KB
015.txt TLE 2104 ms 6528 KB
016.txt TLE 2107 ms 4992 KB
017.txt TLE 2104 ms 6528 KB
018.txt TLE 2103 ms 3328 KB
019.txt TLE 2104 ms 6528 KB
020.txt TLE 2103 ms 2944 KB
021.txt TLE 2104 ms 6656 KB