답안 #982343

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
982343 2024-05-14T07:07:45 Z Jawad_Akbar_JJ 철인 이종 경기 (APIO18_duathlon) C++17
0 / 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 p = -1){
	int 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)
			dfs32(i,u);
}

void sub45(int n){
	for (int i=1;i<=n;i++)
		if (!Seen[i]){
			dfs31(i);
			dfs32(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



*/
# 결과 실행 시간 메모리 Grader output
1 Runtime error 696 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 696 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1060 ms 890184 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 ms 4952 KB Output is correct
5 Correct 2 ms 4952 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Incorrect 2 ms 4956 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 8996 KB Output is correct
2 Correct 58 ms 8788 KB Output is correct
3 Correct 57 ms 9008 KB Output is correct
4 Correct 57 ms 8788 KB Output is correct
5 Correct 57 ms 8784 KB Output is correct
6 Correct 67 ms 11660 KB Output is correct
7 Correct 75 ms 11048 KB Output is correct
8 Correct 61 ms 10576 KB Output is correct
9 Correct 60 ms 9808 KB Output is correct
10 Incorrect 60 ms 8788 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Runtime error 624 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 9008 KB Output is correct
2 Correct 65 ms 8884 KB Output is correct
3 Runtime error 766 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 696 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 696 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -