답안 #243531

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
243531 2020-07-01T09:44:20 Z AMO5 Paths (BOI18_paths) C++17
100 / 100
584 ms 97272 KB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;
const int mxn=300111;
int n,m,k;
int color[mxn];
ll dp[mxn][32];
ll ans = 0ll;
vi adj[mxn];

ll solve(int u, int use){
	if(dp[u][use]!=-1ll)return dp[u][use];
	if((use>>color[u])&1){
		return dp[u][use]=0ll;
	}
	int bt = use;
	use |= 1<<color[u];
	ll res = 1ll;
	for(int v:adj[u]){
		res += solve(v,use);
	}
	if(bt==0)return dp[u][bt]=res-1;
	return dp[u][bt]=res;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	memset(dp,-1ll,sizeof(dp));
	cin >> n >> m >> k;
	for(int i=0; i<n; i++){
		cin >> color[i];
		color[i]--;
	}
	int a,b;
	for(int i=0; i<m; i++){
		cin >> a >> b;
		a--; b--;
		adj[a].eb(b);
		adj[b].eb(a);
	}
	for(int i=0; i<n; i++){
		ans += solve(i,0);
	}
	cout << ans << '\n';
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 82688 KB Output is correct
2 Correct 52 ms 82552 KB Output is correct
3 Correct 49 ms 82680 KB Output is correct
4 Correct 47 ms 82560 KB Output is correct
5 Correct 48 ms 82552 KB Output is correct
6 Correct 49 ms 82552 KB Output is correct
7 Correct 48 ms 82556 KB Output is correct
8 Correct 48 ms 82560 KB Output is correct
9 Correct 48 ms 82556 KB Output is correct
10 Correct 46 ms 82552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 143 ms 89080 KB Output is correct
2 Correct 108 ms 88312 KB Output is correct
3 Correct 507 ms 96760 KB Output is correct
4 Correct 171 ms 90488 KB Output is correct
5 Correct 177 ms 90488 KB Output is correct
6 Correct 308 ms 94572 KB Output is correct
7 Correct 523 ms 96888 KB Output is correct
8 Correct 439 ms 97208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 82688 KB Output is correct
2 Correct 52 ms 82552 KB Output is correct
3 Correct 49 ms 82680 KB Output is correct
4 Correct 47 ms 82560 KB Output is correct
5 Correct 48 ms 82552 KB Output is correct
6 Correct 49 ms 82552 KB Output is correct
7 Correct 48 ms 82556 KB Output is correct
8 Correct 48 ms 82560 KB Output is correct
9 Correct 48 ms 82556 KB Output is correct
10 Correct 46 ms 82552 KB Output is correct
11 Correct 143 ms 89080 KB Output is correct
12 Correct 108 ms 88312 KB Output is correct
13 Correct 507 ms 96760 KB Output is correct
14 Correct 171 ms 90488 KB Output is correct
15 Correct 177 ms 90488 KB Output is correct
16 Correct 308 ms 94572 KB Output is correct
17 Correct 523 ms 96888 KB Output is correct
18 Correct 439 ms 97208 KB Output is correct
19 Correct 126 ms 89080 KB Output is correct
20 Correct 118 ms 88312 KB Output is correct
21 Correct 471 ms 96760 KB Output is correct
22 Correct 171 ms 90488 KB Output is correct
23 Correct 151 ms 90488 KB Output is correct
24 Correct 319 ms 94572 KB Output is correct
25 Correct 459 ms 96580 KB Output is correct
26 Correct 420 ms 97272 KB Output is correct
27 Correct 126 ms 88312 KB Output is correct
28 Correct 138 ms 89832 KB Output is correct
29 Correct 584 ms 96728 KB Output is correct
30 Correct 414 ms 93036 KB Output is correct
31 Correct 432 ms 93040 KB Output is correct
32 Correct 567 ms 96760 KB Output is correct
33 Correct 47 ms 82552 KB Output is correct
34 Correct 51 ms 82552 KB Output is correct
35 Correct 47 ms 82552 KB Output is correct
36 Correct 47 ms 82552 KB Output is correct
37 Correct 47 ms 82552 KB Output is correct
38 Correct 50 ms 82552 KB Output is correct
39 Correct 47 ms 82536 KB Output is correct
40 Correct 47 ms 82552 KB Output is correct
41 Correct 47 ms 82552 KB Output is correct
42 Correct 46 ms 82552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 82552 KB Output is correct
2 Correct 71 ms 84412 KB Output is correct
3 Correct 71 ms 84344 KB Output is correct
4 Correct 144 ms 87032 KB Output is correct
5 Correct 104 ms 87792 KB Output is correct
6 Correct 207 ms 87160 KB Output is correct
7 Correct 73 ms 84344 KB Output is correct
8 Correct 179 ms 87160 KB Output is correct
9 Correct 115 ms 87792 KB Output is correct
10 Correct 144 ms 87924 KB Output is correct
11 Correct 168 ms 85748 KB Output is correct
12 Correct 117 ms 86896 KB Output is correct
13 Correct 147 ms 85948 KB Output is correct
14 Correct 208 ms 87160 KB Output is correct
15 Correct 157 ms 87160 KB Output is correct
16 Correct 46 ms 82552 KB Output is correct
17 Correct 47 ms 82560 KB Output is correct
18 Correct 53 ms 82552 KB Output is correct
19 Correct 47 ms 82552 KB Output is correct
20 Correct 49 ms 82556 KB Output is correct
21 Correct 46 ms 82552 KB Output is correct
22 Correct 47 ms 82552 KB Output is correct
23 Correct 48 ms 82552 KB Output is correct
24 Correct 54 ms 82552 KB Output is correct
25 Correct 46 ms 82552 KB Output is correct