답안 #927218

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
927218 2024-02-14T12:39:58 Z vjudge1 Paths (BOI18_paths) C++17
20 / 100
375 ms 79644 KB
#include <bits/stdc++.h>

using namespace std;

#define all(a) a.begin(),a.end()
#define pb push_back
#define vt vector
#define endl '\n'
typedef long long ll;

const ll mod=1e9+7;
const ll inf=1e9+7;
const int N=5e5+4;

int n,m,k,a[N],used[N];
ll res=0;
ll dp[(1<<6)][N];
vt<int>g[N];

void solve(){
	cin>>n>>m>>k;
	for(int i=1; i<=n; ++i) {
		cin>>a[i];
		a[i]--;
		dp[(1<<a[i])][i]=1;
	}
	for(int i=1; i<=m; ++i){
		int u,v;
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	for(int mask=1; mask<(1<<k); ++mask){
		for(int v=1; v<=n; ++v){
			for(int to:g[v]){
				if(a[to]!=a[v] && ((mask>>a[to])&1)==0) dp[mask|(1<<a[to])][v]+=dp[mask][v];
			}
		}
	}
	ll ans=0;
	for(int mask=1; mask<(1<<k); ++mask){
	for(int v=1; v<=n; ++v){
		ans+=dp[mask][v];
	}
	}
	cout<<ans-n<<endl;
}
			
int main(){
	int tt=1;
	//cin>>tt;
	while(tt--) {
		solve();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 45716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 131 ms 35032 KB Output is correct
2 Correct 114 ms 32832 KB Output is correct
3 Correct 325 ms 52516 KB Output is correct
4 Correct 142 ms 25428 KB Output is correct
5 Correct 132 ms 21236 KB Output is correct
6 Correct 231 ms 46732 KB Output is correct
7 Correct 308 ms 52304 KB Output is correct
8 Correct 375 ms 53332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 45716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 64092 KB Output is correct
2 Incorrect 73 ms 79644 KB Output isn't correct
3 Halted 0 ms 0 KB -