답안 #993987

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
993987 2024-06-07T00:48:19 Z vjudge1 철인 이종 경기 (APIO18_duathlon) C++17
57 / 100
87 ms 46036 KB
#include<bits/stdc++.h>
using namespace std;
#define N 1<<18
int dep[N],id[N],low[N],CC,CC2,in[N],par[N],nod1,nod2,sz[N];
long long ans;
struct unionfind{
    int par[N];
    int abp(int n){
        return(par[n]==n?n:par[n]=abp(par[n]));
    }
    void init(){
        for(int i=0;i<N;i++)
            par[i]=i;
    }
    void merge(int a,int b){
        a=abp(a),b=abp(b);
        if(a-b)par[a]=b;
    }
} CYCLE;
set<pair<int,int>>st[100100];
vector<int>adj1[N],adj2[N];
void tarjan(int n,int p){
    nod1++;
    low[n]=id[n]=++CC2;
    for(auto i:adj1[n]){
        if(i==p)continue;
        if(!id[i]){
            dep[i]=dep[n]+1;
            tarjan(i,n);
            low[n]=min(low[n],low[i]);
            if(low[i]>id[n])
                adj2[n].push_back(i);
        } else if(dep[i]<dep[n])
            st[n].insert({dep[i],++CC}),
            low[n]=min(low[n],low[i]);
    }
}
void dfscyc(int n){
    for(auto i:adj1[n]){
        if(dep[i]-dep[n]-1)
            continue;
        dfscyc(i);
        if(st[i].size()&&st[i].begin()->first<dep[n]){
            if(st[n].size()) CYCLE.merge(st[i].begin()
                        ->second,st[n].begin()->second);
            st[n].insert(*st[i].begin());
        }
    }
    if(st[n].size())
        in[n]=st[n].begin()->second;
}
void dfs2(int n,int p){
    for(auto i:adj1[n])
        if(dep[i]==dep[n]+1)
            dfs2(i,n);
    adj2[CYCLE.abp(in[n])].push_back(n);
    par[CYCLE.abp(in[n])]=p;
}
void dfs3(int n){
    long long sum=0;
    for(auto i:adj2[n]){
        dfs3(i);
        sum+=sz[n]*sz[i];
        sz[n]+=sz[i];
    }
    int x=sz[n];
    sz[n]+=n<=nod2;
    sum+=(nod1-sz[n])*x;
    ans+=(n>nod2?adj2[n].size()-1:1)*sum*2;
}
int main(){
    cin.tie(0)->sync_with_stdio(0);
    CYCLE.init();
    int n,m;
    cin>>n>>m;
    CC=nod2=n;
    while(m--){
        int a,b;
        cin>>a>>b;
        adj1[a].push_back(b);
        adj1[b].push_back(a);
    }
    for(int i=1;i<=n;i++)
        if(!id[i]){
            nod1=0;
            int prv=CC;
            tarjan(i,0),
            dfscyc(i),dfs2(i,0);
            for(int j=prv;j++<CC;)
                if(CYCLE.par[j]==j)
                    adj2[par[j]].push_back(j);
            dfs3(i);
        }
    cout<<ans<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 23132 KB Output is correct
2 Correct 4 ms 23132 KB Output is correct
3 Correct 4 ms 23132 KB Output is correct
4 Correct 4 ms 23208 KB Output is correct
5 Correct 4 ms 23132 KB Output is correct
6 Correct 4 ms 23132 KB Output is correct
7 Correct 4 ms 23200 KB Output is correct
8 Correct 4 ms 23132 KB Output is correct
9 Correct 3 ms 23132 KB Output is correct
10 Correct 3 ms 22976 KB Output is correct
11 Correct 4 ms 23132 KB Output is correct
12 Correct 4 ms 23132 KB Output is correct
13 Correct 4 ms 23128 KB Output is correct
14 Correct 4 ms 23132 KB Output is correct
15 Correct 4 ms 23132 KB Output is correct
16 Correct 4 ms 23132 KB Output is correct
17 Correct 3 ms 23132 KB Output is correct
18 Correct 3 ms 23192 KB Output is correct
19 Correct 4 ms 23132 KB Output is correct
20 Correct 4 ms 23128 KB Output is correct
21 Correct 3 ms 23132 KB Output is correct
22 Correct 5 ms 23208 KB Output is correct
23 Correct 4 ms 23132 KB Output is correct
24 Correct 3 ms 23128 KB Output is correct
25 Correct 4 ms 23132 KB Output is correct
26 Correct 3 ms 23160 KB Output is correct
27 Correct 4 ms 23128 KB Output is correct
28 Correct 4 ms 23132 KB Output is correct
29 Correct 3 ms 23132 KB Output is correct
30 Correct 4 ms 23132 KB Output is correct
31 Correct 5 ms 23132 KB Output is correct
32 Correct 4 ms 23132 KB Output is correct
33 Correct 4 ms 23132 KB Output is correct
34 Correct 4 ms 23132 KB Output is correct
35 Correct 5 ms 23216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 23132 KB Output is correct
2 Correct 4 ms 23132 KB Output is correct
3 Correct 4 ms 23132 KB Output is correct
4 Correct 4 ms 23208 KB Output is correct
5 Correct 4 ms 23132 KB Output is correct
6 Correct 4 ms 23132 KB Output is correct
7 Correct 4 ms 23200 KB Output is correct
8 Correct 4 ms 23132 KB Output is correct
9 Correct 3 ms 23132 KB Output is correct
10 Correct 3 ms 22976 KB Output is correct
11 Correct 4 ms 23132 KB Output is correct
12 Correct 4 ms 23132 KB Output is correct
13 Correct 4 ms 23128 KB Output is correct
14 Correct 4 ms 23132 KB Output is correct
15 Correct 4 ms 23132 KB Output is correct
16 Correct 4 ms 23132 KB Output is correct
17 Correct 3 ms 23132 KB Output is correct
18 Correct 3 ms 23192 KB Output is correct
19 Correct 4 ms 23132 KB Output is correct
20 Correct 4 ms 23128 KB Output is correct
21 Correct 3 ms 23132 KB Output is correct
22 Correct 5 ms 23208 KB Output is correct
23 Correct 4 ms 23132 KB Output is correct
24 Correct 3 ms 23128 KB Output is correct
25 Correct 4 ms 23132 KB Output is correct
26 Correct 3 ms 23160 KB Output is correct
27 Correct 4 ms 23128 KB Output is correct
28 Correct 4 ms 23132 KB Output is correct
29 Correct 3 ms 23132 KB Output is correct
30 Correct 4 ms 23132 KB Output is correct
31 Correct 5 ms 23132 KB Output is correct
32 Correct 4 ms 23132 KB Output is correct
33 Correct 4 ms 23132 KB Output is correct
34 Correct 4 ms 23132 KB Output is correct
35 Correct 5 ms 23216 KB Output is correct
36 Correct 4 ms 23132 KB Output is correct
37 Correct 4 ms 23132 KB Output is correct
38 Correct 4 ms 23132 KB Output is correct
39 Correct 4 ms 23168 KB Output is correct
40 Correct 4 ms 23128 KB Output is correct
41 Correct 4 ms 23132 KB Output is correct
42 Correct 4 ms 23132 KB Output is correct
43 Correct 4 ms 23136 KB Output is correct
44 Correct 4 ms 23132 KB Output is correct
45 Correct 5 ms 23132 KB Output is correct
46 Correct 5 ms 23132 KB Output is correct
47 Correct 5 ms 23132 KB Output is correct
48 Correct 4 ms 23164 KB Output is correct
49 Correct 5 ms 23200 KB Output is correct
50 Correct 3 ms 23128 KB Output is correct
51 Correct 4 ms 23196 KB Output is correct
52 Correct 4 ms 23128 KB Output is correct
53 Correct 4 ms 23132 KB Output is correct
54 Correct 5 ms 23132 KB Output is correct
55 Correct 4 ms 23132 KB Output is correct
56 Correct 3 ms 23128 KB Output is correct
57 Correct 3 ms 23132 KB Output is correct
58 Correct 5 ms 23200 KB Output is correct
59 Correct 4 ms 23132 KB Output is correct
60 Correct 4 ms 23132 KB Output is correct
61 Correct 4 ms 23132 KB Output is correct
62 Correct 4 ms 23204 KB Output is correct
63 Correct 5 ms 23128 KB Output is correct
64 Correct 4 ms 23132 KB Output is correct
65 Correct 4 ms 23132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 45988 KB Output is correct
2 Correct 71 ms 46036 KB Output is correct
3 Correct 62 ms 38120 KB Output is correct
4 Correct 67 ms 43504 KB Output is correct
5 Correct 71 ms 37456 KB Output is correct
6 Correct 72 ms 36736 KB Output is correct
7 Correct 58 ms 34860 KB Output is correct
8 Correct 59 ms 36052 KB Output is correct
9 Correct 59 ms 33348 KB Output is correct
10 Correct 57 ms 34848 KB Output is correct
11 Correct 45 ms 31184 KB Output is correct
12 Correct 46 ms 31180 KB Output is correct
13 Correct 34 ms 30852 KB Output is correct
14 Correct 39 ms 30724 KB Output is correct
15 Correct 39 ms 29136 KB Output is correct
16 Correct 29 ms 29144 KB Output is correct
17 Correct 6 ms 24036 KB Output is correct
18 Correct 5 ms 24072 KB Output is correct
19 Correct 7 ms 24036 KB Output is correct
20 Correct 6 ms 24036 KB Output is correct
21 Correct 6 ms 24028 KB Output is correct
22 Correct 6 ms 24028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 23132 KB Output is correct
2 Correct 4 ms 23204 KB Output is correct
3 Correct 4 ms 23132 KB Output is correct
4 Correct 4 ms 23200 KB Output is correct
5 Correct 4 ms 23132 KB Output is correct
6 Correct 4 ms 23132 KB Output is correct
7 Correct 4 ms 23132 KB Output is correct
8 Correct 4 ms 23132 KB Output is correct
9 Correct 4 ms 23128 KB Output is correct
10 Correct 3 ms 23132 KB Output is correct
11 Correct 4 ms 23132 KB Output is correct
12 Correct 4 ms 23132 KB Output is correct
13 Correct 4 ms 23132 KB Output is correct
14 Correct 4 ms 23132 KB Output is correct
15 Correct 4 ms 23132 KB Output is correct
16 Correct 3 ms 23132 KB Output is correct
17 Correct 4 ms 23132 KB Output is correct
18 Correct 4 ms 23132 KB Output is correct
19 Correct 3 ms 23132 KB Output is correct
20 Correct 4 ms 23208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 40 ms 29068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 23132 KB Output is correct
2 Correct 4 ms 23132 KB Output is correct
3 Correct 5 ms 23132 KB Output is correct
4 Correct 4 ms 23132 KB Output is correct
5 Correct 4 ms 23248 KB Output is correct
6 Correct 4 ms 23128 KB Output is correct
7 Correct 4 ms 23132 KB Output is correct
8 Correct 4 ms 23132 KB Output is correct
9 Correct 4 ms 23308 KB Output is correct
10 Correct 3 ms 23316 KB Output is correct
11 Correct 4 ms 23132 KB Output is correct
12 Correct 3 ms 23132 KB Output is correct
13 Correct 3 ms 23132 KB Output is correct
14 Correct 4 ms 23132 KB Output is correct
15 Correct 4 ms 23204 KB Output is correct
16 Correct 4 ms 23128 KB Output is correct
17 Correct 5 ms 23132 KB Output is correct
18 Correct 4 ms 23132 KB Output is correct
19 Correct 4 ms 23248 KB Output is correct
20 Correct 4 ms 23208 KB Output is correct
21 Correct 4 ms 23132 KB Output is correct
22 Correct 4 ms 23132 KB Output is correct
23 Correct 4 ms 23132 KB Output is correct
24 Correct 4 ms 23132 KB Output is correct
25 Correct 3 ms 23132 KB Output is correct
26 Correct 4 ms 23132 KB Output is correct
27 Correct 4 ms 23232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 41 ms 28876 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 23132 KB Output is correct
2 Correct 4 ms 23132 KB Output is correct
3 Correct 4 ms 23132 KB Output is correct
4 Correct 4 ms 23208 KB Output is correct
5 Correct 4 ms 23132 KB Output is correct
6 Correct 4 ms 23132 KB Output is correct
7 Correct 4 ms 23200 KB Output is correct
8 Correct 4 ms 23132 KB Output is correct
9 Correct 3 ms 23132 KB Output is correct
10 Correct 3 ms 22976 KB Output is correct
11 Correct 4 ms 23132 KB Output is correct
12 Correct 4 ms 23132 KB Output is correct
13 Correct 4 ms 23128 KB Output is correct
14 Correct 4 ms 23132 KB Output is correct
15 Correct 4 ms 23132 KB Output is correct
16 Correct 4 ms 23132 KB Output is correct
17 Correct 3 ms 23132 KB Output is correct
18 Correct 3 ms 23192 KB Output is correct
19 Correct 4 ms 23132 KB Output is correct
20 Correct 4 ms 23128 KB Output is correct
21 Correct 3 ms 23132 KB Output is correct
22 Correct 5 ms 23208 KB Output is correct
23 Correct 4 ms 23132 KB Output is correct
24 Correct 3 ms 23128 KB Output is correct
25 Correct 4 ms 23132 KB Output is correct
26 Correct 3 ms 23160 KB Output is correct
27 Correct 4 ms 23128 KB Output is correct
28 Correct 4 ms 23132 KB Output is correct
29 Correct 3 ms 23132 KB Output is correct
30 Correct 4 ms 23132 KB Output is correct
31 Correct 5 ms 23132 KB Output is correct
32 Correct 4 ms 23132 KB Output is correct
33 Correct 4 ms 23132 KB Output is correct
34 Correct 4 ms 23132 KB Output is correct
35 Correct 5 ms 23216 KB Output is correct
36 Correct 4 ms 23132 KB Output is correct
37 Correct 4 ms 23132 KB Output is correct
38 Correct 4 ms 23132 KB Output is correct
39 Correct 4 ms 23168 KB Output is correct
40 Correct 4 ms 23128 KB Output is correct
41 Correct 4 ms 23132 KB Output is correct
42 Correct 4 ms 23132 KB Output is correct
43 Correct 4 ms 23136 KB Output is correct
44 Correct 4 ms 23132 KB Output is correct
45 Correct 5 ms 23132 KB Output is correct
46 Correct 5 ms 23132 KB Output is correct
47 Correct 5 ms 23132 KB Output is correct
48 Correct 4 ms 23164 KB Output is correct
49 Correct 5 ms 23200 KB Output is correct
50 Correct 3 ms 23128 KB Output is correct
51 Correct 4 ms 23196 KB Output is correct
52 Correct 4 ms 23128 KB Output is correct
53 Correct 4 ms 23132 KB Output is correct
54 Correct 5 ms 23132 KB Output is correct
55 Correct 4 ms 23132 KB Output is correct
56 Correct 3 ms 23128 KB Output is correct
57 Correct 3 ms 23132 KB Output is correct
58 Correct 5 ms 23200 KB Output is correct
59 Correct 4 ms 23132 KB Output is correct
60 Correct 4 ms 23132 KB Output is correct
61 Correct 4 ms 23132 KB Output is correct
62 Correct 4 ms 23204 KB Output is correct
63 Correct 5 ms 23128 KB Output is correct
64 Correct 4 ms 23132 KB Output is correct
65 Correct 4 ms 23132 KB Output is correct
66 Correct 3 ms 23128 KB Output is correct
67 Correct 4 ms 23132 KB Output is correct
68 Correct 4 ms 23132 KB Output is correct
69 Correct 4 ms 23384 KB Output is correct
70 Correct 4 ms 23388 KB Output is correct
71 Correct 4 ms 23132 KB Output is correct
72 Correct 4 ms 23196 KB Output is correct
73 Correct 4 ms 23132 KB Output is correct
74 Correct 4 ms 23160 KB Output is correct
75 Correct 4 ms 23136 KB Output is correct
76 Correct 4 ms 23132 KB Output is correct
77 Correct 3 ms 23224 KB Output is correct
78 Correct 4 ms 23136 KB Output is correct
79 Correct 3 ms 23132 KB Output is correct
80 Correct 5 ms 23128 KB Output is correct
81 Correct 4 ms 23140 KB Output is correct
82 Correct 4 ms 23392 KB Output is correct
83 Correct 4 ms 23392 KB Output is correct
84 Correct 4 ms 23364 KB Output is correct
85 Correct 4 ms 23132 KB Output is correct
86 Correct 4 ms 23132 KB Output is correct
87 Correct 4 ms 23136 KB Output is correct
88 Correct 4 ms 23324 KB Output is correct
89 Correct 4 ms 23136 KB Output is correct
90 Correct 4 ms 23136 KB Output is correct
91 Correct 3 ms 23136 KB Output is correct
92 Correct 3 ms 23132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 23132 KB Output is correct
2 Correct 4 ms 23132 KB Output is correct
3 Correct 4 ms 23132 KB Output is correct
4 Correct 4 ms 23208 KB Output is correct
5 Correct 4 ms 23132 KB Output is correct
6 Correct 4 ms 23132 KB Output is correct
7 Correct 4 ms 23200 KB Output is correct
8 Correct 4 ms 23132 KB Output is correct
9 Correct 3 ms 23132 KB Output is correct
10 Correct 3 ms 22976 KB Output is correct
11 Correct 4 ms 23132 KB Output is correct
12 Correct 4 ms 23132 KB Output is correct
13 Correct 4 ms 23128 KB Output is correct
14 Correct 4 ms 23132 KB Output is correct
15 Correct 4 ms 23132 KB Output is correct
16 Correct 4 ms 23132 KB Output is correct
17 Correct 3 ms 23132 KB Output is correct
18 Correct 3 ms 23192 KB Output is correct
19 Correct 4 ms 23132 KB Output is correct
20 Correct 4 ms 23128 KB Output is correct
21 Correct 3 ms 23132 KB Output is correct
22 Correct 5 ms 23208 KB Output is correct
23 Correct 4 ms 23132 KB Output is correct
24 Correct 3 ms 23128 KB Output is correct
25 Correct 4 ms 23132 KB Output is correct
26 Correct 3 ms 23160 KB Output is correct
27 Correct 4 ms 23128 KB Output is correct
28 Correct 4 ms 23132 KB Output is correct
29 Correct 3 ms 23132 KB Output is correct
30 Correct 4 ms 23132 KB Output is correct
31 Correct 5 ms 23132 KB Output is correct
32 Correct 4 ms 23132 KB Output is correct
33 Correct 4 ms 23132 KB Output is correct
34 Correct 4 ms 23132 KB Output is correct
35 Correct 5 ms 23216 KB Output is correct
36 Correct 4 ms 23132 KB Output is correct
37 Correct 4 ms 23132 KB Output is correct
38 Correct 4 ms 23132 KB Output is correct
39 Correct 4 ms 23168 KB Output is correct
40 Correct 4 ms 23128 KB Output is correct
41 Correct 4 ms 23132 KB Output is correct
42 Correct 4 ms 23132 KB Output is correct
43 Correct 4 ms 23136 KB Output is correct
44 Correct 4 ms 23132 KB Output is correct
45 Correct 5 ms 23132 KB Output is correct
46 Correct 5 ms 23132 KB Output is correct
47 Correct 5 ms 23132 KB Output is correct
48 Correct 4 ms 23164 KB Output is correct
49 Correct 5 ms 23200 KB Output is correct
50 Correct 3 ms 23128 KB Output is correct
51 Correct 4 ms 23196 KB Output is correct
52 Correct 4 ms 23128 KB Output is correct
53 Correct 4 ms 23132 KB Output is correct
54 Correct 5 ms 23132 KB Output is correct
55 Correct 4 ms 23132 KB Output is correct
56 Correct 3 ms 23128 KB Output is correct
57 Correct 3 ms 23132 KB Output is correct
58 Correct 5 ms 23200 KB Output is correct
59 Correct 4 ms 23132 KB Output is correct
60 Correct 4 ms 23132 KB Output is correct
61 Correct 4 ms 23132 KB Output is correct
62 Correct 4 ms 23204 KB Output is correct
63 Correct 5 ms 23128 KB Output is correct
64 Correct 4 ms 23132 KB Output is correct
65 Correct 4 ms 23132 KB Output is correct
66 Correct 87 ms 45988 KB Output is correct
67 Correct 71 ms 46036 KB Output is correct
68 Correct 62 ms 38120 KB Output is correct
69 Correct 67 ms 43504 KB Output is correct
70 Correct 71 ms 37456 KB Output is correct
71 Correct 72 ms 36736 KB Output is correct
72 Correct 58 ms 34860 KB Output is correct
73 Correct 59 ms 36052 KB Output is correct
74 Correct 59 ms 33348 KB Output is correct
75 Correct 57 ms 34848 KB Output is correct
76 Correct 45 ms 31184 KB Output is correct
77 Correct 46 ms 31180 KB Output is correct
78 Correct 34 ms 30852 KB Output is correct
79 Correct 39 ms 30724 KB Output is correct
80 Correct 39 ms 29136 KB Output is correct
81 Correct 29 ms 29144 KB Output is correct
82 Correct 6 ms 24036 KB Output is correct
83 Correct 5 ms 24072 KB Output is correct
84 Correct 7 ms 24036 KB Output is correct
85 Correct 6 ms 24036 KB Output is correct
86 Correct 6 ms 24028 KB Output is correct
87 Correct 6 ms 24028 KB Output is correct
88 Correct 6 ms 23132 KB Output is correct
89 Correct 4 ms 23204 KB Output is correct
90 Correct 4 ms 23132 KB Output is correct
91 Correct 4 ms 23200 KB Output is correct
92 Correct 4 ms 23132 KB Output is correct
93 Correct 4 ms 23132 KB Output is correct
94 Correct 4 ms 23132 KB Output is correct
95 Correct 4 ms 23132 KB Output is correct
96 Correct 4 ms 23128 KB Output is correct
97 Correct 3 ms 23132 KB Output is correct
98 Correct 4 ms 23132 KB Output is correct
99 Correct 4 ms 23132 KB Output is correct
100 Correct 4 ms 23132 KB Output is correct
101 Correct 4 ms 23132 KB Output is correct
102 Correct 4 ms 23132 KB Output is correct
103 Correct 3 ms 23132 KB Output is correct
104 Correct 4 ms 23132 KB Output is correct
105 Correct 4 ms 23132 KB Output is correct
106 Correct 3 ms 23132 KB Output is correct
107 Correct 4 ms 23208 KB Output is correct
108 Incorrect 40 ms 29068 KB Output isn't correct
109 Halted 0 ms 0 KB -