답안 #232067

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
232067 2020-05-16T00:02:34 Z AQT 철인 이종 경기 (APIO18_duathlon) C++14
41 / 100
184 ms 58980 KB
// Problem : APIO '18 P3 - Duathlon
// Contest : DMOJ
// URL : https://dmoj.ca/problem/apio18p3
// Memory Limit : 1 MB
// Time Limit : 600 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;

int N, M;
vector<int> graph[100005], cgraph[200005];
vector<pair<int, int>> stk;
vector<vector<pair<int, int>>> cmp;
int par[200005], dfn[200005], low[200005], t;
long long sz[200005], csz[200005];
long long ans;

void dfs1(int n){
	low[n] = dfn[n] = ++t;
	int c = 0;
	for(int e : graph[n]){
		if(e == par[n]){
			continue;
		}
		if(!dfn[e]){
			c++;
			par[e] = n;
			stk.emplace_back(n, e);					
			dfs1(e);
			low[n] = min(low[n], low[e]);
			if((!par[n] && c >= 2) || (par[n] && low[e] >= dfn[n])){
				//cout << "enter: " << n << "\n";
				pair<int, int> edg = {0, 0};
				vector<pair<int, int>> tmp;
				do{
					edg = stk.back();
					stk.pop_back();
					tmp.push_back(edg);
					//cout << "indfs: " << edg.first << " " << edg.second << "\n";
				}
				while(edg != make_pair(n, e));
				cmp.push_back(tmp);
			}
		}
		else if(dfn[e] < dfn[n]){
			low[n] = min(dfn[e], low[n]);
			stk.emplace_back(n, e);		
		}
	}
}

void dfs2(int n){
	sz[n] = n <= N;
	for(int e : cgraph[n]){
		if(e != par[n]){
			par[e] = n;
			dfs2(e);
			sz[n] += sz[e];
		}
	}
	if(n > N){
		csz[n] = cgraph[n].size();
	}
}

void dfs3(int n, long long tot){
	if(n > N){
		ans -= (csz[n]-1) * (tot-sz[n]) * (tot-sz[n]-1);
	}
	for(int e : cgraph[n]){
		if(n <= N && e == par[n]){
			ans -= (csz[e]-1)*sz[n]*(sz[n]-1);
		}
		if(e != par[n]){
			dfs3(e, tot);
		}
	}
}

int main(){
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> N >> M;
	for(int i = 1; i<=M; i++){
		int a, b;
		cin >> a >> b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	int C = N;
	for(int i = 1; i<=N; i++){
		if(!dfn[i]){
			dfs1(i);
			if(stk.size()){
				cmp.push_back(stk);
				stk.clear();
			}
			for(auto v : cmp){
				++C;
				for(auto p : v){
					//cout << p.first << " " << p.second << "\n";
					cgraph[C].push_back(p.second);
					cgraph[C].push_back(p.first);
				}
				//cout << "\n";
				sort(cgraph[C].begin(), cgraph[C].end());
				cgraph[C].erase(unique(cgraph[C].begin(), cgraph[C].end()), cgraph[C].end());
				for(int n : cgraph[C]){
					cgraph[n].push_back(C);
				}
			}
			dfs2(i);
			dfs3(i, sz[i]);
			ans += sz[i] * (sz[i]-1) * (sz[i] -2);
		}
	}
	cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7424 KB Output is correct
2 Correct 10 ms 7424 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 8 ms 7424 KB Output is correct
5 Correct 9 ms 7424 KB Output is correct
6 Correct 9 ms 7552 KB Output is correct
7 Correct 8 ms 7424 KB Output is correct
8 Correct 8 ms 7424 KB Output is correct
9 Correct 8 ms 7424 KB Output is correct
10 Correct 9 ms 7424 KB Output is correct
11 Correct 8 ms 7424 KB Output is correct
12 Correct 9 ms 7424 KB Output is correct
13 Correct 8 ms 7424 KB Output is correct
14 Correct 8 ms 7424 KB Output is correct
15 Correct 8 ms 7424 KB Output is correct
16 Correct 9 ms 7424 KB Output is correct
17 Correct 8 ms 7424 KB Output is correct
18 Correct 8 ms 7424 KB Output is correct
19 Correct 8 ms 7296 KB Output is correct
20 Correct 8 ms 7424 KB Output is correct
21 Correct 9 ms 7424 KB Output is correct
22 Correct 8 ms 7424 KB Output is correct
23 Correct 8 ms 7424 KB Output is correct
24 Correct 8 ms 7424 KB Output is correct
25 Correct 9 ms 7424 KB Output is correct
26 Correct 9 ms 7424 KB Output is correct
27 Correct 8 ms 7424 KB Output is correct
28 Correct 8 ms 7424 KB Output is correct
29 Correct 8 ms 7424 KB Output is correct
30 Correct 8 ms 7424 KB Output is correct
31 Correct 8 ms 7424 KB Output is correct
32 Correct 8 ms 7424 KB Output is correct
33 Correct 9 ms 7424 KB Output is correct
34 Correct 9 ms 7424 KB Output is correct
35 Correct 8 ms 7424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7424 KB Output is correct
2 Correct 10 ms 7424 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 8 ms 7424 KB Output is correct
5 Correct 9 ms 7424 KB Output is correct
6 Correct 9 ms 7552 KB Output is correct
7 Correct 8 ms 7424 KB Output is correct
8 Correct 8 ms 7424 KB Output is correct
9 Correct 8 ms 7424 KB Output is correct
10 Correct 9 ms 7424 KB Output is correct
11 Correct 8 ms 7424 KB Output is correct
12 Correct 9 ms 7424 KB Output is correct
13 Correct 8 ms 7424 KB Output is correct
14 Correct 8 ms 7424 KB Output is correct
15 Correct 8 ms 7424 KB Output is correct
16 Correct 9 ms 7424 KB Output is correct
17 Correct 8 ms 7424 KB Output is correct
18 Correct 8 ms 7424 KB Output is correct
19 Correct 8 ms 7296 KB Output is correct
20 Correct 8 ms 7424 KB Output is correct
21 Correct 9 ms 7424 KB Output is correct
22 Correct 8 ms 7424 KB Output is correct
23 Correct 8 ms 7424 KB Output is correct
24 Correct 8 ms 7424 KB Output is correct
25 Correct 9 ms 7424 KB Output is correct
26 Correct 9 ms 7424 KB Output is correct
27 Correct 8 ms 7424 KB Output is correct
28 Correct 8 ms 7424 KB Output is correct
29 Correct 8 ms 7424 KB Output is correct
30 Correct 8 ms 7424 KB Output is correct
31 Correct 8 ms 7424 KB Output is correct
32 Correct 8 ms 7424 KB Output is correct
33 Correct 9 ms 7424 KB Output is correct
34 Correct 9 ms 7424 KB Output is correct
35 Correct 8 ms 7424 KB Output is correct
36 Correct 8 ms 7424 KB Output is correct
37 Correct 8 ms 7552 KB Output is correct
38 Correct 8 ms 7424 KB Output is correct
39 Correct 9 ms 7424 KB Output is correct
40 Correct 8 ms 7424 KB Output is correct
41 Correct 8 ms 7424 KB Output is correct
42 Correct 9 ms 7424 KB Output is correct
43 Correct 9 ms 7424 KB Output is correct
44 Correct 8 ms 7424 KB Output is correct
45 Correct 9 ms 7424 KB Output is correct
46 Correct 9 ms 7424 KB Output is correct
47 Correct 8 ms 7424 KB Output is correct
48 Correct 9 ms 7424 KB Output is correct
49 Correct 8 ms 7424 KB Output is correct
50 Correct 8 ms 7424 KB Output is correct
51 Correct 8 ms 7424 KB Output is correct
52 Correct 8 ms 7424 KB Output is correct
53 Correct 8 ms 7424 KB Output is correct
54 Correct 9 ms 7424 KB Output is correct
55 Correct 8 ms 7424 KB Output is correct
56 Correct 8 ms 7424 KB Output is correct
57 Correct 8 ms 7424 KB Output is correct
58 Correct 8 ms 7424 KB Output is correct
59 Correct 9 ms 7424 KB Output is correct
60 Correct 9 ms 7424 KB Output is correct
61 Correct 8 ms 7424 KB Output is correct
62 Correct 9 ms 7424 KB Output is correct
63 Correct 9 ms 7424 KB Output is correct
64 Correct 8 ms 7424 KB Output is correct
65 Correct 8 ms 7424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 30548 KB Output is correct
2 Correct 110 ms 30552 KB Output is correct
3 Correct 134 ms 28896 KB Output is correct
4 Correct 119 ms 30760 KB Output is correct
5 Correct 140 ms 25412 KB Output is correct
6 Runtime error 180 ms 58980 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7680 KB Output is correct
2 Correct 9 ms 7680 KB Output is correct
3 Correct 9 ms 7680 KB Output is correct
4 Correct 9 ms 7680 KB Output is correct
5 Correct 11 ms 7680 KB Output is correct
6 Correct 9 ms 7680 KB Output is correct
7 Correct 9 ms 7680 KB Output is correct
8 Correct 9 ms 7680 KB Output is correct
9 Correct 9 ms 7680 KB Output is correct
10 Correct 9 ms 7552 KB Output is correct
11 Correct 10 ms 7680 KB Output is correct
12 Correct 10 ms 7680 KB Output is correct
13 Correct 11 ms 7936 KB Output is correct
14 Correct 20 ms 10880 KB Output is correct
15 Correct 30 ms 13696 KB Output is correct
16 Correct 39 ms 16248 KB Output is correct
17 Correct 10 ms 7552 KB Output is correct
18 Correct 9 ms 7552 KB Output is correct
19 Correct 10 ms 7808 KB Output is correct
20 Correct 10 ms 7552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 136 ms 26400 KB Output is correct
2 Correct 132 ms 26400 KB Output is correct
3 Correct 141 ms 26532 KB Output is correct
4 Correct 131 ms 26464 KB Output is correct
5 Correct 131 ms 26408 KB Output is correct
6 Correct 143 ms 35172 KB Output is correct
7 Correct 151 ms 32100 KB Output is correct
8 Correct 144 ms 30760 KB Output is correct
9 Correct 148 ms 29220 KB Output is correct
10 Runtime error 142 ms 49188 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7552 KB Output is correct
2 Correct 11 ms 7680 KB Output is correct
3 Correct 9 ms 7552 KB Output is correct
4 Correct 10 ms 7552 KB Output is correct
5 Correct 9 ms 7552 KB Output is correct
6 Correct 10 ms 7552 KB Output is correct
7 Correct 9 ms 7552 KB Output is correct
8 Correct 9 ms 7552 KB Output is correct
9 Correct 9 ms 7552 KB Output is correct
10 Correct 9 ms 7552 KB Output is correct
11 Correct 9 ms 7552 KB Output is correct
12 Correct 10 ms 7680 KB Output is correct
13 Correct 9 ms 7680 KB Output is correct
14 Correct 9 ms 7680 KB Output is correct
15 Correct 9 ms 7680 KB Output is correct
16 Correct 9 ms 7552 KB Output is correct
17 Correct 9 ms 7680 KB Output is correct
18 Correct 10 ms 7680 KB Output is correct
19 Correct 20 ms 9984 KB Output is correct
20 Correct 25 ms 11520 KB Output is correct
21 Correct 9 ms 7552 KB Output is correct
22 Correct 10 ms 7552 KB Output is correct
23 Correct 9 ms 7552 KB Output is correct
24 Correct 9 ms 7552 KB Output is correct
25 Correct 24 ms 12032 KB Output is correct
26 Correct 16 ms 9984 KB Output is correct
27 Correct 13 ms 8704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 129 ms 26400 KB Output is correct
2 Correct 153 ms 26276 KB Output is correct
3 Correct 155 ms 24868 KB Output is correct
4 Correct 139 ms 24108 KB Output is correct
5 Correct 120 ms 21928 KB Output is correct
6 Correct 117 ms 20912 KB Output is correct
7 Correct 109 ms 20652 KB Output is correct
8 Correct 113 ms 20020 KB Output is correct
9 Correct 99 ms 19764 KB Output is correct
10 Correct 99 ms 19680 KB Output is correct
11 Correct 94 ms 19320 KB Output is correct
12 Correct 94 ms 19320 KB Output is correct
13 Correct 97 ms 19320 KB Output is correct
14 Correct 95 ms 22252 KB Output is correct
15 Correct 149 ms 32248 KB Output is correct
16 Correct 147 ms 30232 KB Output is correct
17 Correct 146 ms 30172 KB Output is correct
18 Correct 146 ms 28428 KB Output is correct
19 Runtime error 184 ms 50344 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7424 KB Output is correct
2 Correct 10 ms 7424 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 8 ms 7424 KB Output is correct
5 Correct 9 ms 7424 KB Output is correct
6 Correct 9 ms 7552 KB Output is correct
7 Correct 8 ms 7424 KB Output is correct
8 Correct 8 ms 7424 KB Output is correct
9 Correct 8 ms 7424 KB Output is correct
10 Correct 9 ms 7424 KB Output is correct
11 Correct 8 ms 7424 KB Output is correct
12 Correct 9 ms 7424 KB Output is correct
13 Correct 8 ms 7424 KB Output is correct
14 Correct 8 ms 7424 KB Output is correct
15 Correct 8 ms 7424 KB Output is correct
16 Correct 9 ms 7424 KB Output is correct
17 Correct 8 ms 7424 KB Output is correct
18 Correct 8 ms 7424 KB Output is correct
19 Correct 8 ms 7296 KB Output is correct
20 Correct 8 ms 7424 KB Output is correct
21 Correct 9 ms 7424 KB Output is correct
22 Correct 8 ms 7424 KB Output is correct
23 Correct 8 ms 7424 KB Output is correct
24 Correct 8 ms 7424 KB Output is correct
25 Correct 9 ms 7424 KB Output is correct
26 Correct 9 ms 7424 KB Output is correct
27 Correct 8 ms 7424 KB Output is correct
28 Correct 8 ms 7424 KB Output is correct
29 Correct 8 ms 7424 KB Output is correct
30 Correct 8 ms 7424 KB Output is correct
31 Correct 8 ms 7424 KB Output is correct
32 Correct 8 ms 7424 KB Output is correct
33 Correct 9 ms 7424 KB Output is correct
34 Correct 9 ms 7424 KB Output is correct
35 Correct 8 ms 7424 KB Output is correct
36 Correct 8 ms 7424 KB Output is correct
37 Correct 8 ms 7552 KB Output is correct
38 Correct 8 ms 7424 KB Output is correct
39 Correct 9 ms 7424 KB Output is correct
40 Correct 8 ms 7424 KB Output is correct
41 Correct 8 ms 7424 KB Output is correct
42 Correct 9 ms 7424 KB Output is correct
43 Correct 9 ms 7424 KB Output is correct
44 Correct 8 ms 7424 KB Output is correct
45 Correct 9 ms 7424 KB Output is correct
46 Correct 9 ms 7424 KB Output is correct
47 Correct 8 ms 7424 KB Output is correct
48 Correct 9 ms 7424 KB Output is correct
49 Correct 8 ms 7424 KB Output is correct
50 Correct 8 ms 7424 KB Output is correct
51 Correct 8 ms 7424 KB Output is correct
52 Correct 8 ms 7424 KB Output is correct
53 Correct 8 ms 7424 KB Output is correct
54 Correct 9 ms 7424 KB Output is correct
55 Correct 8 ms 7424 KB Output is correct
56 Correct 8 ms 7424 KB Output is correct
57 Correct 8 ms 7424 KB Output is correct
58 Correct 8 ms 7424 KB Output is correct
59 Correct 9 ms 7424 KB Output is correct
60 Correct 9 ms 7424 KB Output is correct
61 Correct 8 ms 7424 KB Output is correct
62 Correct 9 ms 7424 KB Output is correct
63 Correct 9 ms 7424 KB Output is correct
64 Correct 8 ms 7424 KB Output is correct
65 Correct 8 ms 7424 KB Output is correct
66 Correct 9 ms 7552 KB Output is correct
67 Runtime error 62 ms 34424 KB Execution killed with signal 11 (could be triggered by violating memory limits)
68 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7424 KB Output is correct
2 Correct 10 ms 7424 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 8 ms 7424 KB Output is correct
5 Correct 9 ms 7424 KB Output is correct
6 Correct 9 ms 7552 KB Output is correct
7 Correct 8 ms 7424 KB Output is correct
8 Correct 8 ms 7424 KB Output is correct
9 Correct 8 ms 7424 KB Output is correct
10 Correct 9 ms 7424 KB Output is correct
11 Correct 8 ms 7424 KB Output is correct
12 Correct 9 ms 7424 KB Output is correct
13 Correct 8 ms 7424 KB Output is correct
14 Correct 8 ms 7424 KB Output is correct
15 Correct 8 ms 7424 KB Output is correct
16 Correct 9 ms 7424 KB Output is correct
17 Correct 8 ms 7424 KB Output is correct
18 Correct 8 ms 7424 KB Output is correct
19 Correct 8 ms 7296 KB Output is correct
20 Correct 8 ms 7424 KB Output is correct
21 Correct 9 ms 7424 KB Output is correct
22 Correct 8 ms 7424 KB Output is correct
23 Correct 8 ms 7424 KB Output is correct
24 Correct 8 ms 7424 KB Output is correct
25 Correct 9 ms 7424 KB Output is correct
26 Correct 9 ms 7424 KB Output is correct
27 Correct 8 ms 7424 KB Output is correct
28 Correct 8 ms 7424 KB Output is correct
29 Correct 8 ms 7424 KB Output is correct
30 Correct 8 ms 7424 KB Output is correct
31 Correct 8 ms 7424 KB Output is correct
32 Correct 8 ms 7424 KB Output is correct
33 Correct 9 ms 7424 KB Output is correct
34 Correct 9 ms 7424 KB Output is correct
35 Correct 8 ms 7424 KB Output is correct
36 Correct 8 ms 7424 KB Output is correct
37 Correct 8 ms 7552 KB Output is correct
38 Correct 8 ms 7424 KB Output is correct
39 Correct 9 ms 7424 KB Output is correct
40 Correct 8 ms 7424 KB Output is correct
41 Correct 8 ms 7424 KB Output is correct
42 Correct 9 ms 7424 KB Output is correct
43 Correct 9 ms 7424 KB Output is correct
44 Correct 8 ms 7424 KB Output is correct
45 Correct 9 ms 7424 KB Output is correct
46 Correct 9 ms 7424 KB Output is correct
47 Correct 8 ms 7424 KB Output is correct
48 Correct 9 ms 7424 KB Output is correct
49 Correct 8 ms 7424 KB Output is correct
50 Correct 8 ms 7424 KB Output is correct
51 Correct 8 ms 7424 KB Output is correct
52 Correct 8 ms 7424 KB Output is correct
53 Correct 8 ms 7424 KB Output is correct
54 Correct 9 ms 7424 KB Output is correct
55 Correct 8 ms 7424 KB Output is correct
56 Correct 8 ms 7424 KB Output is correct
57 Correct 8 ms 7424 KB Output is correct
58 Correct 8 ms 7424 KB Output is correct
59 Correct 9 ms 7424 KB Output is correct
60 Correct 9 ms 7424 KB Output is correct
61 Correct 8 ms 7424 KB Output is correct
62 Correct 9 ms 7424 KB Output is correct
63 Correct 9 ms 7424 KB Output is correct
64 Correct 8 ms 7424 KB Output is correct
65 Correct 8 ms 7424 KB Output is correct
66 Correct 102 ms 30548 KB Output is correct
67 Correct 110 ms 30552 KB Output is correct
68 Correct 134 ms 28896 KB Output is correct
69 Correct 119 ms 30760 KB Output is correct
70 Correct 140 ms 25412 KB Output is correct
71 Runtime error 180 ms 58980 KB Execution killed with signal 11 (could be triggered by violating memory limits)
72 Halted 0 ms 0 KB -