답안 #413826

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
413826 2021-05-29T14:50:14 Z ak2006 Paths (BOI18_paths) C++14
0 / 100
247 ms 236228 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vc = vector<char>;
using vvc = vector<vc>;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
void setIO()
{
	fast;
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
}
int n = 3e5 + 5,m = 3e5 + 5,k = 5;
vvi adj(n);
vi col(n);
vvl dp(n,vl(1<<k));
vvb vis(n,vb(1<<k));
void dfs(int u,int mask)
{
	if (vis[u][mask])return;
	int mask2 = mask |  (1<<col[u]);
	dp[u][mask] = 1;
	vis[u][mask] = 1;
	for (int v:adj[u]){
		if ((mask2 & (1<<col[v])))continue;
		dfs(v,mask2);
		dp[u][mask] += dp[v][mask2];
	}
}
int main()
{
	setIO();
	cin>>n>>m>>k;
	for (int i = 1;i<=n;i++){cin>>col[i];col[i]--;}
	while (m--){
		int u,v;
		cin>>u>>v;
		adj[u].pb(v),adj[v].pb(u);
	}
	ll ans = 0;
	for (int i = 1;i<=n;i++){
		for (int mask = 0;mask < (1<<k);mask++){
			if (mask & (1<<col[i]))continue;
			dfs(i,mask);
			if (mask == 0)ans += dp[i][0] - 1;
		}
	}
	cout<<ans;
	return 0;
}

Compilation message

paths.cpp: In function 'void setIO()':
paths.cpp:18:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |  freopen("input.txt","r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
paths.cpp:19:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  freopen("output.txt","w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 241 ms 236228 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 247 ms 236220 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 241 ms 236228 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 230 ms 236224 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -