Submission #815813

# Submission time Handle Problem Language Result Execution time Memory
815813 2023-08-09T00:23:42 Z Ozy Duathlon (APIO18_duathlon) C++17
0 / 100
29 ms 5748 KB
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define debug(a) cout << #a <<  " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define pll pair<lli,lli> 

#define MAX 100000

lli n,m,a,b,tam,res;
vector<lli> hijos[MAX+2];
lli vis[MAX+2];

bool ciclo(lli pos, lli padre) {
    bool puedo = false;

    tam++;
    vis[pos]=1;
    for(auto h : hijos[pos]) {
        if (h == padre) continue;
        if (vis[h]) {
            puedo = true;
            continue;
        }
        puedo |= ciclo(h,pos);
    }

    return puedo;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m;

    rep(i,1,m) {
        cin >> a >> b;
        hijos[a].push_back(b);
    }

    rep(i,1,n) {
        if(vis[i]) continue;
        tam = 0;
        if (ciclo(i,0)) {
            if(tam < 3) continue;
            a = (tam*(tam-1)*(tam-2))/2;
        }
        else {
            if(tam < 3) continue;
            a = (tam*(tam-1)*(tam-2))/3;
        }
        res += a;
    }

    cout << res;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 5748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 5660 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 5680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -