Submission #110932

# Submission time Handle Problem Language Result Execution time Memory
110932 2019-05-13T07:47:50 Z Just_Solve_The_Problem Duathlon (APIO18_duathlon) C++11
0 / 100
151 ms 17568 KB
#include <bits/stdc++.h>

#define ll long long

using namespace std;

const int N = (int)1e5 + 7;

ll ans;

vector<int> gr[N], ngr[N];
vector<int> order;
int n, m;
int used[N], col[N], tin[N], tout[N], fup[N];
int head[N], sz[N], ssz[N];
int cl, tiktak;

void precalc(int v, int pr = 0) {
	used[v] = 1;
	tin[v] = fup[v] = ++tiktak;
	for (int to : gr[v]) {
		if (to == pr) continue;
		if (!used[to]) {
			precalc(to, v);
			fup[v] = min(fup[v], fup[to]);
		} else {
			fup[v] = min(fup[v], tin[to]);
		}
		if (tin[v] >= fup[to]) {
			// not bridge
			col[v] = col[to];
		} 
	}
	if (!col[v]) col[v] = ++cl;
	tout[v] = tiktak;
	sz[col[v]]++;
	head[col[v]] = v;
}

int root;

void predfs(int v, int pr) {
	ssz[v] = sz[v];
	for (int to : ngr[v]) {
		if (to == pr) continue;
		predfs(to, v);
		ssz[v] += ssz[to];
	}
}

void dfs(int v, int pr) {
	used[v] = 1;
	for (int to : ngr[v]) {
		if (to == pr) continue;
		ans += (ssz[root]  - ssz[v]) * 2LL * ssz[to];
		dfs(to, v);
	}
	ans += sz[v] * (sz[v] - 1) * (sz[v] - 2);
	ans += (ssz[root] - sz[v]) * 2LL * ((sz[v] - 1) + (sz[v] - 1) * 1LL * (sz[v] - 2));
}

main() {
	scanf("%d %d", &n, &m);
	for (int i = 1, u, v; i <= m; i++) {
		scanf("%d %d", &u, &v);
		gr[u].push_back(v);
		gr[v].push_back(u);
	}
	for (int i = 1; i <= n; i++) {
		if (!used[i]) {
			precalc(i);
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int to : gr[i]) {
			if (col[i] != col[to]) {
				ngr[col[i]].push_back(col[to]);
			}
		}
	}
	memset(used, 0, sizeof used);
	for (int i = 1; i <= cl; i++) {
		if (!used[i]) {
			root = i;
			predfs(i, i);
			dfs(i, i);
		}
	}
	cout << ans;
}

Compilation message

count_triplets.cpp:62:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:63:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
count_triplets.cpp:65:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &u, &v);
   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 5376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 5376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 129 ms 17568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 5504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 131 ms 15640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 5504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 151 ms 15608 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 5376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 5376 KB Output isn't correct
2 Halted 0 ms 0 KB -