답안 #863351

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
863351 2023-10-20T05:28:47 Z maks007 Paths (BOI18_paths) C++14
23 / 100
3000 ms 773564 KB
// Bismi Allah
#include "bits/stdc++.h"

using namespace std;

#define int long long

signed main () {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m, k, ans = 0;
	cin >> n >> m >> k;
	vector <int> color(n), g[n], used(n), permutation;
	set <int> colorUsed;
	set <vector <int>> paths;
	vector <int> path;
	function <void(int, int)> dfs=[&](int v, int cur) {
		path.push_back(v);
		if(paths.count(path) == 0 && path.size() > 1) ans ++, paths.insert(path);
		if(cur == permutation.size() - 1) {
			path.pop_back();
			return;
		}
		used[v] = 1;
		for(auto u : g[v] ) {
			if(!used[u] && color[u] == permutation[cur+1]) dfs(u, cur + 1);
		}
		path.pop_back();
		used[v]=0;
	};
	
	for(int i = 0; i < n; i ++) cin >> color[i];
	for(int i = 0; i < m; i ++) {
		int u, v;
		cin >> u >> v;
		u --, v --;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	permutation.resize(k);
	for(int i = 0; i < k; i ++) permutation[i] = i + 1;
	do {
		for(int i = 0; i < n; i ++) {
			if(color[i] == permutation[0]) dfs(i, 0);
		}
	}while(next_permutation(permutation.begin(), permutation.end()));
	cout << ans;
	return 0;
}

Compilation message

paths.cpp: In lambda function:
paths.cpp:20:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |   if(cur == permutation.size() - 1) {
      |      ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3062 ms 773564 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Execution timed out 3062 ms 773564 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 3048 ms 700252 KB Time limit exceeded
3 Halted 0 ms 0 KB -