Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create TR5 #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions TR5
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <iostream>
using namespace std;
#define M 100010
#define ll long long int
#define m 1000000007
#define PI 3.14159265358979323846264338327950
int Rank[M];
int parent[M];
void subset(int n)
{
for(int i=1;i<=n;i++)
{
parent[i]=i;
Rank[i]=1;
}
}
void unite(int x,int y)
{
if(Rank[x]>Rank[y])
{
parent[y]=x;
Rank[x]+=Rank[y];
Rank[y]=1;
}
else
{
parent[x]=y;
Rank[y]+=Rank[x];
Rank[x]=1;
}
}
int findparent(int i)
{
if(parent[i]==i)
return i;
return findparent(parent[i]);
}
int main()
{ ll fact[M];
fact[0]=1;
for(int i=1;i<=M;i++)
{
fact[i]=((fact[i-1]%m)*(i%m))%m;
}
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n;
cin>>n;
subset(n);
int x,y;
int k;
cin>>k;
while(k--)
{
cin>>x>>y;
int xroot=findparent(x+1);
int yroot=findparent(y+1);
if(xroot!=yroot) unite(xroot,yroot);
}
ll ways=1;
for(int i=1;i<=n;i++)
{
ways=((ways%m)*(fact[Rank[i]]%m))%m;
}
cout<<ways<<"\n";

return 0;
}