#include <iostream>
#include <vector>
#include <vector>
#include <algorithm>
using namespace std;
struct c_t{
int a; int b;
};
bool myfunction (c_t i,c_t j) { return (i.a<j.a); }
int pocket(vector<c_t> & c, vector<int> & p, int & sz) {
for (auto ip = p.begin(); ip != p.end(); ip++) {
for (auto ic = c.begin(); ic != c.end(); ic++) {
if (ic->a == -1) continue;
if (*ip == ic->a) {
p.push_back(ic->b);
ic->a = -1; sz--;
}
if (*ip == ic->b) {
p.push_back(ic->a);
ic->a = -1; sz--;
}
}
}
return p.size();
}
int solve(vector<c_t> & c) {
int max = 0;
int r = 0;
int sz = c.size();
sort(c.begin(), c.end(), myfunction);
while(sz >= 0) {
cout << "size " << sz << endl;
auto ic = c.begin();
vector<int> p;
p.push_back(ic->a); p.push_back(ic->b);
ic->a = -1;
sz--;
r = pocket(c, p, sz);
if (r>max)
max = r;
}
return max;
}
int main() {
int t, n, p;
cin >> t;
while(t--) {
vector<c_t> c;
cin >> n >> p;
while (p--) {
c_t o;
cin >> o.a >> o.b;
c.push_back(o);
}
cout << solve(c) << endl;
}
return 0;
}
#include <vector>
#include <vector>
#include <algorithm>
using namespace std;
struct c_t{
int a; int b;
};
bool myfunction (c_t i,c_t j) { return (i.a<j.a); }
int pocket(vector<c_t> & c, vector<int> & p, int & sz) {
for (auto ip = p.begin(); ip != p.end(); ip++) {
for (auto ic = c.begin(); ic != c.end(); ic++) {
if (ic->a == -1) continue;
if (*ip == ic->a) {
p.push_back(ic->b);
ic->a = -1; sz--;
}
if (*ip == ic->b) {
p.push_back(ic->a);
ic->a = -1; sz--;
}
}
}
return p.size();
}
int solve(vector<c_t> & c) {
int max = 0;
int r = 0;
int sz = c.size();
sort(c.begin(), c.end(), myfunction);
while(sz >= 0) {
cout << "size " << sz << endl;
auto ic = c.begin();
vector<int> p;
p.push_back(ic->a); p.push_back(ic->b);
ic->a = -1;
sz--;
r = pocket(c, p, sz);
if (r>max)
max = r;
}
return max;
}
int main() {
int t, n, p;
cin >> t;
while(t--) {
vector<c_t> c;
cin >> n >> p;
while (p--) {
c_t o;
cin >> o.a >> o.b;
c.push_back(o);
}
cout << solve(c) << endl;
}
return 0;
}
댓글 없음:
댓글 쓰기