#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][16];
long long cnt2[N][16];
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;
}
for(int j = 0;j < n;++j) {
for(auto c : g[j]) {
int bt = (1 << A[c]) ^ 15 ^ (1 << A[j]);
assert(__builtin_popcount(bt) == 2);
for(int w = 0;w < 4;++w) {
if(bt >> w & 1) {
res += cnt[c][(1 << w)];
cnt2[j][bt ^ (1 << w)] += cnt[c][(1 << w)];
}
}
}
}
for(int j = 0;j < n;++j) {
for(auto c : g[j]) res += cnt2[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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7372 KB |
Output is correct |
4 |
Correct |
4 ms |
7368 KB |
Output is correct |
5 |
Correct |
4 ms |
7372 KB |
Output is correct |
6 |
Correct |
4 ms |
7368 KB |
Output is correct |
7 |
Correct |
4 ms |
7376 KB |
Output is correct |
8 |
Correct |
4 ms |
7380 KB |
Output is correct |
9 |
Correct |
4 ms |
7380 KB |
Output is correct |
10 |
Correct |
4 ms |
7352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
11636 KB |
Output is correct |
2 |
Correct |
51 ms |
9828 KB |
Output is correct |
3 |
Correct |
241 ms |
90792 KB |
Output is correct |
4 |
Correct |
87 ms |
17840 KB |
Output is correct |
5 |
Correct |
48 ms |
7732 KB |
Output is correct |
6 |
Correct |
172 ms |
64232 KB |
Output is correct |
7 |
Correct |
264 ms |
90828 KB |
Output is correct |
8 |
Correct |
266 ms |
91636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7372 KB |
Output is correct |
4 |
Correct |
4 ms |
7368 KB |
Output is correct |
5 |
Correct |
4 ms |
7372 KB |
Output is correct |
6 |
Correct |
4 ms |
7368 KB |
Output is correct |
7 |
Correct |
4 ms |
7376 KB |
Output is correct |
8 |
Correct |
4 ms |
7380 KB |
Output is correct |
9 |
Correct |
4 ms |
7380 KB |
Output is correct |
10 |
Correct |
4 ms |
7352 KB |
Output is correct |
11 |
Correct |
67 ms |
11636 KB |
Output is correct |
12 |
Correct |
51 ms |
9828 KB |
Output is correct |
13 |
Correct |
241 ms |
90792 KB |
Output is correct |
14 |
Correct |
87 ms |
17840 KB |
Output is correct |
15 |
Correct |
48 ms |
7732 KB |
Output is correct |
16 |
Correct |
172 ms |
64232 KB |
Output is correct |
17 |
Correct |
264 ms |
90828 KB |
Output is correct |
18 |
Correct |
266 ms |
91636 KB |
Output is correct |
19 |
Correct |
67 ms |
14284 KB |
Output is correct |
20 |
Correct |
59 ms |
11860 KB |
Output is correct |
21 |
Correct |
245 ms |
95120 KB |
Output is correct |
22 |
Correct |
85 ms |
20740 KB |
Output is correct |
23 |
Correct |
52 ms |
10800 KB |
Output is correct |
24 |
Correct |
171 ms |
68020 KB |
Output is correct |
25 |
Correct |
251 ms |
95044 KB |
Output is correct |
26 |
Correct |
249 ms |
95896 KB |
Output is correct |
27 |
Correct |
56 ms |
13444 KB |
Output is correct |
28 |
Correct |
71 ms |
14988 KB |
Output is correct |
29 |
Correct |
253 ms |
95552 KB |
Output is correct |
30 |
Correct |
171 ms |
54564 KB |
Output is correct |
31 |
Correct |
174 ms |
54852 KB |
Output is correct |
32 |
Correct |
266 ms |
95488 KB |
Output is correct |
33 |
Correct |
4 ms |
7380 KB |
Output is correct |
34 |
Correct |
4 ms |
7380 KB |
Output is correct |
35 |
Correct |
4 ms |
7380 KB |
Output is correct |
36 |
Correct |
4 ms |
7380 KB |
Output is correct |
37 |
Correct |
4 ms |
7380 KB |
Output is correct |
38 |
Correct |
4 ms |
7380 KB |
Output is correct |
39 |
Correct |
4 ms |
7380 KB |
Output is correct |
40 |
Correct |
4 ms |
7376 KB |
Output is correct |
41 |
Correct |
4 ms |
7380 KB |
Output is correct |
42 |
Correct |
4 ms |
7380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
11 ms |
14804 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |