# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
563577 |
2022-05-17T15:09:36 Z |
Karliver |
Paths (BOI18_paths) |
C++17 |
|
371 ms |
241952 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[j][bt];
cnt3[j][(bt ^ (1 << A[j]))] += cnt2[j][bt];
}
}
}
// len = 4 case
for(int j = 0;j < n;++j) {
for(auto c : g[j]) res += cnt3[j][(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;
}
Compilation message
paths.cpp: In function 'void test_case()':
paths.cpp:85:12: warning: unused variable 'c' [-Wunused-variable]
85 | for(auto c : g[j]) for(int bt = 0;bt < 32;++bt) {
| ^
paths.cpp:94:12: warning: unused variable 'c' [-Wunused-variable]
94 | for(auto c : g[j]) res += cnt3[j][(1 << A[j])];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
7424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
108 ms |
13960 KB |
Output is correct |
2 |
Correct |
101 ms |
9956 KB |
Output is correct |
3 |
Correct |
370 ms |
240836 KB |
Output is correct |
4 |
Correct |
129 ms |
32704 KB |
Output is correct |
5 |
Correct |
50 ms |
7728 KB |
Output is correct |
6 |
Correct |
262 ms |
164404 KB |
Output is correct |
7 |
Correct |
360 ms |
241132 KB |
Output is correct |
8 |
Correct |
371 ms |
241952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
7424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Incorrect |
41 ms |
9096 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |