답안 #513741

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
513741 2022-01-17T13:30:54 Z ahmeteren Paths (BOI18_paths) C++17
0 / 100
12 ms 14868 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int N = 3e5 + 5;

ll dp[N][(1 << 5)], c[N];
vector<int> vec[N];

ll dfs(int node, int mask)
{
	if((mask & (1 << c[node])) == 0)
		return 0;
	if(mask == (1 << c[node]))
		return 1;
	if(dp[node][mask] != -1)
		return dp[node][mask];

	dp[node][mask] = 0;

	for(auto to : vec[node])
	{
		dp[node][mask] += dfs(to, mask ^ (1 << c[node]));
	}

	return dp[node][mask];
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	#ifndef ONLINE_JUDGE
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif

	int n, m, k;
	cin >> n >> m >> k;

	for(int i = 1; i <= n; i++)
	{
		cin >> c[i];
		c[i]--;
	}

	for(int i = 1; i <= m; i++)
	{
		int u, v;
		cin >> u >> v;

		vec[u].push_back(v);
		vec[v].push_back(u);
	}

	memset(dp, -1, sizeof(dp));

	ll cevap = 0;

	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j < (1 << k); j++)
		{
			cevap += dfs(i, j);
		}
	}

	cout << cevap - n << '\n';
	return 0;
}

Compilation message

paths.cpp: In function 'int main()':
paths.cpp:35:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |   freopen("in.txt", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
paths.cpp:36:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |   freopen("out.txt", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 14860 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 14868 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 14860 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 14796 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -