F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Color the Simple Cycle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/32768 K (Java/Others)
Total Submission(s): 394    Accepted Submission(s): 100


Problem Description
Consider a simple cycle with N vertices numbered from 1 to N. Each vertex and Each edge has an integer value. We use v[k] to represent the kth vertex's value, and e[k] to represent the kth edge's value. The kth edge is the edge of the kth and the (k+1)th vertex (the (N+m)th vertex is the mth vertex). Now we will use C different colors to color the graph. Every vertice will be colored by one of the C colors. If there exists some integer number k which satisfies v[i]=v[i+k] and e[i]=e[i+k] for each i from 1 to N(v[N+t]=v[t] and e[N+t]=e[t]), we call the graph is the same under k rotation.
If two ways of coloring the cycle can be the same with some rotation and under that rotation the color of the corresponding vertices are also the same, we consider the two ways are the same ways. Given the simple cycle and the number of colors we will use, how many different ways to color the cycle?
 

Input
First comes an integer T representing the number of test cases. Each case consists of three lines. First line contains N(1<=N<=100000) and C (1<=C<=1000000). Second line contains N integer numbers representing the vertex's values. The last line of each case contains N integer numbers representing the edge values. Each value is between 1 and 1000000.
 

Output
For each case, print a line with the different ways of coloring the cycle mod 1000000007.
 

Sample Input
2 3 1 1 1 1 2 2 2 3 2 1 1 1 2 2 2
 

Sample Output
1 4
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-02 12:12:36, Gzip enabled