CSES - Datatähti Open 2017 - Results
Submission details
Task:Witch game
Sender:MladenP
Submission time:2017-01-22 20:25:58 +0200
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:14:5: error: expected ';' before '}' token
     }
     ^
input/code.cpp:6:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int n; scanf("%d", &n);
                           ^
input/code.cpp:8:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
                           ^

Code

#include <bits/stdc++.h>
#define MAXN 100010
using namespace std;
int a[MAXN], degin[MAXN];
int main() {
    int n; scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        degin[a[i]]++;
    }
    long long rez = (long long) n * (n-1) * (n-2) / 6;
    for(int i = 1; i <= n; i++) {
        rez -= n - 2
    }
for(int i=1;i<=n;i++){
rez+=degin[i]*(degin[i]+1)/2;}
for(int i=1;i<=n;i++) if(a[a[a[i]]]==i) rez--;
    printf("%lld", rez);
}