Submission #982241

# Submission time Handle Problem Language Result Execution time Memory
982241 2024-05-14T04:25:28 Z Jawad_Akbar_JJ Duathlon (APIO18_duathlon) C++17
0 / 100
1000 ms 1013104 KB
#include <iostream>
#include <vector>
 
using namespace std;
#define int long long
const int N = 1e5 + 10;
vector<int> nei[N];
bool seen[55][55][55];
int d[N],Seen[N], cur = 1, ver, ed, ch[N];
 
void dfs1(int u,vector<int> v){
	v.push_back(u);
 
	for (int i : v)
		seen[v[0]][u][i] = 1;
 
	for (int i : nei[u]){
		bool ns = 1;
		for (int j : v)
			if (j == i)
				ns = false;
		if (ns)
			dfs1(i,v);
	}
}
 
void sub1(int n){
	for (int i=1;i<=n;i++)
		dfs1(i,{});
 
	int ans = 0;
 
	for (int s = 1;s <= n; s++)
		for (int c = 1;c <= n; c++)
			for (int f = 1;f <= n; f++)
				if ( !(s == c or s == f or c == f) )
					ans += seen[s][f][c];
	cout<<ans<<'\n';
	exit(0);
}

void dfs2(int u){
	Seen[u] = cur;
	ver++;
	ed += d[u];
	for (int i : nei[u])
		if (Seen[i] != cur)
			dfs2(i);
}

void sub3(int n){
	int ans = 0;
	for (int i=1;i<=n;i++)
		if (Seen[i] != cur){
			ver = 0;
			ed = 0;
			dfs2(i);
			ed >>= 1;
			if (ed == ver - 1)
				for (int j=1;j<=ver;j++)
					ans += (j - 1) * (ver - j) * 2;
			else
				ans += ver * (ver-1) * (ver-2);
		}
	cout<<ans<<'\n';
	exit(0);
}
void dfs31(int u,int p = -1){
	ch[u] = 1;
	for (int i : nei[u])
		if (i != p)
			dfs31(i,u),ch[u] += ch[i];
}
int dfs32(int u,int p = -1){
	int S = 0,ans = 0;
	if (p != -1)
		S = ch[1] - ch[u];
	for (int i : nei[u])
		if (i != p)
			ans += ch[i] * S,S += ch[i];
	for (int i : nei[u])
		if (i != p)
			ans += dfs32(i,u);
	return ans;
}

void sub45(int n){
	dfs31(1);
	cout<<dfs32(1) * 2<<'\n';
	exit(0);
}

signed main(){
	int n,m;
	cin>>n>>m;
 
	int mx = 0;

	for (int i=1;i<=m;i++){
		int a,b;
		cin>>a>>b;
		nei[a].push_back(b);
		nei[b].push_back(a);
		d[a]++;
		d[b]++;
		mx = max(mx,max(d[a],d[b]));
	}

	if (m == n-1)
		sub45(n);

	if (mx <= 2)
 		sub3(n);
	 
 	if (n <= 10)
 		sub1(n);


}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 3 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 1 ms 4952 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 2 ms 4952 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 34 ms 4956 KB Output is correct
10 Execution timed out 1041 ms 5104 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 3 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 1 ms 4952 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 2 ms 4952 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 34 ms 4956 KB Output is correct
10 Execution timed out 1041 ms 5104 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 59 ms 10664 KB Output is correct
2 Correct 81 ms 11160 KB Output is correct
3 Execution timed out 1108 ms 1013104 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 5048 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 3 ms 4956 KB Output is correct
5 Correct 1 ms 5208 KB Output is correct
6 Correct 2 ms 5016 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Incorrect 1 ms 4956 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 58 ms 8020 KB Output is correct
2 Correct 60 ms 8020 KB Output is correct
3 Correct 58 ms 8080 KB Output is correct
4 Correct 63 ms 8236 KB Output is correct
5 Correct 58 ms 8020 KB Output is correct
6 Correct 84 ms 10944 KB Output is correct
7 Correct 62 ms 10296 KB Output is correct
8 Correct 99 ms 9808 KB Output is correct
9 Correct 76 ms 9232 KB Output is correct
10 Incorrect 67 ms 7412 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 5040 KB Output is correct
3 Incorrect 2 ms 4956 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 64 ms 8972 KB Output is correct
2 Correct 60 ms 8020 KB Output is correct
3 Incorrect 87 ms 10464 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 3 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 1 ms 4952 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 2 ms 4952 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 34 ms 4956 KB Output is correct
10 Execution timed out 1041 ms 5104 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 3 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 1 ms 4952 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 2 ms 4952 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 34 ms 4956 KB Output is correct
10 Execution timed out 1041 ms 5104 KB Time limit exceeded
11 Halted 0 ms 0 KB -