1126. Eulerian Path (25) 注意判断连通
#include <iostream>#include <vector>using namespace std;int cnt=0,vis[502];vector<vector<int>> v(502);void dfs(int u)//判断是否连通{ vis[u]=1;cnt++; for(auto it=v[u].begin();it!=v[u].end();++it) if(vis[*it]==0)dfs(*it);}int main(){ int vnum,anum; cin>>vnum>>anum; int w,u; for(int i=0;i<anum;++i) { cin>>w>>u; v[w].push_back(u); v[u].push_back(w); } int oddcnt=0; for(int i=1;i<=vnum;++i) { ((int)v[i].size()&1)?oddcnt++:1; (i==vnum)?cout<<v[i].size()<<endl:cout<<v[i].size()<<" "; } dfs(1); if(!oddcnt&&cnt==vnum)cout<<"Eulerian"; else if(oddcnt==2&&cnt==vnum)cout<<"Semi-Eulerian"; else cout<<"Non-Eulerian"; return 0;}新闻热点
疑难解答