#include <bits/stdc++.h>
using namespace std ;
const int N = 1010 , mod = 4001 ;
struct graph
{
int n ;
bool edge[N][N] ;
} gg ;
int hash11( graph g )
{
int deg[N] ;
memset( deg , 0 , sizeof(deg) ) ;
for( int i = 0 ; i < g.n ; i ++ ) //这个for循环的功能是计算所有点的度数
{
for( int j = 0 ; j < g.n ; j ++ )
{
if( g.edge[i][j] )
{
deg[i] ++ ;
}
}
}
int a[N] , p[N] ;
memset( p , 0 , sizeof(p) ) ;
for( int i = 0 ; i < g.n ; i ++ )
{
a[i] = i ;
}
for( int i = 0 ; i < g.n ; i ++ ) //这个for循环的功能是对所有点按照度数进行冒泡排序
{
for( int j = g.n - 1 ; j > i ; j -- )
{
if( deg[a[j]] > deg[a[j - 1]] )
{
int tmp = a[j] ;
a[j] = a[j - 1] ;
a[j - 1] = tmp ;
}
}
}
int ans = 0 ;
for( int i = 0 ; i < g.n ; i ++ ) //这个for循环的功能是计算hash值
{
for( int j = 0 ; j < g.n ; j ++ )
{
if( g.edge[a[i]][j] )
{
ans += deg[a[i]] * deg[j] ;
deg[j] -- ;
ans %= mod ;
}
}
}
return ans ;
}
//以下省略main函数
varN,M: integer
N:=1000M:=4001// This function calculates the hash value.// The variant edge means stores the graph:// If the value of edge[i,j] is true, then it has an edge between i and j.functionhash11(edge [1:N,1:N]: boolean , n : integer)
begin
var deg [1:N]: integer
var i , j : integer
for i :=1 to n do
begin
deg [ i ]:=0
end
// This part calculates the degrees of all pointsfor i :=1 to n do
begin
for j :=1 to n do
begin
if edge [ i , j ]==true then do
begin
deg [ i ]:= deg [ i ]+1
end
end
end
var a [1:N]: integer
for i :=1 to n do
begin
a [ i ]:= i
end
// This part is a bubble sort of all points by degreefor i :=1 to n -1do
begin
for j := n downto i +1do
begin
if deg [ a [ j ]]> deg [ a [ j -1]] then do
begin
var tmp : integer
tmp := a [ j ]
a [ j ]:= a [ j -1]
a [ j -1]:= tmp
end
end
end
var ans : integer
ans :=0// This part is to calculates the hash value.for i :=1 to n do
begin
for j :=1 to n do
begin
if edge [ a [ i ], j ]==true then do
begin
ans := ans + deg [ a [ i ]]* deg [ j ]
deg [ j ]:= deg [ j ]-1
ans := ans mod M
end
end
end
return: ans
end