src2020/4083_mit/main.cpp

44 lines
1.1 KiB
C++

#include <iostream>
using namespace std;
int main()
{
int n, m, rdui[100001] = { 0 }, jiad = 0, fud = 0;
bool dui[100001] = { 0 };
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int yi, er;
char u;
cin >> u >> yi >> er;
if (rdui[yi] == 0 && rdui[er] == 0) {
jiad++;
rdui[yi] = jiad;
rdui[er] = jiad;
}
if (rdui[yi] != 0 && rdui[er] == 0) {
rdui[er] = rdui[yi];
}
if (rdui[yi] == 0 && rdui[er] != 0) {
rdui[yi] = rdui[er];
}
if (rdui[yi] != 0, rdui[er] != 0) {
fud++;
if (dui[rdui[yi]] == 0 && dui[rdui[er]] == 0) {
dui[rdui[er]] = 1;
} else {
if (dui[rdui[yi]] == 1 && dui[rdui[er]] == 1) {
fud--;
} else {
dui[rdui[yi]] = dui[rdui[er]] == 1;
}
}
}
}
int ll = jiad - fud;
cout << "1";
for (int i = 1; i <= ll; i++) {
cout << "0";
}
return 0;
}