Submission #952042

# Submission time Handle Problem Language Result Execution time Memory
952042 2024-03-23T04:09:51 Z mocha Paths (BOI18_paths) C++14
0 / 100
3000 ms 12392 KB
#include <bits/stdc++.h>
using namespace std;
const int mx = 3e5+5;

int n, m, K;
int a[mx];
vector<int> g[mx];
bool vis[mx];
set<int> st;
long long cnt;
int arr[mx];

void dfs(int x) {
	vis[x] = 1;
	st.insert(a[x]);
	cnt++;
	arr[st.size()]++;
	for (int i:g[x]) {
		if (!st.count(a[i]) and !vis[i]) {
			dfs(i);
		}
	}
	vis[x] = 0;
	st.erase(a[x]);
}

int main() {
	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;
		g[u].push_back(v);
		g[v].push_back(u);
	}

	for (int i=1;i<=n;i++) {
		dfs(i);
	}
	cout << cnt - n << "\n";
	for (int i=1;i<=K;i++) {
		cout << arr[i] << " ";
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3061 ms 12392 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8540 KB Output isn't correct
2 Halted 0 ms 0 KB -