// UVa 10227 - Forests
#include <iostream>
#include <string.h>
#include <sstream>
using namespace std;
int main() {
string l;
int tt;
cin >> tt;
getline(cin, l);
getline(cin, l);
for (; tt; tt--) {
int p, t;
getline(cin, l);
istringstream strm2(l);
strm2 >> p >> t;
bool see[100][100];
memset(see, false, sizeof(see));
while (getline(cin, l) && l.length() > 0) {
int a, b;
istringstream strm(l);
strm >> a >> b;
see[a][b] = true;
}
bool diff[100];
int sol = 0;
memset(diff, true, sizeof(diff));
for (int i = 1; i <= p; i++)
if (diff[i]) {
sol++;
for (int j = i + 1; j <= p; j++)
if (diff[j]) {
bool same = true;
for (int k = 1; k <= t; k++)
if (see[i][k] != see[j][k]) {
same = false;
break;
}
if (same)
diff[j] = false;
}
}
cout << sol << endl;
if (tt > 1)
cout << endl;
}
return 0;
}
Monday, June 22, 2015
UVa 10227 - Forests
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment