题意
思路
仍然是凑数的水~只要闷头做就好了,然后注意一下那个sign量
代码
#include <iostream>
#include <string.h>
using namespace std;
int main() {
int t,person,relation,leastneed,net[101][101],people1,people2;
while(cin>>t) {
while (t--) {
cin >> person >> relation >> leastneed;
memset(net, 0, sizeof(net));
int operation = 0;
while (relation--) {
cin >> people1 >> people2;
net[people1][people2]=1,net[people2][people1]=1;
}
int sign=1;
while(sign){
sign=0;
for (int i = 0; i < person; i++) {
for (int j = 0; j < person; j++) {
int commonfriends = 0;
if (net[i][j] == 0 && i != j) {
for (int k = 0; k < person; k++) {
if (net[i][k] == 1 && net[j][k] == 1) {
commonfriends++;
}
}
if (commonfriends >= leastneed) {
net[i][j]=1,net[j][i] = 1;
operation++;
sign=1;
}
}
}
}
}
cout << operation << endl;
}
}
return 0;
}