Submission #737052

# Submission time Handle Problem Language Result Execution time Memory
737052 2023-05-06T14:00:26 Z onlk97 Duathlon (APIO18_duathlon) C++14
49 / 100
152 ms 29852 KB
#include <bits/stdc++.h>
using namespace std;
long long n,m;
vector <int> g[100010],bc[200010];
bool visited[200010];
long long dfn[100010],lo[100010],w[200020],sz[200020],occ[200020];
int dsu[200020],siz[200020];
int prt(int n){
    if (dsu[n]==n) return n;
    return dsu[n]=prt(dsu[n]);
}
void unn(int u,int v){
    u=prt(u); v=prt(v);
    if (u==v) return;
    if (siz[u]<siz[v]) swap(u,v);
    dsu[v]=dsu[u];
    siz[u]+=siz[v];
}
stack <int> st;
int tme,curid;
void dfs(int cur){
    tme++;
    dfn[cur]=lo[cur]=tme;
    visited[cur]=1;
    st.push(cur);
    for (int i:g[cur]){
        if (!visited[i]){
            dfs(i);
            lo[cur]=min(lo[cur],lo[i]);
            if (lo[i]==dfn[cur]){
                curid++;
                bool ok=1;
                while (ok){
                    bc[st.top()].push_back(curid);
                    bc[curid].push_back(st.top());
                    w[curid]++;
                    if (st.top()==i) ok=0;
                    st.pop();
                }
                bc[cur].push_back(curid);
                bc[curid].push_back(cur);
                w[curid]++;
            }
        } else lo[cur]=min(lo[cur],dfn[i]);
    }
}
int S;
void dfs2(int cur,int prv){
    visited[cur]=1;
    sz[cur]=(cur<=n);
    long long rem=S-(cur<=n);
    occ[cur]=S*(S-1)/2;
    for (int i:bc[cur]){
        if (i==prv) continue;
        dfs2(i,cur);
        sz[cur]+=sz[i];
        occ[cur]-=sz[i]*(sz[i]-1)/2;
        rem-=sz[i];
    }
    occ[cur]-=rem*(rem-1)/2;
}
signed main(){
    cin>>n>>m;
    for (int i=1; i<=2*n; i++){
        dsu[i]=i; siz[i]=(i<=n);
    }
    for (int i=0; i<m; i++){
        int u,v; cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
        unn(u,v);
    }
    curid=n;
    for (int i=1; i<=n; i++){
        if (!visited[i]) dfs(i);
    }
    for (int i=1; i<=curid; i++) visited[i]=0;
    for (int i=1; i<=n; i++) w[i]=-1;
    for (int i=1; i<=curid; i++){
        if (!visited[i]){
            S=siz[prt(i)];
            dfs2(i,0);
        }
    }
    long long ans=0;
    for (int i=1; i<=curid; i++) ans+=w[i]*occ[i];
    cout<<ans*2<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7356 KB Output is correct
4 Correct 5 ms 7380 KB Output is correct
5 Correct 4 ms 7356 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 5 ms 7352 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 5 ms 7400 KB Output is correct
10 Correct 4 ms 7424 KB Output is correct
11 Correct 5 ms 7380 KB Output is correct
12 Correct 4 ms 7352 KB Output is correct
13 Correct 4 ms 7360 KB Output is correct
14 Correct 6 ms 7380 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 4 ms 7356 KB Output is correct
17 Correct 4 ms 7296 KB Output is correct
18 Correct 4 ms 7356 KB Output is correct
19 Correct 4 ms 7360 KB Output is correct
20 Correct 4 ms 7380 KB Output is correct
21 Correct 4 ms 7380 KB Output is correct
22 Correct 4 ms 7380 KB Output is correct
23 Correct 4 ms 7380 KB Output is correct
24 Correct 6 ms 7356 KB Output is correct
25 Correct 4 ms 7380 KB Output is correct
26 Correct 4 ms 7380 KB Output is correct
27 Correct 5 ms 7528 KB Output is correct
28 Correct 6 ms 7380 KB Output is correct
29 Correct 4 ms 7380 KB Output is correct
30 Correct 4 ms 7380 KB Output is correct
31 Correct 4 ms 7380 KB Output is correct
32 Correct 4 ms 7380 KB Output is correct
33 Correct 4 ms 7356 KB Output is correct
34 Correct 4 ms 7356 KB Output is correct
35 Correct 6 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7356 KB Output is correct
4 Correct 5 ms 7380 KB Output is correct
5 Correct 4 ms 7356 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 5 ms 7352 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 5 ms 7400 KB Output is correct
10 Correct 4 ms 7424 KB Output is correct
11 Correct 5 ms 7380 KB Output is correct
12 Correct 4 ms 7352 KB Output is correct
13 Correct 4 ms 7360 KB Output is correct
14 Correct 6 ms 7380 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 4 ms 7356 KB Output is correct
17 Correct 4 ms 7296 KB Output is correct
18 Correct 4 ms 7356 KB Output is correct
19 Correct 4 ms 7360 KB Output is correct
20 Correct 4 ms 7380 KB Output is correct
21 Correct 4 ms 7380 KB Output is correct
22 Correct 4 ms 7380 KB Output is correct
23 Correct 4 ms 7380 KB Output is correct
24 Correct 6 ms 7356 KB Output is correct
25 Correct 4 ms 7380 KB Output is correct
26 Correct 4 ms 7380 KB Output is correct
27 Correct 5 ms 7528 KB Output is correct
28 Correct 6 ms 7380 KB Output is correct
29 Correct 4 ms 7380 KB Output is correct
30 Correct 4 ms 7380 KB Output is correct
31 Correct 4 ms 7380 KB Output is correct
32 Correct 4 ms 7380 KB Output is correct
33 Correct 4 ms 7356 KB Output is correct
34 Correct 4 ms 7356 KB Output is correct
35 Correct 6 ms 7380 KB Output is correct
36 Correct 4 ms 7380 KB Output is correct
37 Correct 5 ms 7356 KB Output is correct
38 Correct 5 ms 7380 KB Output is correct
39 Correct 4 ms 7380 KB Output is correct
40 Correct 5 ms 7356 KB Output is correct
41 Correct 5 ms 7380 KB Output is correct
42 Correct 5 ms 7356 KB Output is correct
43 Correct 4 ms 7352 KB Output is correct
44 Correct 5 ms 7380 KB Output is correct
45 Correct 4 ms 7380 KB Output is correct
46 Correct 4 ms 7380 KB Output is correct
47 Correct 6 ms 7356 KB Output is correct
48 Correct 6 ms 7380 KB Output is correct
49 Correct 4 ms 7356 KB Output is correct
50 Correct 5 ms 7380 KB Output is correct
51 Correct 5 ms 7380 KB Output is correct
52 Correct 5 ms 7380 KB Output is correct
53 Correct 5 ms 7380 KB Output is correct
54 Correct 4 ms 7380 KB Output is correct
55 Correct 4 ms 7356 KB Output is correct
56 Correct 4 ms 7352 KB Output is correct
57 Correct 4 ms 7380 KB Output is correct
58 Correct 4 ms 7380 KB Output is correct
59 Correct 4 ms 7424 KB Output is correct
60 Correct 4 ms 7380 KB Output is correct
61 Correct 5 ms 7380 KB Output is correct
62 Correct 5 ms 7356 KB Output is correct
63 Correct 4 ms 7356 KB Output is correct
64 Correct 4 ms 7380 KB Output is correct
65 Correct 4 ms 7356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 132 ms 27876 KB Output is correct
2 Correct 129 ms 28588 KB Output is correct
3 Incorrect 146 ms 29852 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7508 KB Output is correct
2 Correct 5 ms 7508 KB Output is correct
3 Correct 5 ms 7508 KB Output is correct
4 Correct 5 ms 7620 KB Output is correct
5 Correct 6 ms 7612 KB Output is correct
6 Correct 5 ms 7636 KB Output is correct
7 Correct 5 ms 7636 KB Output is correct
8 Correct 6 ms 7508 KB Output is correct
9 Correct 7 ms 7508 KB Output is correct
10 Correct 6 ms 7508 KB Output is correct
11 Correct 5 ms 7492 KB Output is correct
12 Correct 5 ms 7496 KB Output is correct
13 Correct 5 ms 7508 KB Output is correct
14 Correct 5 ms 7508 KB Output is correct
15 Correct 4 ms 7508 KB Output is correct
16 Correct 5 ms 7508 KB Output is correct
17 Correct 5 ms 7488 KB Output is correct
18 Correct 6 ms 7488 KB Output is correct
19 Correct 5 ms 7508 KB Output is correct
20 Correct 5 ms 7508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 137 ms 25432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7492 KB Output is correct
2 Correct 5 ms 7488 KB Output is correct
3 Correct 6 ms 7508 KB Output is correct
4 Correct 5 ms 7508 KB Output is correct
5 Correct 5 ms 7484 KB Output is correct
6 Correct 5 ms 7492 KB Output is correct
7 Correct 5 ms 7508 KB Output is correct
8 Correct 5 ms 7508 KB Output is correct
9 Correct 5 ms 7508 KB Output is correct
10 Correct 6 ms 7508 KB Output is correct
11 Correct 5 ms 7508 KB Output is correct
12 Correct 6 ms 7620 KB Output is correct
13 Correct 5 ms 7508 KB Output is correct
14 Correct 5 ms 7508 KB Output is correct
15 Correct 5 ms 7528 KB Output is correct
16 Correct 5 ms 7488 KB Output is correct
17 Correct 5 ms 7484 KB Output is correct
18 Correct 5 ms 7508 KB Output is correct
19 Correct 6 ms 7492 KB Output is correct
20 Correct 5 ms 7508 KB Output is correct
21 Correct 5 ms 7508 KB Output is correct
22 Correct 5 ms 7508 KB Output is correct
23 Correct 5 ms 7484 KB Output is correct
24 Correct 6 ms 7508 KB Output is correct
25 Correct 6 ms 7380 KB Output is correct
26 Correct 4 ms 7380 KB Output is correct
27 Correct 4 ms 7360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 152 ms 25500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7356 KB Output is correct
4 Correct 5 ms 7380 KB Output is correct
5 Correct 4 ms 7356 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 5 ms 7352 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 5 ms 7400 KB Output is correct
10 Correct 4 ms 7424 KB Output is correct
11 Correct 5 ms 7380 KB Output is correct
12 Correct 4 ms 7352 KB Output is correct
13 Correct 4 ms 7360 KB Output is correct
14 Correct 6 ms 7380 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 4 ms 7356 KB Output is correct
17 Correct 4 ms 7296 KB Output is correct
18 Correct 4 ms 7356 KB Output is correct
19 Correct 4 ms 7360 KB Output is correct
20 Correct 4 ms 7380 KB Output is correct
21 Correct 4 ms 7380 KB Output is correct
22 Correct 4 ms 7380 KB Output is correct
23 Correct 4 ms 7380 KB Output is correct
24 Correct 6 ms 7356 KB Output is correct
25 Correct 4 ms 7380 KB Output is correct
26 Correct 4 ms 7380 KB Output is correct
27 Correct 5 ms 7528 KB Output is correct
28 Correct 6 ms 7380 KB Output is correct
29 Correct 4 ms 7380 KB Output is correct
30 Correct 4 ms 7380 KB Output is correct
31 Correct 4 ms 7380 KB Output is correct
32 Correct 4 ms 7380 KB Output is correct
33 Correct 4 ms 7356 KB Output is correct
34 Correct 4 ms 7356 KB Output is correct
35 Correct 6 ms 7380 KB Output is correct
36 Correct 4 ms 7380 KB Output is correct
37 Correct 5 ms 7356 KB Output is correct
38 Correct 5 ms 7380 KB Output is correct
39 Correct 4 ms 7380 KB Output is correct
40 Correct 5 ms 7356 KB Output is correct
41 Correct 5 ms 7380 KB Output is correct
42 Correct 5 ms 7356 KB Output is correct
43 Correct 4 ms 7352 KB Output is correct
44 Correct 5 ms 7380 KB Output is correct
45 Correct 4 ms 7380 KB Output is correct
46 Correct 4 ms 7380 KB Output is correct
47 Correct 6 ms 7356 KB Output is correct
48 Correct 6 ms 7380 KB Output is correct
49 Correct 4 ms 7356 KB Output is correct
50 Correct 5 ms 7380 KB Output is correct
51 Correct 5 ms 7380 KB Output is correct
52 Correct 5 ms 7380 KB Output is correct
53 Correct 5 ms 7380 KB Output is correct
54 Correct 4 ms 7380 KB Output is correct
55 Correct 4 ms 7356 KB Output is correct
56 Correct 4 ms 7352 KB Output is correct
57 Correct 4 ms 7380 KB Output is correct
58 Correct 4 ms 7380 KB Output is correct
59 Correct 4 ms 7424 KB Output is correct
60 Correct 4 ms 7380 KB Output is correct
61 Correct 5 ms 7380 KB Output is correct
62 Correct 5 ms 7356 KB Output is correct
63 Correct 4 ms 7356 KB Output is correct
64 Correct 4 ms 7380 KB Output is correct
65 Correct 4 ms 7356 KB Output is correct
66 Correct 4 ms 7380 KB Output is correct
67 Correct 4 ms 7488 KB Output is correct
68 Correct 4 ms 7508 KB Output is correct
69 Correct 6 ms 7508 KB Output is correct
70 Correct 6 ms 7496 KB Output is correct
71 Correct 5 ms 7508 KB Output is correct
72 Correct 5 ms 7508 KB Output is correct
73 Correct 5 ms 7504 KB Output is correct
74 Correct 5 ms 7508 KB Output is correct
75 Correct 5 ms 7508 KB Output is correct
76 Correct 4 ms 7380 KB Output is correct
77 Correct 5 ms 7508 KB Output is correct
78 Correct 5 ms 7508 KB Output is correct
79 Correct 5 ms 7440 KB Output is correct
80 Correct 6 ms 7508 KB Output is correct
81 Correct 5 ms 7508 KB Output is correct
82 Correct 5 ms 7508 KB Output is correct
83 Correct 7 ms 7508 KB Output is correct
84 Correct 5 ms 7488 KB Output is correct
85 Correct 5 ms 7508 KB Output is correct
86 Correct 5 ms 7508 KB Output is correct
87 Correct 6 ms 7508 KB Output is correct
88 Correct 5 ms 7492 KB Output is correct
89 Correct 5 ms 7528 KB Output is correct
90 Correct 5 ms 7508 KB Output is correct
91 Correct 5 ms 7508 KB Output is correct
92 Correct 6 ms 7508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7356 KB Output is correct
4 Correct 5 ms 7380 KB Output is correct
5 Correct 4 ms 7356 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 5 ms 7352 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 5 ms 7400 KB Output is correct
10 Correct 4 ms 7424 KB Output is correct
11 Correct 5 ms 7380 KB Output is correct
12 Correct 4 ms 7352 KB Output is correct
13 Correct 4 ms 7360 KB Output is correct
14 Correct 6 ms 7380 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 4 ms 7356 KB Output is correct
17 Correct 4 ms 7296 KB Output is correct
18 Correct 4 ms 7356 KB Output is correct
19 Correct 4 ms 7360 KB Output is correct
20 Correct 4 ms 7380 KB Output is correct
21 Correct 4 ms 7380 KB Output is correct
22 Correct 4 ms 7380 KB Output is correct
23 Correct 4 ms 7380 KB Output is correct
24 Correct 6 ms 7356 KB Output is correct
25 Correct 4 ms 7380 KB Output is correct
26 Correct 4 ms 7380 KB Output is correct
27 Correct 5 ms 7528 KB Output is correct
28 Correct 6 ms 7380 KB Output is correct
29 Correct 4 ms 7380 KB Output is correct
30 Correct 4 ms 7380 KB Output is correct
31 Correct 4 ms 7380 KB Output is correct
32 Correct 4 ms 7380 KB Output is correct
33 Correct 4 ms 7356 KB Output is correct
34 Correct 4 ms 7356 KB Output is correct
35 Correct 6 ms 7380 KB Output is correct
36 Correct 4 ms 7380 KB Output is correct
37 Correct 5 ms 7356 KB Output is correct
38 Correct 5 ms 7380 KB Output is correct
39 Correct 4 ms 7380 KB Output is correct
40 Correct 5 ms 7356 KB Output is correct
41 Correct 5 ms 7380 KB Output is correct
42 Correct 5 ms 7356 KB Output is correct
43 Correct 4 ms 7352 KB Output is correct
44 Correct 5 ms 7380 KB Output is correct
45 Correct 4 ms 7380 KB Output is correct
46 Correct 4 ms 7380 KB Output is correct
47 Correct 6 ms 7356 KB Output is correct
48 Correct 6 ms 7380 KB Output is correct
49 Correct 4 ms 7356 KB Output is correct
50 Correct 5 ms 7380 KB Output is correct
51 Correct 5 ms 7380 KB Output is correct
52 Correct 5 ms 7380 KB Output is correct
53 Correct 5 ms 7380 KB Output is correct
54 Correct 4 ms 7380 KB Output is correct
55 Correct 4 ms 7356 KB Output is correct
56 Correct 4 ms 7352 KB Output is correct
57 Correct 4 ms 7380 KB Output is correct
58 Correct 4 ms 7380 KB Output is correct
59 Correct 4 ms 7424 KB Output is correct
60 Correct 4 ms 7380 KB Output is correct
61 Correct 5 ms 7380 KB Output is correct
62 Correct 5 ms 7356 KB Output is correct
63 Correct 4 ms 7356 KB Output is correct
64 Correct 4 ms 7380 KB Output is correct
65 Correct 4 ms 7356 KB Output is correct
66 Correct 132 ms 27876 KB Output is correct
67 Correct 129 ms 28588 KB Output is correct
68 Incorrect 146 ms 29852 KB Output isn't correct
69 Halted 0 ms 0 KB -