UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213638#2715. 8.4t4erican2053ms1348kbC++112.0kb2024-11-12 22:18:392024-11-13 00:02:53

answer

// Problem: B. 8.4t4
// Contest: undefined - NOIP2024训练赛 03
// URL: http://noi.ac/contest/1155/problem/2715
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
// Challenger: Erica N
// ----
// 
#include<bits/stdc++.h>

using namespace std;
#define rd read()
#define ull unsigned long long
#define int long long 
#define pb push_back
#define itn int
#define ps second 
#define pf first


#define rd read()
int read(){
  int xx = 0, ff = 1;char ch = getchar();
  while (ch < '0' || ch > '9'){
    if (ch == '-')ff = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')xx = xx * 10 + (ch - '0'), ch = getchar();
  return xx * ff;
}
#define zerol = 1
#ifdef zerol
#define cdbg(x...) do { cerr << #x << " -> "; err(x); } while (0)
void err() {cerr << endl;}
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) {
	for (auto v: a) cerr << v << ' ';err(x...);
}
template<typename T, typename... A>
void err(T a, A... x) {
	cerr << a << ' ';err(x...);
}
#else
#define dbg(...)
#endif
const int N=2e5+5;
const ull P=137;
const int INF=1e18+7;
/*

策略


*/	

const int mod=1e9+7;
const int maxn=5005;
bool vis[maxn];
vector<int> e[maxn];
int n;
inline void view_all(vector<int> &cur,int x,int fa)
{
    cur.push_back(x);
    for(int p: e[x])
    {
        if (vis[p]) continue;
        if (p == fa) continue;
        view_all(cur, p, x);
    }
}
inline int calc(int x)
{
    vector<int> cur;
    int ans = 0;
    view_all(cur, x, -1);
    for(int w : cur)
    {
        int res = 1;
        vis[w] = 1;
        for(int p: e[w])
        {
            if (vis[p]) continue;
            res = 1ll * res * calc(p) % mod;
        }
        vis[w] = 0;
        ans = (ans + res) % mod;
    }
    return ans;
}
inline int get_ans()
{
    return calc(1);
}


void add(int a,int b){
	e[a].pb(b);
	e[b].pb(a);
}

signed main(){
	int n=rd;
	for(int i=1;i<n;i++){
		add(rd,rd);
	}
	cout<<get_ans();
}



详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 41ms
memory: 1344kb

input:

10
1 2
1 3
3 4
3 5
3 6
3 7
1 8
5 9
5 10

output:

227506

result:

ok found '227506.00000', expected '227506.00000', error '0.00000'

Test #2:

score: 10
Accepted
time: 12ms
memory: 1348kb

input:

10
1 2
1 3
3 4
4 5
5 6
4 7
5 8
8 9
8 10

output:

70140

result:

ok found '70140.00000', expected '70140.00000', error '0.00000'

Test #3:

score: 0
Time Limit Exceeded

input:

100
1 2
1 3
1 4
3 5
5 6
4 7
7 8
8 9
8 10
3 11
7 12
1 13
5 14
8 15
10 16
7 17
1 18
6 19
10 20
15 21
7...

output:


result:


Test #4:

score: 0
Time Limit Exceeded

input:

100
1 2
2 3
3 4
4 5
4 6
6 7
5 8
8 9
8 10
1 11
6 12
4 13
9 14
13 15
7 16
3 17
15 18
17 19
9 20
8 21
4...

output:


result:


Test #5:

score: 0
Time Limit Exceeded

input:

100
1 2
2 3
3 4
2 5
2 6
5 7
2 8
4 9
7 10
5 11
11 12
6 13
8 14
13 15
5 16
11 17
16 18
11 19
7 20
19 2...

output:


result:


Test #6:

score: 0
Time Limit Exceeded

input:

500
1 2
1 3
3 4
3 5
5 6
1 7
3 8
8 9
4 10
6 11
7 12
2 13
11 14
8 15
7 16
9 17
2 18
3 19
15 20
2 21
20...

output:


result:


Test #7:

score: 0
Time Limit Exceeded

input:

500
1 2
1 3
1 4
2 5
5 6
5 7
4 8
8 9
1 10
4 11
8 12
6 13
13 14
13 15
12 16
1 17
10 18
13 19
1 20
1 21...

output:


result:


Test #8:

score: 0
Time Limit Exceeded

input:

5000
1 2
1 3
1 4
3 5
3 6
5 7
4 8
4 9
1 10
5 11
6 12
10 13
12 14
14 15
12 16
8 17
14 18
9 19
8 20
20 ...

output:


result:


Test #9:

score: 0
Time Limit Exceeded

input:

5000
1 2
1 3
1 4
2 5
1 6
5 7
2 8
5 9
4 10
9 11
10 12
8 13
7 14
13 15
12 16
5 17
9 18
8 19
3 20
4 21
...

output:


result:


Test #10:

score: 0
Time Limit Exceeded

input:

5000
1 2
1 3
1 4
4 5
4 6
3 7
2 8
8 9
6 10
9 11
3 12
3 13
7 14
13 15
4 16
10 17
9 18
10 19
5 20
17 21...

output:


result: