답안 #610985

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
610985 2022-07-28T22:23:33 Z GusterGoose27 철인 이종 경기 (APIO18_duathlon) C++11
0 / 100
206 ms 55876 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAXN = 1e5;
vector<int> edges[MAXN];
vector<int> bcc_graph[2*MAXN];
int n, m;
ll csize;
int num_bcc = 0;
int depth[MAXN];
int lp[MAXN];
bool vis[MAXN];
vector<int> stck;
ll sz[MAXN];
ll ans = 0;

void make_bcc(int cur, int p = -1) {
	lp[cur] = depth[cur];
	vis[cur] = 1;
	stck.push_back(cur);
	csize++;
	for (int next: edges[cur]) {
		if (next == p) continue;
		if (vis[next]) {
			lp[cur] = min(lp[cur], depth[next]);
			continue;
		}
		depth[next] = 1+depth[cur];
		make_bcc(next, cur);
		lp[cur] = min(lp[cur], lp[next]);
		if (lp[next] >= depth[cur]) {
			int cur_bcc = n+(num_bcc++);
			bcc_graph[cur].push_back(cur_bcc);
			bcc_graph[cur_bcc].push_back(cur);
			while (stck.back() != cur) {
				int b = stck.back();
				stck.pop_back();
				bcc_graph[b].push_back(cur_bcc);
				bcc_graph[cur_bcc].push_back(b);
			}
		}
	}
}

void make_ans(int cur, int p = -1) {
	if (cur < n) sz[cur]++;
	for (int next: bcc_graph[cur]) {
		if (next == p) continue;
		make_ans(next, cur);
		sz[cur] += sz[next];
		if (cur >= n) ans -= sz[next]*(sz[next]-1)*(bcc_graph[cur].size()-1); // can't include this articulation point as a midpoint
	}
	ll out_sz = n-sz[cur];
	if (cur >= n) ans -= out_sz*(out_sz-1)*(bcc_graph[cur].size()-1);
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int x, y; cin >> x >> y; x--; y--;
		edges[x].push_back(y);
		edges[y].push_back(x);
	}
	for (int i = 0; i < n; i++) {
		if (vis[i]) continue;
		csize = 0;
		make_bcc(i);
		ans += csize*(csize-1)*(csize-2);
		make_ans(i);
	}
	cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 86 ms 55876 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7508 KB Output is correct
2 Correct 4 ms 7508 KB Output is correct
3 Correct 5 ms 7516 KB Output is correct
4 Correct 4 ms 7520 KB Output is correct
5 Correct 4 ms 7508 KB Output is correct
6 Correct 5 ms 7508 KB Output is correct
7 Correct 4 ms 7588 KB Output is correct
8 Correct 4 ms 7508 KB Output is correct
9 Correct 5 ms 7508 KB Output is correct
10 Incorrect 4 ms 7508 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 206 ms 38812 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7508 KB Output is correct
2 Correct 4 ms 7636 KB Output is correct
3 Incorrect 4 ms 7392 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 91 ms 38812 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7380 KB Output isn't correct
2 Halted 0 ms 0 KB -