This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
int cnt[N][3];
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][A[c]] += 1;
}
for(int j = 0;j < n;++j) {
for(auto c : g[j]) {
res += cnt[c][A[c] ^ 3 ^ 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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |