Submission #628280

# Submission time Handle Problem Language Result Execution time Memory
628280 2022-08-13T09:31:06 Z Do_you_copy Duathlon (APIO18_duathlon) C++17
49 / 100
98 ms 40304 KB
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using ull = unsigned ll;
using ld = long double;
using pii = pair <int, int>;
using pil = pair <int, ll>;
using pli = pair <ll, int>;
using pll = pair <ll, ll>;
mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count());

ll min(const ll &a, const ll &b){
    return (a < b) ? a : b;
}

ll max(const ll &a, const ll &b){
    return (a > b) ? a : b;
}

//const ll Mod = 1000000007;
//const ll Mod2 = 999999999989;
//only use when required
const int maxN = 1e5 + 1;
int n, m;
vector <int> adj[maxN];
int low[maxN], num[maxN], timedfs;
vector <int> S;
vector <int> adj1[maxN];
int bcc;
ll sz[maxN];

ll cnt, ans;
void pre_dfs(int u, int p){
    low[u] = num[u] = ++timedfs;
    S.pb(u);
    ++cnt;
    int child = 0;
    for (const int &i: adj[u]){
        if (i == p) continue;
        if (!num[i]){
            pre_dfs(i, u);
            ++child;
            low[u] = min(low[u], low[i]);
            if (low[i] >= num[u]){
                ++bcc;
                adj1[u].pb(n + bcc);
                int v;
                do{
                    v = S.back();
                    S.pop_back();
                    adj1[bcc + n].pb(v);
                } while (v != i);
            }
        }
        else low[u] = min(low[u], num[i]);
    }
}

void dfs(int u, int p){
    sz[u] = (u <= n);
    for (auto i: adj1[u]){
        dfs(i, u);
        sz[u] += sz[i];
        if (u > n) ans -= adj1[u].size() * sz[i] * (sz[i] - 1);
    }
    if (u > n) ans -= adj1[u].size() * (cnt - sz[u]) * (cnt - sz[u] - 1);
}

