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;
  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: In function 'int main()':
a.cc:22:9: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   22 | 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:23:1: error: 'vector' was not declared in this scope
   23 | vector<vector<int>>graph(N); for(inti=0;i<N-1;++i){
      | ^~~~~~
a.cc:23:15: error: expected primary-expression before 'int'
   23 | vector<vector<int>>graph(N); for(inti=0;i<N-1;++i){
      |               ^~~
a.cc:23:34: error: 'inti' was not declared in this scope; did you mean 'int'?
   23 | vector<vector<int>>graph(N); for(inti=0;i<N-1;++i){
      |                                  ^~~~
      |                                  int
a.cc:23:41: error: 'i' was not declared in this scope
   23 | vector<vector<int>>graph(N); for(inti=0;i<N-1;++i){
      |                                         ^
a.cc:25:1: error: 'graph' was not declared in this scope; did you mean 'isgraph'?
   25 | graph[a].push_back(b);
      | ^~~~~
      | isgraph
a.cc:27:30: error: 'graph' was not declared in this scope; did you mean 'isgraph'?
   27 | long long int answer=K*dfs(K,graph,0,-1); answer%=mod;
      |                              ^~~~~
      |                              isgraph
a.cc:28:1: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   28 | 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:28:15: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   28 | 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:20:1: warning: control reaches end of non-void function [-Wreturn-type]
   20 | }
      | ^