Submission #50061

# Submission time Handle Problem Language Result Execution time Memory
50061 2018-06-07T08:53:50 Z tmwilliamlin168 Duathlon (APIO18_duathlon) C++14
0 / 100
126 ms 43980 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const int mxN=1e5;
int n, m, dt=1, tin[mxN], low[mxN], st[mxN], sth, bccI;
vector<int> adj1[mxN], adj2[2*mxN];
ll sz[mxN], n2, ans;

void dfs1(int u, int p) {
	tin[u]=low[u]=dt++;
	st[sth++]=u;
	++n2;
	for(int v : adj1[u]) {
		if(!tin[v]) {
			dfs1(v, u);
			low[u]=min(low[v], low[u]);
			if(low[v]>=tin[u]) {
				adj2[u].push_back(bccI+n);
				while(st[sth-1]!=u)
					adj2[bccI+n].push_back(st[--sth]);
				++bccI;
			}
		} else if(v!=p)
			low[u]=min(tin[v], low[u]);
	}
}

void dfs2(int u, int p) {
//	cout << "d21 " << u << " " << p << endl;
	sz[u]=u<n;
	for(int v : adj2[u]) {
		dfs2(v, u);
		sz[u]+=sz[v];
		if(u>=n)
			ans-=(adj2[u].size()-(p==-1))*sz[v]*(sz[v]-1);
	}
	if(u>=n)
		ans-=adj2[u].size()*(n2-sz[u])*(n2-sz[u]-1);
//	cout << "d29 " << u << " " << p << endl;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	while(m--) {
		int u, v;
		cin >> u >> v, --u, --v;
		adj1[u].push_back(v);
		adj1[v].push_back(u);
	}
	for(int i=0; i<n; ++i) {
		if(tin[i])
			continue;
		dfs1(0, -1);
		ans+=n2*(n2-1)*(n2-2);
		dfs2(0, -1);
		n2=0;
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 7416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 7416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 126 ms 43980 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 43980 KB Output is correct
2 Correct 9 ms 43980 KB Output is correct
3 Correct 9 ms 43980 KB Output is correct
4 Correct 9 ms 43980 KB Output is correct
5 Correct 9 ms 43980 KB Output is correct
6 Correct 9 ms 43980 KB Output is correct
7 Correct 11 ms 43980 KB Output is correct
8 Correct 7 ms 43980 KB Output is correct
9 Correct 8 ms 43980 KB Output is correct
10 Incorrect 9 ms 43980 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 110 ms 43980 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 43980 KB Output is correct
2 Correct 8 ms 43980 KB Output is correct
3 Incorrect 9 ms 43980 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 119 ms 43980 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 7416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 7416 KB Output isn't correct
2 Halted 0 ms 0 KB -