답안 #993988

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
993988 2024-06-07T00:50:02 Z vjudge1 철인 이종 경기 (APIO18_duathlon) C++17
57 / 100
84 ms 89604 KB
#include<bits/stdc++.h>
using namespace std;
#define N 1<<20
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 11 ms 66136 KB Output is correct
2 Correct 11 ms 66140 KB Output is correct
3 Correct 11 ms 66140 KB Output is correct
4 Correct 10 ms 64168 KB Output is correct
5 Correct 12 ms 66140 KB Output is correct
6 Correct 10 ms 64092 KB Output is correct
7 Correct 11 ms 66140 KB Output is correct
8 Correct 11 ms 66140 KB Output is correct
9 Correct 11 ms 66140 KB Output is correct
10 Correct 11 ms 66136 KB Output is correct
11 Correct 11 ms 66136 KB Output is correct
12 Correct 10 ms 66140 KB Output is correct
13 Correct 11 ms 66268 KB Output is correct
14 Correct 11 ms 66140 KB Output is correct
15 Correct 11 ms 66140 KB Output is correct
16 Correct 11 ms 66140 KB Output is correct
17 Correct 12 ms 66140 KB Output is correct
18 Correct 11 ms 66140 KB Output is correct
19 Correct 12 ms 64236 KB Output is correct
20 Correct 10 ms 64188 KB Output is correct
21 Correct 11 ms 64092 KB Output is correct
22 Correct 11 ms 66140 KB Output is correct
23 Correct 10 ms 66136 KB Output is correct
24 Correct 11 ms 66136 KB Output is correct
25 Correct 11 ms 66136 KB Output is correct
26 Correct 10 ms 66140 KB Output is correct
27 Correct 11 ms 66140 KB Output is correct
28 Correct 11 ms 66140 KB Output is correct
29 Correct 11 ms 66140 KB Output is correct
30 Correct 10 ms 66140 KB Output is correct
31 Correct 11 ms 66244 KB Output is correct
32 Correct 11 ms 66136 KB Output is correct
33 Correct 10 ms 66280 KB Output is correct
34 Correct 14 ms 66140 KB Output is correct
35 Correct 14 ms 66308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 66136 KB Output is correct
2 Correct 11 ms 66140 KB Output is correct
3 Correct 11 ms 66140 KB Output is correct
4 Correct 10 ms 64168 KB Output is correct
5 Correct 12 ms 66140 KB Output is correct
6 Correct 10 ms 64092 KB Output is correct
7 Correct 11 ms 66140 KB Output is correct
8 Correct 11 ms 66140 KB Output is correct
9 Correct 11 ms 66140 KB Output is correct
10 Correct 11 ms 66136 KB Output is correct
11 Correct 11 ms 66136 KB Output is correct
12 Correct 10 ms 66140 KB Output is correct
13 Correct 11 ms 66268 KB Output is correct
14 Correct 11 ms 66140 KB Output is correct
15 Correct 11 ms 66140 KB Output is correct
16 Correct 11 ms 66140 KB Output is correct
17 Correct 12 ms 66140 KB Output is correct
18 Correct 11 ms 66140 KB Output is correct
19 Correct 12 ms 64236 KB Output is correct
20 Correct 10 ms 64188 KB Output is correct
21 Correct 11 ms 64092 KB Output is correct
22 Correct 11 ms 66140 KB Output is correct
23 Correct 10 ms 66136 KB Output is correct
24 Correct 11 ms 66136 KB Output is correct
25 Correct 11 ms 66136 KB Output is correct
26 Correct 10 ms 66140 KB Output is correct
27 Correct 11 ms 66140 KB Output is correct
28 Correct 11 ms 66140 KB Output is correct
29 Correct 11 ms 66140 KB Output is correct
30 Correct 10 ms 66140 KB Output is correct
31 Correct 11 ms 66244 KB Output is correct
32 Correct 11 ms 66136 KB Output is correct
33 Correct 10 ms 66280 KB Output is correct
34 Correct 14 ms 66140 KB Output is correct
35 Correct 14 ms 66308 KB Output is correct
36 Correct 10 ms 64088 KB Output is correct
37 Correct 10 ms 64088 KB Output is correct
38 Correct 12 ms 66212 KB Output is correct
39 Correct 12 ms 66140 KB Output is correct
40 Correct 10 ms 66288 KB Output is correct
41 Correct 12 ms 64088 KB Output is correct
42 Correct 11 ms 64092 KB Output is correct
43 Correct 11 ms 64092 KB Output is correct
44 Correct 11 ms 64092 KB Output is correct
45 Correct 10 ms 64236 KB Output is correct
46 Correct 11 ms 64092 KB Output is correct
47 Correct 12 ms 66268 KB Output is correct
48 Correct 11 ms 64088 KB Output is correct
49 Correct 11 ms 64236 KB Output is correct
50 Correct 10 ms 64092 KB Output is correct
51 Correct 10 ms 66140 KB Output is correct
52 Correct 12 ms 66140 KB Output is correct
53 Correct 11 ms 66312 KB Output is correct
54 Correct 11 ms 66140 KB Output is correct
55 Correct 11 ms 66228 KB Output is correct
56 Correct 11 ms 66320 KB Output is correct
57 Correct 11 ms 66212 KB Output is correct
58 Correct 11 ms 66140 KB Output is correct
59 Correct 14 ms 66140 KB Output is correct
60 Correct 10 ms 66392 KB Output is correct
61 Correct 11 ms 66140 KB Output is correct
62 Correct 10 ms 66140 KB Output is correct
63 Correct 11 ms 66140 KB Output is correct
64 Correct 11 ms 66392 KB Output is correct
65 Correct 11 ms 66140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 89604 KB Output is correct
2 Correct 82 ms 89532 KB Output is correct
3 Correct 75 ms 81568 KB Output is correct
4 Correct 72 ms 84096 KB Output is correct
5 Correct 68 ms 79696 KB Output is correct
6 Correct 69 ms 79160 KB Output is correct
7 Correct 76 ms 75472 KB Output is correct
8 Correct 69 ms 78292 KB Output is correct
9 Correct 62 ms 73932 KB Output is correct
10 Correct 64 ms 77048 KB Output is correct
11 Correct 52 ms 73676 KB Output is correct
12 Correct 51 ms 73424 KB Output is correct
13 Correct 47 ms 73424 KB Output is correct
14 Correct 52 ms 71660 KB Output is correct
15 Correct 41 ms 70348 KB Output is correct
16 Correct 48 ms 70352 KB Output is correct
17 Correct 13 ms 65508 KB Output is correct
18 Correct 13 ms 65444 KB Output is correct
19 Correct 13 ms 65508 KB Output is correct
20 Correct 14 ms 65508 KB Output is correct
21 Correct 13 ms 65388 KB Output is correct
22 Correct 15 ms 65244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 64088 KB Output is correct
2 Correct 11 ms 64092 KB Output is correct
3 Correct 12 ms 64092 KB Output is correct
4 Correct 11 ms 64348 KB Output is correct
5 Correct 12 ms 64236 KB Output is correct
6 Correct 11 ms 64348 KB Output is correct
7 Correct 11 ms 64344 KB Output is correct
8 Correct 10 ms 64348 KB Output is correct
9 Correct 10 ms 64216 KB Output is correct
10 Correct 11 ms 64092 KB Output is correct
11 Correct 11 ms 64224 KB Output is correct
12 Correct 10 ms 64092 KB Output is correct
13 Correct 11 ms 64088 KB Output is correct
14 Correct 11 ms 64088 KB Output is correct
15 Correct 12 ms 64092 KB Output is correct
16 Correct 11 ms 64092 KB Output is correct
17 Correct 11 ms 64092 KB Output is correct
18 Correct 11 ms 64192 KB Output is correct
19 Correct 10 ms 64092 KB Output is correct
20 Correct 10 ms 64180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 68 ms 70348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 64088 KB Output is correct
2 Correct 11 ms 64092 KB Output is correct
3 Correct 14 ms 66396 KB Output is correct
4 Correct 12 ms 66276 KB Output is correct
5 Correct 12 ms 66204 KB Output is correct
6 Correct 12 ms 66424 KB Output is correct
7 Correct 11 ms 66248 KB Output is correct
8 Correct 11 ms 66396 KB Output is correct
9 Correct 10 ms 66416 KB Output is correct
10 Correct 11 ms 66416 KB Output is correct
11 Correct 12 ms 66396 KB Output is correct
12 Correct 11 ms 66396 KB Output is correct
13 Correct 11 ms 66260 KB Output is correct
14 Correct 12 ms 66392 KB Output is correct
15 Correct 11 ms 66396 KB Output is correct
16 Correct 11 ms 66212 KB Output is correct
17 Correct 12 ms 66392 KB Output is correct
18 Correct 12 ms 66392 KB Output is correct
19 Correct 10 ms 66404 KB Output is correct
20 Correct 11 ms 66396 KB Output is correct
21 Correct 11 ms 66252 KB Output is correct
22 Correct 11 ms 66400 KB Output is correct
23 Correct 12 ms 66396 KB Output is correct
24 Correct 12 ms 66396 KB Output is correct
25 Correct 10 ms 64244 KB Output is correct
26 Correct 10 ms 64092 KB Output is correct
27 Correct 10 ms 64092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 55 ms 70348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 66136 KB Output is correct
2 Correct 11 ms 66140 KB Output is correct
3 Correct 11 ms 66140 KB Output is correct
4 Correct 10 ms 64168 KB Output is correct
5 Correct 12 ms 66140 KB Output is correct
6 Correct 10 ms 64092 KB Output is correct
7 Correct 11 ms 66140 KB Output is correct
8 Correct 11 ms 66140 KB Output is correct
9 Correct 11 ms 66140 KB Output is correct
10 Correct 11 ms 66136 KB Output is correct
11 Correct 11 ms 66136 KB Output is correct
12 Correct 10 ms 66140 KB Output is correct
13 Correct 11 ms 66268 KB Output is correct
14 Correct 11 ms 66140 KB Output is correct
15 Correct 11 ms 66140 KB Output is correct
16 Correct 11 ms 66140 KB Output is correct
17 Correct 12 ms 66140 KB Output is correct
18 Correct 11 ms 66140 KB Output is correct
19 Correct 12 ms 64236 KB Output is correct
20 Correct 10 ms 64188 KB Output is correct
21 Correct 11 ms 64092 KB Output is correct
22 Correct 11 ms 66140 KB Output is correct
23 Correct 10 ms 66136 KB Output is correct
24 Correct 11 ms 66136 KB Output is correct
25 Correct 11 ms 66136 KB Output is correct
26 Correct 10 ms 66140 KB Output is correct
27 Correct 11 ms 66140 KB Output is correct
28 Correct 11 ms 66140 KB Output is correct
29 Correct 11 ms 66140 KB Output is correct
30 Correct 10 ms 66140 KB Output is correct
31 Correct 11 ms 66244 KB Output is correct
32 Correct 11 ms 66136 KB Output is correct
33 Correct 10 ms 66280 KB Output is correct
34 Correct 14 ms 66140 KB Output is correct
35 Correct 14 ms 66308 KB Output is correct
36 Correct 10 ms 64088 KB Output is correct
37 Correct 10 ms 64088 KB Output is correct
38 Correct 12 ms 66212 KB Output is correct
39 Correct 12 ms 66140 KB Output is correct
40 Correct 10 ms 66288 KB Output is correct
41 Correct 12 ms 64088 KB Output is correct
42 Correct 11 ms 64092 KB Output is correct
43 Correct 11 ms 64092 KB Output is correct
44 Correct 11 ms 64092 KB Output is correct
45 Correct 10 ms 64236 KB Output is correct
46 Correct 11 ms 64092 KB Output is correct
47 Correct 12 ms 66268 KB Output is correct
48 Correct 11 ms 64088 KB Output is correct
49 Correct 11 ms 64236 KB Output is correct
50 Correct 10 ms 64092 KB Output is correct
51 Correct 10 ms 66140 KB Output is correct
52 Correct 12 ms 66140 KB Output is correct
53 Correct 11 ms 66312 KB Output is correct
54 Correct 11 ms 66140 KB Output is correct
55 Correct 11 ms 66228 KB Output is correct
56 Correct 11 ms 66320 KB Output is correct
57 Correct 11 ms 66212 KB Output is correct
58 Correct 11 ms 66140 KB Output is correct
59 Correct 14 ms 66140 KB Output is correct
60 Correct 10 ms 66392 KB Output is correct
61 Correct 11 ms 66140 KB Output is correct
62 Correct 10 ms 66140 KB Output is correct
63 Correct 11 ms 66140 KB Output is correct
64 Correct 11 ms 66392 KB Output is correct
65 Correct 11 ms 66140 KB Output is correct
66 Correct 10 ms 64092 KB Output is correct
67 Correct 10 ms 64092 KB Output is correct
68 Correct 11 ms 66392 KB Output is correct
69 Correct 11 ms 66396 KB Output is correct
70 Correct 11 ms 66540 KB Output is correct
71 Correct 11 ms 64092 KB Output is correct
72 Correct 11 ms 64352 KB Output is correct
73 Correct 12 ms 64180 KB Output is correct
74 Correct 12 ms 64348 KB Output is correct
75 Correct 14 ms 64348 KB Output is correct
76 Correct 11 ms 66140 KB Output is correct
77 Correct 11 ms 66396 KB Output is correct
78 Correct 11 ms 66260 KB Output is correct
79 Correct 11 ms 66392 KB Output is correct
80 Correct 10 ms 66396 KB Output is correct
81 Correct 11 ms 66396 KB Output is correct
82 Correct 11 ms 66392 KB Output is correct
83 Correct 11 ms 66396 KB Output is correct
84 Correct 12 ms 66396 KB Output is correct
85 Correct 11 ms 66232 KB Output is correct
86 Correct 11 ms 66396 KB Output is correct
87 Correct 11 ms 66396 KB Output is correct
88 Correct 11 ms 66396 KB Output is correct
89 Correct 11 ms 66232 KB Output is correct
90 Correct 11 ms 66396 KB Output is correct
91 Correct 12 ms 66296 KB Output is correct
92 Correct 12 ms 66424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 66136 KB Output is correct
2 Correct 11 ms 66140 KB Output is correct
3 Correct 11 ms 66140 KB Output is correct
4 Correct 10 ms 64168 KB Output is correct
5 Correct 12 ms 66140 KB Output is correct
6 Correct 10 ms 64092 KB Output is correct
7 Correct 11 ms 66140 KB Output is correct
8 Correct 11 ms 66140 KB Output is correct
9 Correct 11 ms 66140 KB Output is correct
10 Correct 11 ms 66136 KB Output is correct
11 Correct 11 ms 66136 KB Output is correct
12 Correct 10 ms 66140 KB Output is correct
13 Correct 11 ms 66268 KB Output is correct
14 Correct 11 ms 66140 KB Output is correct
15 Correct 11 ms 66140 KB Output is correct
16 Correct 11 ms 66140 KB Output is correct
17 Correct 12 ms 66140 KB Output is correct
18 Correct 11 ms 66140 KB Output is correct
19 Correct 12 ms 64236 KB Output is correct
20 Correct 10 ms 64188 KB Output is correct
21 Correct 11 ms 64092 KB Output is correct
22 Correct 11 ms 66140 KB Output is correct
23 Correct 10 ms 66136 KB Output is correct
24 Correct 11 ms 66136 KB Output is correct
25 Correct 11 ms 66136 KB Output is correct
26 Correct 10 ms 66140 KB Output is correct
27 Correct 11 ms 66140 KB Output is correct
28 Correct 11 ms 66140 KB Output is correct
29 Correct 11 ms 66140 KB Output is correct
30 Correct 10 ms 66140 KB Output is correct
31 Correct 11 ms 66244 KB Output is correct
32 Correct 11 ms 66136 KB Output is correct
33 Correct 10 ms 66280 KB Output is correct
34 Correct 14 ms 66140 KB Output is correct
35 Correct 14 ms 66308 KB Output is correct
36 Correct 10 ms 64088 KB Output is correct
37 Correct 10 ms 64088 KB Output is correct
38 Correct 12 ms 66212 KB Output is correct
39 Correct 12 ms 66140 KB Output is correct
40 Correct 10 ms 66288 KB Output is correct
41 Correct 12 ms 64088 KB Output is correct
42 Correct 11 ms 64092 KB Output is correct
43 Correct 11 ms 64092 KB Output is correct
44 Correct 11 ms 64092 KB Output is correct
45 Correct 10 ms 64236 KB Output is correct
46 Correct 11 ms 64092 KB Output is correct
47 Correct 12 ms 66268 KB Output is correct
48 Correct 11 ms 64088 KB Output is correct
49 Correct 11 ms 64236 KB Output is correct
50 Correct 10 ms 64092 KB Output is correct
51 Correct 10 ms 66140 KB Output is correct
52 Correct 12 ms 66140 KB Output is correct
53 Correct 11 ms 66312 KB Output is correct
54 Correct 11 ms 66140 KB Output is correct
55 Correct 11 ms 66228 KB Output is correct
56 Correct 11 ms 66320 KB Output is correct
57 Correct 11 ms 66212 KB Output is correct
58 Correct 11 ms 66140 KB Output is correct
59 Correct 14 ms 66140 KB Output is correct
60 Correct 10 ms 66392 KB Output is correct
61 Correct 11 ms 66140 KB Output is correct
62 Correct 10 ms 66140 KB Output is correct
63 Correct 11 ms 66140 KB Output is correct
64 Correct 11 ms 66392 KB Output is correct
65 Correct 11 ms 66140 KB Output is correct
66 Correct 84 ms 89604 KB Output is correct
67 Correct 82 ms 89532 KB Output is correct
68 Correct 75 ms 81568 KB Output is correct
69 Correct 72 ms 84096 KB Output is correct
70 Correct 68 ms 79696 KB Output is correct
71 Correct 69 ms 79160 KB Output is correct
72 Correct 76 ms 75472 KB Output is correct
73 Correct 69 ms 78292 KB Output is correct
74 Correct 62 ms 73932 KB Output is correct
75 Correct 64 ms 77048 KB Output is correct
76 Correct 52 ms 73676 KB Output is correct
77 Correct 51 ms 73424 KB Output is correct
78 Correct 47 ms 73424 KB Output is correct
79 Correct 52 ms 71660 KB Output is correct
80 Correct 41 ms 70348 KB Output is correct
81 Correct 48 ms 70352 KB Output is correct
82 Correct 13 ms 65508 KB Output is correct
83 Correct 13 ms 65444 KB Output is correct
84 Correct 13 ms 65508 KB Output is correct
85 Correct 14 ms 65508 KB Output is correct
86 Correct 13 ms 65388 KB Output is correct
87 Correct 15 ms 65244 KB Output is correct
88 Correct 14 ms 64088 KB Output is correct
89 Correct 11 ms 64092 KB Output is correct
90 Correct 12 ms 64092 KB Output is correct
91 Correct 11 ms 64348 KB Output is correct
92 Correct 12 ms 64236 KB Output is correct
93 Correct 11 ms 64348 KB Output is correct
94 Correct 11 ms 64344 KB Output is correct
95 Correct 10 ms 64348 KB Output is correct
96 Correct 10 ms 64216 KB Output is correct
97 Correct 11 ms 64092 KB Output is correct
98 Correct 11 ms 64224 KB Output is correct
99 Correct 10 ms 64092 KB Output is correct
100 Correct 11 ms 64088 KB Output is correct
101 Correct 11 ms 64088 KB Output is correct
102 Correct 12 ms 64092 KB Output is correct
103 Correct 11 ms 64092 KB Output is correct
104 Correct 11 ms 64092 KB Output is correct
105 Correct 11 ms 64192 KB Output is correct
106 Correct 10 ms 64092 KB Output is correct
107 Correct 10 ms 64180 KB Output is correct
108 Incorrect 68 ms 70348 KB Output isn't correct
109 Halted 0 ms 0 KB -