Submission #716410

# Submission time Handle Problem Language Result Execution time Memory
716410 2023-03-30T04:34:19 Z ajab_01 Paths (BOI18_paths) C++17
43 / 100
3000 ms 27716 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long

const int N = 3e5 + 5;
vector<pair<int , int> > edge;
vector<int> g[N];
int C[N] , n , m , k;
int ans;

void cal2(){
	for(auto i : edge){
		int u = i.first , v = i.second;
		if(C[u] != C[v])
			ans++;
	}
}

void cal3(){
	for(int i = 1 ; i <= n ; i++){
		int cnt[6];
		memset(cnt , 0 , sizeof(cnt));
		for(int j : g[i]){
			if(C[j] == C[i]) continue;
			cnt[C[j]]++;
		}
		for(int i = 1 ; i <= 5 ; i++)
			for(int j = i + 1 ; j <= 5 ; j++)
				ans += cnt[i] * cnt[j];
	}
}

void cal4(){
	for(auto i : edge){
		int u = i.first , v = i.second;
		if(C[u] == C[v]) continue;
		int cnt1[6] , mx = 0;
		memset(cnt1 , 0 , sizeof(cnt1));
		for(int j : g[u]){
			if(C[j] == C[u] || C[j] == C[v]) continue;
			cnt1[C[j]]++;
		}
		int cnt2[6];
		memset(cnt2 , 0 , sizeof(cnt2));
		for(int j : g[v]){
			if(C[j] == C[u] || C[j] == C[v]) continue;
			cnt2[C[j]]++;
		}
		for(int i = 1 ; i <= 5 ; i++){
			for(int j = i + 1 ; j <= 5 ; j++){
				ans += cnt1[i] * cnt2[j];
				ans += cnt1[j] * cnt2[i];
			}
		}
	}
}

int32_t main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> m >> k;
	for(int i = 1 ; i <= n ; i++)
		cin >> C[i];

	for(int i = 1 ; i <= m ; i++){
		int u , v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
		edge.push_back({u , v});
	}

	if(k == 1){
		cout << ans * 2 << '\n';
		return 0;
	}

	cal2();

	if(k == 2){
		cout << ans * 2 << '\n';
		return 0;
	}

	cal3();

	if(k == 3){
		cout << ans * 2 << '\n';
		return 0;
	}

	cal4();

	if(k == 4){
		cout << ans * 2 << '\n';
		return 0;
	}

	// cal5();

	// cout << ans * 2 << '\n';
	return 0;
}

Compilation message

paths.cpp: In function 'void cal4()':
paths.cpp:38:17: warning: unused variable 'mx' [-Wunused-variable]
   38 |   int cnt1[6] , mx = 0;
      |                 ^~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7492 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7284 KB Output is correct
8 Correct 5 ms 7252 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
10 Correct 4 ms 7252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 21332 KB Output is correct
2 Correct 58 ms 22700 KB Output is correct
3 Correct 248 ms 27216 KB Output is correct
4 Correct 98 ms 23216 KB Output is correct
5 Correct 93 ms 23192 KB Output is correct
6 Correct 158 ms 25048 KB Output is correct
7 Correct 261 ms 27312 KB Output is correct
8 Correct 207 ms 27716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7492 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7284 KB Output is correct
8 Correct 5 ms 7252 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
10 Correct 4 ms 7252 KB Output is correct
11 Correct 79 ms 21332 KB Output is correct
12 Correct 58 ms 22700 KB Output is correct
13 Correct 248 ms 27216 KB Output is correct
14 Correct 98 ms 23216 KB Output is correct
15 Correct 93 ms 23192 KB Output is correct
16 Correct 158 ms 25048 KB Output is correct
17 Correct 261 ms 27312 KB Output is correct
18 Correct 207 ms 27716 KB Output is correct
19 Correct 73 ms 21304 KB Output is correct
20 Correct 75 ms 22636 KB Output is correct
21 Correct 237 ms 27448 KB Output is correct
22 Correct 97 ms 23216 KB Output is correct
23 Correct 96 ms 23284 KB Output is correct
24 Correct 149 ms 25120 KB Output is correct
25 Correct 241 ms 27312 KB Output is correct
26 Correct 214 ms 27680 KB Output is correct
27 Correct 2384 ms 22732 KB Output is correct
28 Correct 421 ms 22844 KB Output is correct
29 Correct 322 ms 27312 KB Output is correct
30 Execution timed out 3070 ms 25440 KB Time limit exceeded
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -