#include <iostream>
#include <vector>
// #include <algorithm>
#include <queue>
// #include <string>
#include <bitset>
using namespace std;
vector<int> vert(101);
vector<vector<int> > a(101,vector<int>());
bitset<101> visited;
int dfs(int u){
visited[u]=1;
if(a[u].size()==0)return vert[u]=1;
int count=1;
for(int i=0;i<a[u].size();i++)
if(!visited[a[u][i]])count+=dfs(a[u][i]);
return vert[u]=count;
}
int bfs(int u){
visited[u]=1;
if(a[u].size()==0)return 0;
int count=0;
for(int i=0;i<a[u].size();i++){
if(!visited[a[u][i]]){
if(vert[a[u][i]]%2==0)count++;
count+=bfs(a[u][i]);
}
}
return count;
}
int main(){
int n,e;
cin>>n>>e;
for(int i=0;i<e;i++){
int x,y;
cin>>x>>y;
a[x].push_back(y);
a[y].push_back(x);
}
dfs(1);
// for(int z: vert)
// cout<<z<<' ';
visited.reset();
cout<<bfs(1)<<endl;
}
#include <vector>
// #include <algorithm>
#include <queue>
// #include <string>
#include <bitset>
using namespace std;
vector<int> vert(101);
vector<vector<int> > a(101,vector<int>());
bitset<101> visited;
int dfs(int u){
visited[u]=1;
if(a[u].size()==0)return vert[u]=1;
int count=1;
for(int i=0;i<a[u].size();i++)
if(!visited[a[u][i]])count+=dfs(a[u][i]);
return vert[u]=count;
}
int bfs(int u){
visited[u]=1;
if(a[u].size()==0)return 0;
int count=0;
for(int i=0;i<a[u].size();i++){
if(!visited[a[u][i]]){
if(vert[a[u][i]]%2==0)count++;
count+=bfs(a[u][i]);
}
}
return count;
}
int main(){
int n,e;
cin>>n>>e;
for(int i=0;i<e;i++){
int x,y;
cin>>x>>y;
a[x].push_back(y);
a[y].push_back(x);
}
dfs(1);
// for(int z: vert)
// cout<<z<<' ';
visited.reset();
cout<<bfs(1)<<endl;
}
Comments
Post a Comment