Submission #1520793


Source Code Expand

#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<complex>
#include<unordered_map>

#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-8

#define REP(i, m) for(long long i = 0; i < m; ++i)
#define FOR(i, n, m) for(long long i = n; i < m; ++i)
#define ALL(v) v.begin(), v.end()
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

vector<vector<int> > adj;
ll dfs(int pos, int c, int b) {
	ll res=1;
	REP(i,adj[pos].size()) {
		if(adj[pos][i]!=b) {
			if(c==0) res*=dfs(adj[pos][i],0,pos)+dfs(adj[pos][i],1,pos);
			else res*=dfs(adj[pos][i],0,pos);
		}
	}
	return res % MOD;
}

int main() {
	int n;
	cin>>n;
	adj.resize(n);
	REP(i,n-1) {
		int a,b;
		cin>>a>>b;
		--a;
		--b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	cout<<dfs(0,0,-1)+dfs(0,1,-1)<<endl;
}

Submission Info

Submission Time
Task D - 塗り絵
User gazelle
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1006 Byte
Status TLE
Exec Time 2104 ms
Memory 5760 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 1 ms 256 KB
001.txt AC 1 ms 256 KB
002.txt TLE 2103 ms 4608 KB
003.txt TLE 2104 ms 5760 KB
004.txt TLE 2103 ms 3840 KB
005.txt TLE 2104 ms 5760 KB
006.txt TLE 2104 ms 5376 KB
007.txt TLE 2104 ms 5760 KB
008.txt TLE 2104 ms 4096 KB
009.txt TLE 2104 ms 5760 KB
010.txt TLE 2104 ms 4224 KB
011.txt TLE 2104 ms 5760 KB
012.txt TLE 2103 ms 3456 KB
013.txt TLE 2103 ms 5760 KB
014.txt TLE 2103 ms 2816 KB
015.txt TLE 2104 ms 5760 KB
016.txt TLE 2103 ms 3584 KB
017.txt TLE 2104 ms 5760 KB
018.txt TLE 2103 ms 1280 KB
019.txt TLE 2104 ms 5760 KB
020.txt TLE 2103 ms 768 KB
021.txt TLE 2104 ms 5760 KB