# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
473380 | ZaZo_ | Paths (BOI18_paths) | C++14 | 104 ms | 21480 KiB |
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 ZAZO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
using namespace std;
int n , m , k;
int cols[300001],another[300001][6]={0};
vector<int>edges[300001];
set<vector<int>>ans;
void dfs(int node,set<int>path,vector<int>path2,int par)
{
if(path2.size()==0){
path2.push_back(node);
path.insert(cols[node]);
}
for(int i = 0 ; i < edges[node].size() ; i++)
{
if(edges[node][i]!=par && !path.count(cols[edges[node][i]]) && path.size()<=k ){
path.insert(cols[edges[node][i]]);
path2.push_back(edges[node][i]);
ans.insert(path2);
dfs(edges[node][i] , path , path2 , node);
path2.erase(path2.begin()+(path2.size()-1));
path.erase(cols[edges[node][i]]);
}
}
}
int32_t main() {
ZAZO
int an2=0;
cin >> n >> m >> k ;
vector<pair<int,int>>e;
for(int i = 1 ; i <= n ; i++)
{
cin>>cols[i];
}
for(int i = 0 ; i < m ; i++)
{
int u , v;
cin >> u >> v;
e.push_back({u,v});
if(cols[u]!=cols[v]) an2+=2;
edges[u].push_back(v);
edges[v].push_back(u);
another[u][cols[v]]++;
another[v][cols[u]]++;
}
//subtask 2
//k<=3 that's mean that maximum path = 3
if(k==1){
cout<<"0";
return 0;
}
if(k==2){
cout<<an2;
return 0;
}
int ans2=m*2;
for(int o=0;o<e.size();o++)
{
int i = e[o].first , j=e[o].second;
for(int p = 1 ; p <= k ; p ++)
{
if(p!=cols[i]&&p!=cols[j]&&cols[i]!=cols[j]&&i!=j)
{
// cout<<i<< " "<<j<<" "<<p<<" "<<another[i][p]+another[j][p]<<endl;
ans2+=another[i][p]+another[j][p];
}
}
}
cout<<ans2<<endl;
}
Compilation message (stderr)
# | 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... |