Submission #261064

# Submission time Handle Problem Language Result Execution time Memory
261064 2020-08-11T10:52:25 Z Hideo Duathlon (APIO18_duathlon) C++17
23 / 100
104 ms 14072 KB
//1610612741, 1000000007
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;

#define all(s) s.begin(), s.end()
#define ok puts("ok")
#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define pi pair < int, int >
#define pii pair < int, pi >
#define next next123
#define left left123

const int N = 2e5 + 7;
const int INF = 1e9 + 7;

ll S1, S2, S3;
int h[N], sz[N];
int n, m;

vi g[N];

void precalc (int v, int p = 0){
    h[v] = h[p] + 1;
    sz[v] = 1;
    for (int to : g[v]){
        if (!h[to]){
            precalc(to, v);
            sz[v] += sz[to];
        }
    }
}

void calc1 (int v, int csz){
    for (int to : g[v])
        if (h[to] - h[v] == 1)
            S1 += 1LL * (csz - sz[to] - 1) * sz[to];
    S1 += 1LL * (csz - sz[v]) * (sz[v] - 1);
    for (int to : g[v])
        if (h[to] - h[v] == 1)
            calc1(to, csz);
}

main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    for (int i = 1; i <= m; i++){
        int a, b;
        cin >> a >> b;
        g[a].pb(b);
        g[b].pb(a);
    }
    for (int i = 1; i <= n; i++)
        if (!h[i])
            precalc(i);
    for (int i = 1; i <= n; i++)
        if (h[i] == 1)
            calc1(i, sz[i]);
    cout << S1;
}

Compilation message

count_triplets.cpp:54:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 97 ms 14072 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 4 ms 5120 KB Output is correct
3 Correct 5 ms 5120 KB Output is correct
4 Correct 4 ms 5120 KB Output is correct
5 Correct 4 ms 5120 KB Output is correct
6 Correct 5 ms 5120 KB Output is correct
7 Correct 5 ms 5120 KB Output is correct
8 Correct 4 ms 5120 KB Output is correct
9 Correct 4 ms 5120 KB Output is correct
10 Correct 4 ms 5120 KB Output is correct
11 Correct 5 ms 5120 KB Output is correct
12 Correct 5 ms 5120 KB Output is correct
13 Correct 4 ms 5120 KB Output is correct
14 Correct 4 ms 5120 KB Output is correct
15 Correct 4 ms 5120 KB Output is correct
16 Correct 4 ms 5120 KB Output is correct
17 Correct 4 ms 5120 KB Output is correct
18 Correct 4 ms 5120 KB Output is correct
19 Correct 4 ms 5120 KB Output is correct
20 Correct 4 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 9584 KB Output is correct
2 Correct 70 ms 9336 KB Output is correct
3 Correct 69 ms 9384 KB Output is correct
4 Correct 72 ms 9336 KB Output is correct
5 Correct 77 ms 9340 KB Output is correct
6 Correct 92 ms 11768 KB Output is correct
7 Correct 84 ms 10976 KB Output is correct
8 Correct 86 ms 10492 KB Output is correct
9 Correct 94 ms 10104 KB Output is correct
10 Correct 79 ms 9464 KB Output is correct
11 Correct 85 ms 10360 KB Output is correct
12 Correct 88 ms 10360 KB Output is correct
13 Correct 88 ms 10360 KB Output is correct
14 Correct 72 ms 10104 KB Output is correct
15 Correct 74 ms 9824 KB Output is correct
16 Correct 56 ms 8824 KB Output is correct
17 Correct 64 ms 10608 KB Output is correct
18 Correct 63 ms 10608 KB Output is correct
19 Correct 52 ms 10604 KB Output is correct
20 Correct 68 ms 10616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 5 ms 5120 KB Output is correct
3 Incorrect 4 ms 5120 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 78 ms 9604 KB Output is correct
2 Correct 88 ms 9336 KB Output is correct
3 Incorrect 87 ms 9208 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4992 KB Output isn't correct
2 Halted 0 ms 0 KB -