题目理解: 找出图中连接的三条边,起点和终点可以相同,求有多少种,直接暴力来写
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 1e4+10;
vector<int> vec[N];
int book[N];
int main()
{
int n,m;
int u,v,ans = 0 ;
cin>>n>>m;
for ( int i=0; i<m; i++ )
{
scanf("%d%d",&u,&v) ;
vec[u].push_back(v);
vec[v].push_back(u);
}
for ( int i=1; i<=n; i++ )
{
book[i] = 1;
for ( int j=0; j<vec[i].size(); j++ ) {
int to1 = vec[i][j];
book[to1] = 1;
for ( int l = 0; l<vec[to1].size(); l++ ) {
int to2 = vec[to1][l];
if ( book[to2]==0 ) ans += vec[to2].size()-1;
}
book[to1] = 0;
}
book[i] = 0;
}
cout<<ans<<endl;
return 0;
}