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 <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
int b1;
int cycle(int a, int b2);
vector<vector<int>> v;
vector<int> v2;
vector<int> cnt;
int main()
{
int n,m,a,b,t=0, i;
cin >> n >> m;
v.resize(n);
v2.resize(n);
cnt.resize(n);
for(i=0;i<n;++i){
v2.at(i)=0;
}
for(i=0; i<m; ++i)
{
cin >> a >> b;
v.at(a-1).push_back(b-1);
v.at(b-1).push_back(a-1);
}
b1=0;
int temp1, temp2;
temp1=cycle(1,-1);
for(i=0; i<n;++i)
{
if(cnt.at(i)==0){temp2=cycle(i,-1);break;}
}
if(temp1==0 && temp2==0){++t;}
for(i=1;i<n;++i)
{
for(int j=0;j<n;++j){
v2.at(j)=0;
}
for(int j=0;j<n;++j){
cnt.at(j)=0;
}
b1=i;
temp1=cycle(0,-1);
for(int j=0; j<n;++j)
{
if(cnt.at(j)==0){temp2=cycle(j,-1);break;}
}
if(temp1==0 && temp2==0){t+=i+1;}
}
cout <<t;
}
int cycle(int a,int b2)
{
v2.at(a)=1;
cnt.at(a)=1;
int k;
for(int i=0;i<v.at(a).size();++i){
k=v.at(a).at(i);
//cout << k << " ";
if(k==b1||k==b2){
//cout << k << " continue" << endl;
continue;
}
else if(v2.at(k)==1){
//cout << "find cycle" << endl;
return 1;
}
// cout<< v.at(a).at(i) << " ";//<< endl;
if(cycle(v.at(a).at(i), a))return 1;
}
v2.at(a)=0;
return 0;
}
Compilation message (stderr)
cat.cpp: In function 'int cycle(int, int)':
cat.cpp:62:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v.at(a).size();++i){
~^~~~~~~~~~~~~~~
cat.cpp: In function 'int main()':
cat.cpp:36:17: warning: 'temp2' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(temp1==0 && temp2==0){++t;}
~~~~~~~~~^~~~~~~~~~~
# | 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... |