Submission #656239

#TimeUsernameProblemLanguageResultExecution timeMemory
656239Hydroxic_AcidLogičari (COCI21_logicari)C++17
10 / 110
1084 ms10824 KiB
#include <iostream> #include <cstring> #include <vector> using namespace std; int N; vector<int> adjl[100005]; bool visited[100005]; int see[100005]; int cnt = 0; int dp(int i){ if(i <= N){ cnt++; for(int j = 0; j < (int)adjl[i].size(); j++){ see[adjl[i][j]]++; } int returnval = dp(i + 1); cnt--; for(int j = 0; j < (int)adjl[i].size(); j++){ see[adjl[i][j]]--; } int temp = dp(i + 1); if(temp == -1) return returnval; if(returnval == -1) return temp; return min(returnval, temp); } for(int j = 1; j <= N; j++){ if(see[j] != 1) return -1; } return cnt; } int main(){ cin >> N; for(int i = 0; i < N; i++){ int a, b; cin >> a >> b; adjl[a].push_back(b); adjl[b].push_back(a); } memset(visited, false, sizeof(visited)); memset(see, 0, sizeof(see)); cout << dp(1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...