Submission #926981

# Submission time Handle Problem Language Result Execution time Memory
926981 2024-02-14T06:11:52 Z vjudge1 Paths (BOI18_paths) C++17
23 / 100
3000 ms 20048 KB
#include<bits/stdc++.h>

using namespace std;


const int N = (int)3e5+3;
const int MOD = (int)1e6+3;

int n, m, k, a[N], cnt[6];
vector<int> g[N];
bool used[6];
int ans;

void dfs(int v) {
	used[a[v]] = 1;
	ans++;
	for(auto to : g[v]) {
		if(!used[a[to]]) {
			dfs(to);
		}
	}
	used[a[v]] = 0;
}

int main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(0);
	cin >> n >> m >> k;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	for(int i = 1; i <= m; ++i) {
		int u, v;
		cin >> u >> v;
		if(a[u] == a[v]) {
			continue;
		}
		ans += 2;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	if(k > 3) {
	    ans=0;
		for(int i = 1; i <= n; ++i) {
			dfs(i);
		}
		cout << ans-n;
		return 0;
	}
	for(int i = 1; i <= n; ++i) {
		int cur = 0;
		memset(cnt, 0, sizeof(cnt));
		for(auto x : g[i]) {
			ans += 2*(cur-cnt[a[x]]);
			cur++;	
			cnt[a[x]]++;
		}
	}
	cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7260 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 2 ms 7260 KB Output is correct
4 Correct 2 ms 7260 KB Output is correct
5 Correct 2 ms 7260 KB Output is correct
6 Correct 2 ms 7260 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 2 ms 7260 KB Output is correct
9 Correct 2 ms 7260 KB Output is correct
10 Correct 2 ms 7260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 10300 KB Output is correct
2 Correct 34 ms 9308 KB Output is correct
3 Correct 100 ms 20048 KB Output is correct
4 Correct 52 ms 13392 KB Output is correct
5 Correct 37 ms 10844 KB Output is correct
6 Incorrect 71 ms 18428 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7260 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 2 ms 7260 KB Output is correct
4 Correct 2 ms 7260 KB Output is correct
5 Correct 2 ms 7260 KB Output is correct
6 Correct 2 ms 7260 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 2 ms 7260 KB Output is correct
9 Correct 2 ms 7260 KB Output is correct
10 Correct 2 ms 7260 KB Output is correct
11 Correct 41 ms 10300 KB Output is correct
12 Correct 34 ms 9308 KB Output is correct
13 Correct 100 ms 20048 KB Output is correct
14 Correct 52 ms 13392 KB Output is correct
15 Correct 37 ms 10844 KB Output is correct
16 Incorrect 71 ms 18428 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7260 KB Output is correct
2 Execution timed out 3017 ms 8536 KB Time limit exceeded
3 Halted 0 ms 0 KB -