Language: C++

#include<iostream> #include<vector> using namespace std;
const long long int mod=1e9+7;
long long int dfs(int K,const vector<vector<int>>&graph, int now,int from) {
int can_use_color_num; if (from==-1) {
can_use_color_num=K-1; }
else { can_use_color_num=K-2;
}
if (K<graph[now].size()) {
return 0; }
else {
long long int case_num=1; for (auto e : graph[now]) {
if(e==from)continue;
case_num*=can_use_color_num; can_use_color_num--; case_num%=mod;
}
for (auto e : graph[now]) {
if(e==from)continue;
5
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
case_num *=dfs(K,graph,e,now);
case_num %= mod; }
return case_num; }
}
int main() {
int N,K;cin>>N>>K;
vector<vector<int>>graph(N); for(inti=0;i<N-1;++i){
int a,b;cin>>a>>b;a--;b--;
graph[a].push_back(b);
graph[b].push_back(a); }
long long int answer=K*dfs(K,graph,0,-1); answer%=mod;
cout<<answer<<endl;
return 0;
}

Compiler output:
a.cc:1:20: warning: extra tokens at end of #include directive
    1 | #include<iostream> #include<vector> using namespace std;
      |                    ^
a.cc:3:31: error: 'vector' does not name a type
    3 | long long int dfs(int K,const vector<vector<int>>&graph, int now,int from) {
      |                               ^~~~~~
a.cc:3:37: error: expected ',' or '...' before '<' token
    3 | long long int dfs(int K,const vector<vector<int>>&graph, int now,int from) {
      |                                     ^
a.cc: In function 'long long int dfs(int, int)':
a.cc:4:28: error: 'from' was not declared in this scope
    4 | int can_use_color_num; if (from==-1) {
      |                            ^~~~
a.cc:8:7: error: 'graph' was not declared in this scope; did you mean 'isgraph'?
    8 | if (K<graph[now].size()) {
      |       ^~~~~
      |       isgraph
a.cc:8:13: error: 'now' was not declared in this scope
    8 | if (K<graph[now].size()) {
      |             ^~~
a.cc:12:7: error: 'from' was not declared in this scope
   12 | if(e==from)continue;
      |       ^~~~
a.cc:16:7: error: 'from' was not declared in this scope
   16 | if(e==from)continue;
      |       ^~~~
a.cc:17:2: error: expected ';' before numeric constant
   17 | 5
      |  ^
      |  ;
   18 | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
      | ~~
a.cc: In function 'int main()':
a.cc:24:9: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   24 | int N,K;cin>>N>>K;
      |         ^~~
      |         std::cin
In file included from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:25:1: error: 'vector' was not declared in this scope
   25 | vector<vector<int>>graph(N); for(inti=0;i<N-1;++i){
      | ^~~~~~
a.cc:25:15: error: expected primary-expression before 'int'
   25 | vector<vector<int>>graph(N); for(inti=0;i<N-1;++i){
      |               ^~~
a.cc:25:34: error: 'inti' was not declared in this scope; did you mean 'int'?
   25 | vector<vector<int>>graph(N); for(inti=0;i<N-1;++i){
      |                                  ^~~~
      |                                  int
a.cc:25:41: error: 'i' was not declared in this scope
   25 | vector<vector<int>>graph(N); for(inti=0;i<N-1;++i){
      |                                         ^
a.cc:27:1: error: 'graph' was not declared in this scope; did you mean 'isgraph'?
   27 | graph[a].push_back(b);
      | ^~~~~
      | isgraph
a.cc:29:30: error: 'graph' was not declared in this scope; did you mean 'isgraph'?
   29 | long long int answer=K*dfs(K,graph,0,-1); answer%=mod;
      |                              ^~~~~
      |                              isgraph
a.cc:30:1: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   30 | cout<<answer<<endl;
      | ^~~~
      | std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:30:15: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   30 | cout<<answer<<endl;
      |               ^~~~
      |               std::endl
In file included from /usr/include/c++/14/iostream:41:
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~
a.cc: In function 'long long int dfs(int, int)':
a.cc:22:1: warning: control reaches end of non-void function [-Wreturn-type]
   22 | }
      | ^