This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |