#include"bits/stdc++.h" usingnamespace std; #define fi first #define se second #define vi vector<int> #define pb push_back #define eb emplace_back #define pii pair<int,int> #define mp make_pair #define rep( i , a , b ) for( int i = (a) , i##end = b ; i <= i##end ; ++ i ) #define per( i , a , b ) for( int i = (a) , i##end = b ; i >= i##end ; -- i ) #define mem( a ) memset( a , 0 , sizeof (a) ) #define all( x ) x.begin() , x.end() //#define int long long // #pragma GCC optimize(2) typedeflonglong ll; constint MAXN = 506 + 10; constint P = 1e9 + 7; int n;
int idx[MAXN][MAXN]; vector<pii> G[MAXN][MAXN]; int vis[MAXN][MAXN]; int cnt = 0; voiddfs( int i , int j ){ // if( i > j ) swap( i , j ); if( vis[i][j] ) return; vis[i][j] = cnt; for( auto t : G[i][j] ) { dfs( t.fi , t.se ); } }
voidsolve(){ cin >> n; rep( i , 1 , n * ( n - 1 ) / 2 ) { int u , v; scanf("%d%d",&u,&v); idx[u][v] = i; } rep( i , 1 , n ) rep( j , i + 1 , n ) rep( t , j + 1 , n ) { int a , u , v; int mx = max( { idx[i][j] , idx[j][t] , idx[i][t] } ); if( mx == idx[i][j] ) u = i , v = j , a = t; elseif( mx == idx[i][t] ) u = i , v = t , a = j; else u = j , v = t , a = i; G[a][u].eb( a , v ) , G[a][v].eb( a , u ); G[u][a].eb( v , a ) , G[v][a].eb( u , a ); } rep( i , 1 , n ) rep( j , i + 1 , n ) if( !vis[i][j] && !vis[j][i] ) { ++ cnt; dfs( i , j ); } int flg = 0; rep( i , 1 , n ) rep( j , 1 , n ) if( vis[i][j] && vis[j][i] ) { // cout << i << ' ' << j << endl; flg = 1; } // rep( i , 1 , n ) rep( j , i + 1 , n ) rep( t , j + 1 , n ) { // if( vis[i][j] == vis[j][t] && vis[i][j] == vis[i][t] ) { // cout << i << ' ' << j << ' ' << t << endl; // flg = 1; break; // } // } if( flg ) puts("0"); else { int res = 1; rep( t , 1 , cnt ) res = res * 2 % P; cout << res << endl; } }