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 <bits/stdc++.h>
using namespace std;
int n;
vector <int> v[100000];
bool blue[100000], notBlue[100000];
int main()
{
cin>>n;
for(int i = 0; i < n; i++)
{
int a, b;
cin>>a>>b;
a--;
b--;
v[a].push_back(b);
v[b].push_back(a);
}
int res = 0;
for(int i = 0; i < n; i++)
{
if(blue[i] || notBlue[i])
continue;
blue[i] = true;
res++;
for(auto j : v[i])
for(auto t : v[j])
notBlue[t] = true;
}
for(int i = 0; i < n; i++)
{
bool seesBlue = false;
for(auto j : v[i])
if(blue[j])
{
seesBlue = true;
break;
}
if(!seesBlue)
{
cout<<-1<<endl;
return 0;
}
}
cout<<res<<endl;
return 0;
}
# | 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... |