Submission #260898

# Submission time Handle Problem Language Result Execution time Memory
260898 2020-08-11T07:16:45 Z emanIaicepsa Duathlon (APIO18_duathlon) C++14
36 / 100
1000 ms 23572 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll,ll>
#define vi vector<int>
#define pb emplace_back
#define fi first
#define se second
#define all(n) (n).begin(),(n).end()
#define mem(n,m) memset(n,m,sizeof(n))
#define IOS ios::sync_with_stdio(0), cin.tie(0)
#define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__);
template<typename A> void _do(A x){cerr<<x<<'\n';}
template<typename A,typename ...B> void _do(A x,B ...y){cerr<<x<<", ";_do(y...);}

ll n,m;
vi E[100005];
ll siz[100005], ans=0;
bool vis[100005];

int pa[100005][18], dep[100005];

ll C(ll x){
    return (x)*(x-1)*(x-2)/6*2;
}

ll P(ll x){
    return C(x)*3;
}

vector<pii> circ;

void dfs(int x,int p){
    vis[x] = 1;
    siz[x] = 1;
    dep[x] = dep[p] + 1;
    pa[x][0] = p;
    for(int i=1;i<=__lg(n);i++){
        pa[x][i] = pa[ pa[x][i-1] ][i-1];
    }
    for(auto i:E[x]){
        if(i==p) continue;
        else if(vis[i]){
            if(x<i)circ.pb(x,i);
        }
        else{
            dfs(i,x);
            siz[x] += siz[i];
        }
    }
}

void dfs2(int x,int p,int anc){
    vis[x] = 1;
    for(auto i:E[x]){
        if(vis[i]) continue;
        dfs2(i,x,anc);
        ans += siz[i] * (siz[anc]-siz[i]-1);
    }
    ans += (siz[x]-1) * (siz[anc]-siz[x]);
}

int dis(int x,int y){
    ll ans = 0;
    if(dep[x]<dep[y]) swap(x,y);
    for(int i=__lg(n),le=dep[x]-dep[y];i>=0;i--){
        if(le>=(1<<i)){
            le -= 1<<i;
            ans += 1<<i;
            x = pa[x][i];
        }
    }
    if(x==y) return ans;
    for(int i=__lg(n);i>=0;i--){
        if(pa[x][i] != pa[y][i]){
            x = pa[x][i];
            y = pa[y][i];
            ans += (1<<i)*2;
        }
    }
    return ans+2;
}

ll ok[55];
void DFS(int x,int y){
    if(x==y){
        for(int i=1;i<=n;i++) if(vis[i]) ok[i] = 1;
        return;
    }
    vis[x] = 1;
    for(auto i:E[x]){
        if(!vis[i])DFS(i,y);
    }
    vis[x] = 0;
}

void brute(int x,int y){
    for(int i=1;i<=n;i++) vis[i] = 0, ok[i] = 0;
    DFS(x,y);
    //dbg(x, y);
    for(int i=1;i<=n;i++) if(ok[i]&&i!=x&&i!=y) ans++;
    cout<<'\n';
}


