Submission #837328

# Submission time Handle Problem Language Result Execution time Memory
837328 2023-08-25T09:36:19 Z sugartheanh Duathlon (APIO18_duathlon) C++14
0 / 100
59 ms 22340 KB
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;

ll n, m, N, ans, sz[200001];
vector<int> graph[100001], bcc_graph[200001], stck;
int low[100001], tin[100001], timer = 1, bccs = 1;

void dfs(int node, int parent = 0) {
	low[node] = tin[node] = timer++;
	stck.push_back(node);
	N++;
	for (int i : graph[node])
		if (i != parent) {
			if (tin[i]) low[node] = min(low[node], tin[i]);
			else {
				dfs(i, node);
				low[node] = min(low[node], low[i]);
				if (low[i] >= tin[node]) {
					bcc_graph[node].push_back(n + bccs);
					while (1) {
                        if(stck.empty())
                            break;
                        sz[n + bccs]++;
						//bcc_graph[n + bccs].push_back(stck.back());
						//cout<<n+bccs<<' '<<stck.back()<<'\n';
                        int res = stck.back();
						stck.pop_back();
                        if(res == i)
                            break;
					}
					//cout<<node<<' '<<n+bccs<<' '<<sz[n+bccs]<<'\n';
					bccs++;
				}
			}
		}
}

void dfs2(int node) {
	sz[node] += (node <= n);
	for (int i : bcc_graph[node]) {
        //cout<<node<<' '<<i<<'\n';
		dfs2(i);
		sz[node] += sz[i];
		//if (node > n)
        {
            ans -= (N - sz[i]) * sz[i] * (sz[i] - 1);
            //cout<<node<<' '<<(N - sz[i])<<' '<<i<<' '<<sz[i]<<'\n';
        }
	}
	//if (node > n)
    {
        ans -= sz[node] * (N - sz[node]) * (N - sz[node] - 1);
        //cout<<node<<' '<<sz[node]<<' '<<N-sz[node]<<'\n';
    }
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	while (m--) {
		int u, v;
		cin >> u >> v;
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	FOR(i, 1, n + 1) if (!tin[i]) {
		N = 0;
		dfs(i);
		ans += N * (N - 1) * (N - 2);
		dfs2(i);
	}
	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 22340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 7380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 50 ms 15000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 7388 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 59 ms 14940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7380 KB Output isn't correct
2 Halted 0 ms 0 KB -