Submission #564071

# Submission time Handle Problem Language Result Execution time Memory
564071 2022-05-18T14:07:22 Z Karliver Paths (BOI18_paths) C++17
100 / 100
507 ms 245108 KB
#include <bits/stdc++.h>

using namespace std;
const int N = 3e5 + 10;


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#define sz(x) int(x.size())
template<typename T> void ckmi(T &a, T b) {
	a = (b < a ? b : a);
}

int n, m ,k;
vector<int> g[N];
long long cnt[N][32];
long long cnt2[N][32];
long long cnt3[N][32];
long long res = 0;
int A[N];
bool vis[N];
void dfs(int v, int mask = 0) {
	mask |= (1 << A[v]);
	res += 1;
	for(auto c : g[v]) {
		if((mask & (1 << A[c])))continue;
		dfs(c, mask);
	}
}
void test_case() {
	
	cin >> n >> m >> k;
	
	for(int j = 0;j < n;++j) cin >> A[j], --A[j];
	for(int i = 0;i < m;++i) {
		int a, b;
		cin >> a >> b;
		--a;--b;
		if(A[a] == A[b])continue;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	
	for(int j = 0;j < n;++j) res += int(g[j].size());
	
	for(int j = 0;j < n;++j) {
		for(auto c : g[j]) cnt[j][(1 << A[c])] += 1;
	}
	// len = 2 case
	for(int j = 0;j < n;++j) {
		for(auto c : g[j]) {
			int bt = (1 << A[c]) ^ 31 ^ (1 << A[j]);
			assert(__builtin_popcount(bt) == 3);
			for(int w = 0;w < 5;++w) {
				if(bt >> w & 1) {
					res += cnt[c][(1 << w)];
					cnt2[j][bt ^ (1 << w)] += cnt[c][(1 << w)];
				}
			}
				
		}
	}
	// len = 3 case
	for(int j = 0;j < n;++j) {
		for(auto c : g[j]) for(int bt = 0;bt < 32;++bt) {
			if(__builtin_popcount(bt) == 2 && (bt >> A[j] & 1)) {
				res += cnt2[c][bt];
				cnt3[j][(bt ^ (1 << A[j]))] += cnt2[c][bt];
				
			}
		}
	}
	// len = 4 case
	for(int j = 0;j < n;++j) {
		for(auto c : g[j]) res += cnt3[c][(1 << A[j])];
	}
	
	cout << res << '\n';
	
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tt;
	tt = 1;
	//cin >> tt;
	
	for(int p = 1;p <= tt;++p) {
		//cout << "Case #" << p << ": ";
		test_case();
	}
	
		
	return 0;
}
  
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 5 ms 7376 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 5 ms 7380 KB Output is correct
7 Correct 4 ms 7372 KB Output is correct
8 Correct 4 ms 7372 KB Output is correct
9 Correct 4 ms 7368 KB Output is correct
10 Correct 4 ms 7368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 16724 KB Output is correct
2 Correct 95 ms 12252 KB Output is correct
3 Correct 416 ms 244352 KB Output is correct
4 Correct 145 ms 35812 KB Output is correct
5 Correct 50 ms 10788 KB Output is correct
6 Correct 313 ms 167588 KB Output is correct
7 Correct 422 ms 244360 KB Output is correct
8 Correct 440 ms 245108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 5 ms 7376 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 5 ms 7380 KB Output is correct
7 Correct 4 ms 7372 KB Output is correct
8 Correct 4 ms 7372 KB Output is correct
9 Correct 4 ms 7368 KB Output is correct
10 Correct 4 ms 7368 KB Output is correct
11 Correct 119 ms 16724 KB Output is correct
12 Correct 95 ms 12252 KB Output is correct
13 Correct 416 ms 244352 KB Output is correct
14 Correct 145 ms 35812 KB Output is correct
15 Correct 50 ms 10788 KB Output is correct
16 Correct 313 ms 167588 KB Output is correct
17 Correct 422 ms 244360 KB Output is correct
18 Correct 440 ms 245108 KB Output is correct
19 Correct 109 ms 16764 KB Output is correct
20 Correct 95 ms 12220 KB Output is correct
21 Correct 432 ms 244260 KB Output is correct
22 Correct 142 ms 35844 KB Output is correct
23 Correct 53 ms 10784 KB Output is correct
24 Correct 303 ms 167564 KB Output is correct
25 Correct 416 ms 244408 KB Output is correct
26 Correct 432 ms 245044 KB Output is correct
27 Correct 103 ms 13772 KB Output is correct
28 Correct 141 ms 19072 KB Output is correct
29 Correct 505 ms 244748 KB Output is correct
30 Correct 328 ms 129088 KB Output is correct
31 Correct 362 ms 129324 KB Output is correct
32 Correct 507 ms 244648 KB Output is correct
33 Correct 4 ms 7380 KB Output is correct
34 Correct 4 ms 7408 KB Output is correct
35 Correct 4 ms 7380 KB Output is correct
36 Correct 4 ms 7380 KB Output is correct
37 Correct 6 ms 7380 KB Output is correct
38 Correct 4 ms 7368 KB Output is correct
39 Correct 7 ms 7380 KB Output is correct
40 Correct 4 ms 7380 KB Output is correct
41 Correct 4 ms 7320 KB Output is correct
42 Correct 5 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7300 KB Output is correct
2 Correct 43 ms 9556 KB Output is correct
3 Correct 46 ms 9568 KB Output is correct
4 Correct 173 ms 86520 KB Output is correct
5 Correct 121 ms 86524 KB Output is correct
6 Correct 158 ms 86800 KB Output is correct
7 Correct 49 ms 9548 KB Output is correct
8 Correct 135 ms 86620 KB Output is correct
9 Correct 120 ms 86892 KB Output is correct
10 Correct 144 ms 87644 KB Output is correct
11 Correct 96 ms 47884 KB Output is correct
12 Correct 114 ms 68040 KB Output is correct
13 Correct 98 ms 48088 KB Output is correct
14 Correct 150 ms 86748 KB Output is correct
15 Correct 175 ms 86820 KB Output is correct
16 Correct 4 ms 7320 KB Output is correct
17 Correct 4 ms 7380 KB Output is correct
18 Correct 4 ms 7376 KB Output is correct
19 Correct 4 ms 7380 KB Output is correct
20 Correct 4 ms 7372 KB Output is correct
21 Correct 4 ms 7380 KB Output is correct
22 Correct 5 ms 7380 KB Output is correct
23 Correct 4 ms 7372 KB Output is correct
24 Correct 4 ms 7348 KB Output is correct
25 Correct 5 ms 7376 KB Output is correct