void Init(){
    cin >> n >> m;
    for (int i = 1; i <= m; ++i){
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    for (int i = 1; i <= n; ++i){
        if (!num[i]){
            cnt = 0;
            pre_dfs(i, i);
            ans += cnt * (cnt - 1) * (cnt - 2);
            dfs(i, i);
        }
    }
    cout << ans;
}

#define debu
#define taskname "test"
signed main(){
    if (fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
        #ifdef debug
        freopen(taskname".out", "w", stdout);
        #endif
    }
    faster;
    ll tt = 1;
    //cin >> tt;
    while (tt--){
        Init();
    }
    if (fopen("timeout.txt", "r")){
        ofstream timeout("timeout.txt");
        timeout << 1000 * double(clock()) / CLOCKS_PER_SEC;
        #ifndef debug
        cerr << "\nTime elapsed: " << 1000 * double(clock()) / CLOCKS_PER_SEC << "ms\n";
        #endif
    }
}

Compilation message

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:97:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 4 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 4 ms 4964 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 4 ms 5012 KB Output is correct
29 Correct 4 ms 4948 KB Output is correct
30 Correct 3 ms 4948 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 3 ms 4948 KB Output is correct
34 Correct 4 ms 4948 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 4 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 4 ms 4964 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 4 ms 5012 KB Output is correct
29 Correct 4 ms 4948 KB Output is correct
30 Correct 3 ms 4948 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 3 ms 4948 KB Output is correct
34 Correct 4 ms 4948 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 2 ms 4948 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 3 ms 4948 KB Output is correct
40 Correct 4 ms 4948 KB Output is correct
41 Correct 4 ms 4948 KB Output is correct
42 Correct 4 ms 5032 KB Output is correct
43 Correct 4 ms 4948 KB Output is correct
44 Correct 4 ms 4948 KB Output is correct
45 Correct 3 ms 4948 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 4 ms 4948 KB Output is correct
50 Correct 4 ms 5004 KB Output is correct
51 Correct 3 ms 4948 KB Output is correct
52 Correct 4 ms 4948 KB Output is correct
53 Correct 3 ms 4948 KB Output is correct
54 Correct 3 ms 4948 KB Output is correct
55 Correct 4 ms 4948 KB Output is correct
56 Correct 4 ms 4948 KB Output is correct
57 Correct 4 ms 4948 KB Output is correct
58 Correct 2 ms 4948 KB Output is correct
59 Correct 3 ms 4948 KB Output is correct
60 Correct 3 ms 4948 KB Output is correct
61 Correct 4 ms 5040 KB Output is correct
62 Correct 3 ms 4948 KB Output is correct
63 Correct 3 ms 4968 KB Output is correct
64 Correct 3 ms 4948 KB Output is correct
65 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 98 ms 40304 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5076 KB Output is correct
2 Correct 4 ms 5092 KB Output is correct
3 Correct 4 ms 5076 KB Output is correct
4 Correct 3 ms 5204 KB Output is correct
5 Correct 3 ms 5204 KB Output is correct
6 Correct 4 ms 5204 KB Output is correct
7 Correct 3 ms 5204 KB Output is correct
8 Correct 3 ms 5204 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 3 ms 5088 KB Output is correct
14 Correct 4 ms 5076 KB Output is correct
15 Correct 3 ms 5084 KB Output is correct
16 Correct 4 ms 5084 KB Output is correct
17 Correct 3 ms 5080 KB Output is correct
18 Correct 3 ms 5080 KB Output is correct
19 Correct 3 ms 5088 KB Output is correct
20 Correct 3 ms 5088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 41 ms 17644 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5088 KB Output is correct
2 Correct 3 ms 5088 KB Output is correct
3 Correct 4 ms 5168 KB Output is correct
4 Correct 4 ms 5088 KB Output is correct
5 Correct 4 ms 5044 KB Output is correct
6 Correct 5 ms 5076 KB Output is correct
7 Correct 4 ms 5032 KB Output is correct
8 Correct 3 ms 5076 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 4 ms 5076 KB Output is correct
11 Correct 3 ms 5076 KB Output is correct
12 Correct 4 ms 5220 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 3 ms 5076 KB Output is correct
17 Correct 3 ms 5144 KB Output is correct
18 Correct 4 ms 5076 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 4 ms 5076 KB Output is correct
21 Correct 4 ms 5076 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 4 ms 5076 KB Output is correct
24 Correct 4 ms 5076 KB Output is correct
25 Correct 4 ms 5120 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 55 ms 17652 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 4 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 4 ms 4964 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 4 ms 5012 KB Output is correct
29 Correct 4 ms 4948 KB Output is correct
30 Correct 3 ms 4948 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 3 ms 4948 KB Output is correct
34 Correct 4 ms 4948 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 2 ms 4948 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 3 ms 4948 KB Output is correct
40 Correct 4 ms 4948 KB Output is correct
41 Correct 4 ms 4948 KB Output is correct
42 Correct 4 ms 5032 KB Output is correct
43 Correct 4 ms 4948 KB Output is correct
44 Correct 4 ms 4948 KB Output is correct
45 Correct 3 ms 4948 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 4 ms 4948 KB Output is correct
50 Correct 4 ms 5004 KB Output is correct
51 Correct 3 ms 4948 KB Output is correct
52 Correct 4 ms 4948 KB Output is correct
53 Correct 3 ms 4948 KB Output is correct
54 Correct 3 ms 4948 KB Output is correct
55 Correct 4 ms 4948 KB Output is correct
56 Correct 4 ms 4948 KB Output is correct
57 Correct 4 ms 4948 KB Output is correct
58 Correct 2 ms 4948 KB Output is correct
59 Correct 3 ms 4948 KB Output is correct
60 Correct 3 ms 4948 KB Output is correct
61 Correct 4 ms 5040 KB Output is correct
62 Correct 3 ms 4948 KB Output is correct
63 Correct 3 ms 4968 KB Output is correct
64 Correct 3 ms 4948 KB Output is correct
65 Correct 3 ms 4948 KB Output is correct
66 Correct 3 ms 5076 KB Output is correct
67 Correct 3 ms 5076 KB Output is correct
68 Correct 4 ms 5088 KB Output is correct
69 Correct 3 ms 5076 KB Output is correct
70 Correct 3 ms 5200 KB Output is correct
71 Correct 3 ms 5076 KB Output is correct
72 Correct 3 ms 5076 KB Output is correct
73 Correct 3 ms 5076 KB Output is correct
74 Correct 4 ms 5076 KB Output is correct
75 Correct 3 ms 5076 KB Output is correct
76 Correct 3 ms 4948 KB Output is correct
77 Correct 5 ms 5096 KB Output is correct
78 Correct 3 ms 5076 KB Output is correct
79 Correct 4 ms 5124 KB Output is correct
80 Correct 3 ms 5076 KB Output is correct
81 Correct 3 ms 5076 KB Output is correct
82 Correct 3 ms 5076 KB Output is correct
83 Correct 4 ms 5076 KB Output is correct
84 Correct 4 ms 5048 KB Output is correct
85 Correct 3 ms 5076 KB Output is correct
86 Correct 3 ms 5076 KB Output is correct
87 Correct 3 ms 5076 KB Output is correct
88 Correct 3 ms 5076 KB Output is correct
89 Correct 3 ms 5076 KB Output is correct
90 Correct 3 ms 5016 KB Output is correct
91 Correct 3 ms 5076 KB Output is correct
92 Correct 3 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 4 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 4 ms 4964 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 4 ms 5012 KB Output is correct
29 Correct 4 ms 4948 KB Output is correct
30 Correct 3 ms 4948 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 3 ms 4948 KB Output is correct
34 Correct 4 ms 4948 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 2 ms 4948 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 3 ms 4948 KB Output is correct
40 Correct 4 ms 4948 KB Output is correct
41 Correct 4 ms 4948 KB Output is correct
42 Correct 4 ms 5032 KB Output is correct
43 Correct 4 ms 4948 KB Output is correct
44 Correct 4 ms 4948 KB Output is correct
45 Correct 3 ms 4948 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 4 ms 4948 KB Output is correct
50 Correct 4 ms 5004 KB Output is correct
51 Correct 3 ms 4948 KB Output is correct
52 Correct 4 ms 4948 KB Output is correct
53 Correct 3 ms 4948 KB Output is correct
54 Correct 3 ms 4948 KB Output is correct
55 Correct 4 ms 4948 KB Output is correct
56 Correct 4 ms 4948 KB Output is correct
57 Correct 4 ms 4948 KB Output is correct
58 Correct 2 ms 4948 KB Output is correct
59 Correct 3 ms 4948 KB Output is correct
60 Correct 3 ms 4948 KB Output is correct
61 Correct 4 ms 5040 KB Output is correct
62 Correct 3 ms 4948 KB Output is correct
63 Correct 3 ms 4968 KB Output is correct
64 Correct 3 ms 4948 KB Output is correct
65 Correct 3 ms 4948 KB Output is correct
66 Runtime error 98 ms 40304 KB Execution killed with signal 11
67 Halted 0 ms 0 KB -