hiho week 167 register

Ended

Participants:334

Verdict:Accepted
Score:100 / 100
Submitted:2017-09-11 10:50:40

Lang:G++

Edit
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
#include<stdio.h>
int p[110][2];
int n,r,s;
int gcd(int a,int b)
{
    if(a%b==0)  return b;
    else    return gcd(b,a%b);
}
int lcm(int a,int b)
{
    return a*b/gcd(a,b);
}
int main()
{
    int i,j,k,l;
    while(scanf("%d",&n)!=EOF)
    {
        for(i=1;i<=n;i++)scanf("%d",&p[i][0]);
        for(i=1;i<=n;i++)p[i][1]=1;
        r=1;
        for(i=1;i<=n;i++)if(p[i][1]==1)
        {
            j=i;
            s=0;
            while(p[j][1]==1)
            {
                p[j][1]=0;
                j=p[j][0];
                s++;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX