#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Incorrect |
87 ms |
7028 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Incorrect |
87 ms |
7028 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |