-
Notifications
You must be signed in to change notification settings - Fork 1
/
FIRESC.cpp
61 lines (54 loc) · 906 Bytes
/
FIRESC.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<cstdio>
#include<vector>
using namespace std;
typedef vector<int> VI;
vector<VI> a;
VI mark;
int cnt;
void dfs(int u)
{
++cnt;
mark[u]=1;
for(VI::iterator v=a[u].begin();v!=a[u].end();++v)
{
if(!mark[*v])
{
dfs(*v);
}
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int N, M;
scanf("%d%d", &N, &M);
a=vector<VI> (N);
for(int i=0;i<M;++i)
{
int u,v;
scanf("%d%d",&u,&v);
--u;
--v;
a[u].push_back(v);
a[v].push_back(u);
}
int res=0,ways=1;
mark=VI(N,0);
for(int u=0;u<N;u++)
{
if(mark[u])
{
continue;
}
++res;
cnt=0;
dfs(u);
ways = (long long)cnt * ways % 1000000007;
}
printf("%d %d\n", res, ways);
}
return 0;
}