signed main(){
	IOS;
    cin>>n>>m;
    for(int i=1,a,b;i<=m;i++){
        cin>>a>>b;
        E[a].pb(b);
        E[b].pb(a);
    }

    if(n<=50){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                if(i==j) continue;
                brute(i,j);
            }
        }
        cout<<ans<<'\n';
        return 0;
    }


    for(int i=1;i<=n;i++) if(!vis[i]) dfs(i,0);
    mem(vis,0);
    for(int i=1;i<=n;i++) if(!vis[i]) dfs2(i,0,i);

    for(auto i:circ){
        int d = dis(i.fi,i.se) + 1;
        ans -= C(d);
        ans += P(d);
    }

    cout<<ans<<'\n';

}
/*
3 3
1 2
2 3
3 1
*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 3 ms 2688 KB Output is correct
9 Correct 35 ms 2688 KB Output is correct
10 Correct 541 ms 2688 KB Output is correct
11 Correct 2 ms 2688 KB Output is correct
12 Correct 2 ms 2688 KB Output is correct
13 Correct 2 ms 2688 KB Output is correct
14 Correct 2 ms 2688 KB Output is correct
15 Correct 3 ms 2688 KB Output is correct
16 Correct 3 ms 2688 KB Output is correct
17 Correct 2 ms 2688 KB Output is correct
18 Correct 2 ms 2688 KB Output is correct
19 Correct 2 ms 2688 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 2 ms 2688 KB Output is correct
22 Correct 2 ms 2688 KB Output is correct
23 Correct 3 ms 2688 KB Output is correct
24 Correct 2 ms 2688 KB Output is correct
25 Correct 2 ms 2688 KB Output is correct
26 Correct 3 ms 2688 KB Output is correct
27 Correct 3 ms 2688 KB Output is correct
28 Correct 2 ms 2688 KB Output is correct
29 Correct 2 ms 2688 KB Output is correct
30 Correct 2 ms 2688 KB Output is correct
31 Correct 2 ms 2688 KB Output is correct
32 Correct 2 ms 2688 KB Output is correct
33 Correct 2 ms 2688 KB Output is correct
34 Correct 2 ms 2688 KB Output is correct
35 Correct 2 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 3 ms 2688 KB Output is correct
9 Correct 35 ms 2688 KB Output is correct
10 Correct 541 ms 2688 KB Output is correct
11 Correct 2 ms 2688 KB Output is correct
12 Correct 2 ms 2688 KB Output is correct
13 Correct 2 ms 2688 KB Output is correct
14 Correct 2 ms 2688 KB Output is correct
15 Correct 3 ms 2688 KB Output is correct
16 Correct 3 ms 2688 KB Output is correct
17 Correct 2 ms 2688 KB Output is correct
18 Correct 2 ms 2688 KB Output is correct
19 Correct 2 ms 2688 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 2 ms 2688 KB Output is correct
22 Correct 2 ms 2688 KB Output is correct
23 Correct 3 ms 2688 KB Output is correct
24 Correct 2 ms 2688 KB Output is correct
25 Correct 2 ms 2688 KB Output is correct
26 Correct 3 ms 2688 KB Output is correct
27 Correct 3 ms 2688 KB Output is correct
28 Correct 2 ms 2688 KB Output is correct
29 Correct 2 ms 2688 KB Output is correct
30 Correct 2 ms 2688 KB Output is correct
31 Correct 2 ms 2688 KB Output is correct
32 Correct 2 ms 2688 KB Output is correct
33 Correct 2 ms 2688 KB Output is correct
34 Correct 2 ms 2688 KB Output is correct
35 Correct 2 ms 2688 KB Output is correct
36 Correct 2 ms 2688 KB Output is correct
37 Correct 3 ms 2688 KB Output is correct
38 Correct 46 ms 2688 KB Output is correct
39 Execution timed out 1085 ms 2808 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 148 ms 23464 KB Output is correct
2 Correct 144 ms 23572 KB Output is correct
3 Correct 122 ms 18808 KB Output is correct
4 Correct 161 ms 21188 KB Output is correct
5 Correct 134 ms 17272 KB Output is correct
6 Correct 139 ms 17292 KB Output is correct
7 Correct 134 ms 16060 KB Output is correct
8 Correct 136 ms 16760 KB Output is correct
9 Correct 135 ms 15300 KB Output is correct
10 Correct 117 ms 15864 KB Output is correct
11 Correct 100 ms 14584 KB Output is correct
12 Correct 89 ms 14328 KB Output is correct
13 Correct 92 ms 14456 KB Output is correct
14 Correct 95 ms 14200 KB Output is correct
15 Correct 66 ms 13816 KB Output is correct
16 Correct 68 ms 13688 KB Output is correct
17 Correct 16 ms 11008 KB Output is correct
18 Correct 16 ms 11008 KB Output is correct
19 Correct 15 ms 11008 KB Output is correct
20 Correct 16 ms 11008 KB Output is correct
21 Correct 16 ms 11008 KB Output is correct
22 Correct 15 ms 11008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2944 KB Output is correct
2 Correct 3 ms 2944 KB Output is correct
3 Correct 3 ms 2944 KB Output is correct
4 Correct 2 ms 2944 KB Output is correct
5 Correct 3 ms 2944 KB Output is correct
6 Correct 3 ms 2944 KB Output is correct
7 Correct 3 ms 2944 KB Output is correct
8 Correct 3 ms 2944 KB Output is correct
9 Correct 3 ms 2944 KB Output is correct
10 Correct 3 ms 2944 KB Output is correct
11 Correct 2 ms 2944 KB Output is correct
12 Correct 3 ms 2944 KB Output is correct
13 Correct 3 ms 2944 KB Output is correct
14 Correct 3 ms 2944 KB Output is correct
15 Correct 2 ms 2944 KB Output is correct
16 Correct 3 ms 2944 KB Output is correct
17 Correct 2 ms 2944 KB Output is correct
18 Correct 3 ms 2944 KB Output is correct
19 Correct 3 ms 2944 KB Output is correct
20 Correct 2 ms 2944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 14328 KB Output is correct
2 Correct 112 ms 14332 KB Output is correct
3 Correct 97 ms 14200 KB Output is correct
4 Correct 111 ms 14200 KB Output is correct
5 Correct 111 ms 14200 KB Output is correct
6 Correct 143 ms 19320 KB Output is correct
7 Correct 127 ms 17592 KB Output is correct
8 Correct 139 ms 16760 KB Output is correct
9 Correct 127 ms 15864 KB Output is correct
10 Correct 109 ms 14204 KB Output is correct
11 Correct 105 ms 14200 KB Output is correct
12 Correct 114 ms 14424 KB Output is correct
13 Correct 116 ms 14296 KB Output is correct
14 Correct 101 ms 14200 KB Output is correct
15 Correct 88 ms 14072 KB Output is correct
16 Correct 56 ms 13304 KB Output is correct
17 Correct 71 ms 14576 KB Output is correct
18 Correct 78 ms 14576 KB Output is correct
19 Correct 66 ms 14572 KB Output is correct
20 Correct 78 ms 14716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2944 KB Output is correct
2 Correct 4 ms 2944 KB Output is correct
3 Incorrect 3 ms 2944 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 106 ms 14200 KB Output is correct
2 Correct 115 ms 14248 KB Output is correct
3 Incorrect 131 ms 14840 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 3 ms 2688 KB Output is correct
9 Correct 35 ms 2688 KB Output is correct
10 Correct 541 ms 2688 KB Output is correct
11 Correct 2 ms 2688 KB Output is correct
12 Correct 2 ms 2688 KB Output is correct
13 Correct 2 ms 2688 KB Output is correct
14 Correct 2 ms 2688 KB Output is correct
15 Correct 3 ms 2688 KB Output is correct
16 Correct 3 ms 2688 KB Output is correct
17 Correct 2 ms 2688 KB Output is correct
18 Correct 2 ms 2688 KB Output is correct
19 Correct 2 ms 2688 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 2 ms 2688 KB Output is correct
22 Correct 2 ms 2688 KB Output is correct
23 Correct 3 ms 2688 KB Output is correct
24 Correct 2 ms 2688 KB Output is correct
25 Correct 2 ms 2688 KB Output is correct
26 Correct 3 ms 2688 KB Output is correct
27 Correct 3 ms 2688 KB Output is correct
28 Correct 2 ms 2688 KB Output is correct
29 Correct 2 ms 2688 KB Output is correct
30 Correct 2 ms 2688 KB Output is correct
31 Correct 2 ms 2688 KB Output is correct
32 Correct 2 ms 2688 KB Output is correct
33 Correct 2 ms 2688 KB Output is correct
34 Correct 2 ms 2688 KB Output is correct
35 Correct 2 ms 2688 KB Output is correct
36 Correct 2 ms 2688 KB Output is correct
37 Correct 3 ms 2688 KB Output is correct
38 Correct 46 ms 2688 KB Output is correct
39 Execution timed out 1085 ms 2808 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 3 ms 2688 KB Output is correct
9 Correct 35 ms 2688 KB Output is correct
10 Correct 541 ms 2688 KB Output is correct
11 Correct 2 ms 2688 KB Output is correct
12 Correct 2 ms 2688 KB Output is correct
13 Correct 2 ms 2688 KB Output is correct
14 Correct 2 ms 2688 KB Output is correct
15 Correct 3 ms 2688 KB Output is correct
16 Correct 3 ms 2688 KB Output is correct
17 Correct 2 ms 2688 KB Output is correct
18 Correct 2 ms 2688 KB Output is correct
19 Correct 2 ms 2688 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 2 ms 2688 KB Output is correct
22 Correct 2 ms 2688 KB Output is correct
23 Correct 3 ms 2688 KB Output is correct
24 Correct 2 ms 2688 KB Output is correct
25 Correct 2 ms 2688 KB Output is correct
26 Correct 3 ms 2688 KB Output is correct
27 Correct 3 ms 2688 KB Output is correct
28 Correct 2 ms 2688 KB Output is correct
29 Correct 2 ms 2688 KB Output is correct
30 Correct 2 ms 2688 KB Output is correct
31 Correct 2 ms 2688 KB Output is correct
32 Correct 2 ms 2688 KB Output is correct
33 Correct 2 ms 2688 KB Output is correct
34 Correct 2 ms 2688 KB Output is correct
35 Correct 2 ms 2688 KB Output is correct
36 Correct 2 ms 2688 KB Output is correct
37 Correct 3 ms 2688 KB Output is correct
38 Correct 46 ms 2688 KB Output is correct
39 Execution timed out 1085 ms 2808 KB Time limit exceeded
40 Halted 0 ms 0 KB -