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>
#define stop system("pause")
#define INP freopen("input.txt","r",stdin)
#define OUTP freopen("solve1.txt","w",stdout)
#define int long long
using namespace std;
typedef long long ll;
vector<vector<int> > v;
const int maxn = 4e5;
int color[maxn];
bool c_used[maxn];
bool used[maxn];
int cnt[maxn][5];
int n,m,k;
bool is_good(int mask,int x){
return !(mask&(1<<x));
}
int ans = 0 ;
void dfs(int u,int mask){
if(mask)ans++;
mask|=(1<<color[u]);
for(int i(0); i < v[u].size();i++){
int to = v[u][i];
if(!is_good(mask,color[to]))continue;
dfs(to,mask);
}
}
void solve_1(){
int ans = 0;
for(int i(0); i < n;i++){
for(int j(0); j < v[i].size();j++){
int to = v[i][j];
ans++;
for(int z(1); z <= 3;z++){
if(z!=color[i]&&z!=color[to])ans+=cnt[to][z];
}
}
}
cout << ans;
exit(0);
}
main()
{
ios_base::sync_with_stdio(0);
cin >> n >> m >> k;
v.resize(n+2);
for(int i(0); i < n;i++)cin >> color[i];
for(int i(0); i < m;i++){
int a,b; cin >> a >> b;
a--;b--;
if(color[a] == color[b])continue;
cnt[a][color[b]]++;
cnt[b][color[a]]++;
//cout << "good " << a+1 << ' ' << b+1 << endl;
v[a].push_back(b);
v[b].push_back(a);
}
if(k == 3)solve_1();
for(int i(0); i < n;i++){
dfs(i,0);
}
cout << ans;
return 0;
}
/*
*/
Compilation message (stderr)
paths.cpp: In function 'void dfs(long long int, long long int)':
paths.cpp:27:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i(0); i < v[u].size();i++){
~~^~~~~~~~~~~~~
paths.cpp: In function 'void solve_1()':
paths.cpp:37:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j(0); j < v[i].size();j++){
~~^~~~~~~~~~~~~
paths.cpp: At global scope:
paths.cpp:49:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
# | 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... |