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;
typedef long long ll;
const long long maxn=1e6 + 10;
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
int n,m,k;
cin>>n>>m>>k;
int x[n];
vector<int>g[n];
for(int i=0;i<n;i++)
{
cin>>x[i];
x[i]--;
}
for(int i=0;i<m;i++)
{
int l,r;
cin>>l>>r;
l--;r--;
g[l].push_back(r);
g[r].push_back(l);
}
int ans=0;
for(int i=0;i<n;i++)
{
vector<int>c(5);
c[x[i]]=1;
queue<vector<int>>Q;
Q.push({i});
Q.push({1});
Q.push(c);
while(!Q.empty())
{
int teme=Q.front()[0];Q.pop();
int pat=Q.front()[0];Q.pop();
vector<int>co=Q.front();Q.pop();
if(pat<=k && co[0]<2 && co[1]<2 && co[2]<2 && co[3]<2)
{
///cout<<i<< " "<< pat<<" "<<teme<<" "<<co[0]<<endl;
ans++;
}
for(auto ax:g[teme])
{
int col=x[ax];
if(co[col]+1<2)
{
vector<int>pomcol;
pomcol=co;
pomcol[col]++;
Q.push({ax});
Q.push({pat+1});
Q.push(pomcol);
}
}
}
}
cout<<ans-n<<endl;
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... |