Submission #427826

#TimeUsernameProblemLanguageResultExecution timeMemory
427826OzyStar Trek (CEOI20_startrek)C++17
0 / 100
5 ms5196 KiB
#include <iostream> #include <bits/stdc++.h> using namespace std; #define lli long long int #define rep(i,a,b) for(int i = (a); i <= (b); i++) #define repa(i,a,b) for(int i = (a); i >= (b); i--) #define debugsl(a) cout << #a << " = " << a << ", " #define debug(a) cout << #a << " = " << a << endl; #define MAX 100000 #define mod 1000000007 bool si; lli n,d,a,b,total,g,p; vector<lli> hijos[MAX+2]; lli estado[MAX+2],original[MAX+2]; lli DFS (lli pos, lli padre) { lli res = 1; lli cant = 0; for (auto h : hijos[pos]) { if (h == padre) continue; cant++; res *= DFS(h,pos); } if (cant == 0) { if (si) original[pos] = 0; return 0; } if (res == 0) { if (si) original[pos] = 1; return 1; } else { if (si) original[pos] = 0; return 0; } } lli resuelve(lli pos, lli padre, lli prof) { if (prof%2 == 0) total += p; else if (original[pos] == 0) total += g; if (total > mod) total %= mod; for(auto h : hijos[pos]) { if (h == padre) continue; if (prof%2 == 0){ if (original[pos] == 0) { if (hijos[pos].size() <= 2) resuelve(h,pos,prof+1); } else if (original[h] == 0) resuelve(h,pos,prof+1); } else { if (original[pos] == 1) { if (hijos[pos].size() <= 2) resuelve(h,pos,prof+1); } else resuelve(h,pos,prof+1); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> d; rep(i,1,n-1) { cin >> a >> b; hijos[a].push_back(b); hijos[b].push_back(a); } si = true; rep(i,1,n) { estado[i] = DFS(i,0); si = false; if (estado[i] == 0) p++; else g++; } total = 0; resuelve(1,0,0); cout << total; }

Compilation message (stderr)

startrek.cpp: In function 'long long int resuelve(long long int, long long int, long long int)':
startrek.cpp:64:1: warning: no return statement in function returning non-void [-Wreturn-type]
   64 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...