Submission #982347

# Submission time Handle Problem Language Result Execution time Memory
982347 2024-05-14T07:12:17 Z Jawad_Akbar_JJ Duathlon (APIO18_duathlon) C++17
23 / 100
1000 ms 1048576 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){
	Seen[u] = true;
	ch[u] = 1;
	for (int i : nei[u])
		if (i != p)
			dfs31(i,u),ch[u] += ch[i];
}
int ans = 0;
void dfs32(int u,int rt,int p = -1){
	int S = ch[rt] - 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)
			dfs32(i,rt,u);
}

void sub45(int n){
	for (int i=1;i<=n;i++)
		if (!Seen[i]){
			dfs31(i);
			dfs32(i,i);
		}
	cout<<ans * 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 (mx <= 2)
 	// 	sub3(n);

 	// if (m == n-1)
		sub45(n);
		 
 	// if (n <= 10)
 	// 	sub1(n);



}

/*

16 15
1 2
1 3
3 4
3 5
3 6
5 7
5 8
5 9
2 10
2 11
11 12
11 13
13 15
13 16
13 14



*/
# Verdict Execution time Memory Grader output
1 Runtime error 688 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 688 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1057 ms 854064 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 2 ms 5212 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 2 ms 5040 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 3 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 5044 KB Output is correct
16 Correct 1 ms 4952 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 2 ms 4952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 8820 KB Output is correct
2 Correct 58 ms 8784 KB Output is correct
3 Correct 61 ms 8968 KB Output is correct
4 Correct 65 ms 9012 KB Output is correct
5 Correct 58 ms 8788 KB Output is correct
6 Correct 62 ms 11604 KB Output is correct
7 Correct 62 ms 11092 KB Output is correct
8 Correct 61 ms 10580 KB Output is correct
9 Correct 60 ms 10016 KB Output is correct
10 Correct 61 ms 8788 KB Output is correct
11 Correct 58 ms 10064 KB Output is correct
12 Correct 58 ms 10168 KB Output is correct
13 Correct 59 ms 10064 KB Output is correct
14 Correct 52 ms 9832 KB Output is correct
15 Correct 49 ms 9556 KB Output is correct
16 Correct 28 ms 8312 KB Output is correct
17 Correct 50 ms 10448 KB Output is correct
18 Correct 51 ms 10308 KB Output is correct
19 Correct 49 ms 10440 KB Output is correct
20 Correct 54 ms 10236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Runtime error 640 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 63 ms 8816 KB Output is correct
2 Correct 57 ms 8748 KB Output is correct
3 Runtime error 731 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 688 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 688 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -