Submission #1232035


Source Code Expand

#include<cstdio>
#include<string>
#include<algorithm>
#include<string.h>
#include<functional>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<limits.h>
#include<iostream>
#define int long long
#define mod 1000000007
using namespace std;


int r[100000];
vector<int>rinsetu[100000];
int S = 0;
void DFS(int a) {
	r[a] = S;
	S++;
	for (int i : rinsetu[a]) {
		if(r[i]==-1)
		DFS(i);
	}
	S--;
}
int saiki(int a, int b) {
	int c = 1;
	if (b == 0) {
		for (int i : rinsetu[a]) {
			if (r[i] > r[a]) {
				c = c*(saiki(i, 0) + saiki(i, 1)) % mod;
			}
		}
	}
	else {
		for (int i : rinsetu[a]) {
			if (r[i] > r[a]) {
				c = c*(saiki(i, 0)) % mod;
			}
		}
	}
	return c;
}
signed main() {
	memset(r, -1, sizeof(r));
	int a; scanf("%lld", &a);
	for (int b = 1; b < a; b++) {
		int c, d; scanf("%lld%lld", &c, &d);
		c--; d--;
		rinsetu[c].push_back(d);
		rinsetu[d].push_back(c);
	}
	DFS(0);
	cout << (saiki(0, 0) + saiki(0, 1))%mod << endl;
}

Submission Info

Submission Time
Task D - 塗り絵
User naoki2016
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1065 Byte
Status TLE
Exec Time 2104 ms
Memory 7040 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:51:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  int a; scanf("%lld", &a);
                          ^
./Main.cpp:53:38: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   int c, d; scanf("%lld%lld", &c, &d);
                                      ^

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 3 ms 3328 KB
001.txt AC 3 ms 3328 KB
002.txt TLE 2104 ms 6272 KB
003.txt TLE 2104 ms 7040 KB
004.txt TLE 2104 ms 5760 KB
005.txt TLE 2104 ms 7040 KB
006.txt TLE 2104 ms 6656 KB
007.txt TLE 2104 ms 7040 KB
008.txt TLE 2104 ms 5888 KB
009.txt TLE 2104 ms 7040 KB
010.txt TLE 2104 ms 6016 KB
011.txt TLE 2104 ms 7040 KB
012.txt TLE 2104 ms 5504 KB
013.txt TLE 2104 ms 7040 KB
014.txt TLE 2104 ms 5120 KB
015.txt TLE 2104 ms 7040 KB
016.txt TLE 2104 ms 5632 KB
017.txt TLE 2104 ms 7040 KB
018.txt TLE 2104 ms 3968 KB
019.txt TLE 2104 ms 7040 KB
020.txt TLE 2103 ms 3712 KB
021.txt TLE 2104 ms 7040 KB