# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
473390 |
2021-09-15T13:00:33 Z |
ZaZo_ |
Paths (BOI18_paths) |
C++14 |
|
329 ms |
41788 KB |
#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]]++;
}
if(n<=100 && m<=100 && k<=4)
{
//ba7sb kol path w dah bya5od time 3aly f 7ygeeb awel subtask
for(int i = 1 ; i <= n ; i++)
{
dfs(i,{},{},-1);
}
cout<<ans.size()<<endl;
}
else
{
//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=an2;
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
paths.cpp: In function 'void dfs(long long int, std::set<long long int>, std::vector<long long int>, long long int)':
paths.cpp:15:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | for(int i = 0 ; i < edges[node].size() ; i++)
| ~~^~~~~~~~~~~~~~~~~~~~
paths.cpp:17:79: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
17 | if(edges[node][i]!=par && !path.count(cols[edges[node][i]]) && path.size()<=k ){
| ~~~~~~~~~~~^~~
paths.cpp: In function 'int32_t main()':
paths.cpp:69:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for(int o=0;o<e.size();o++)
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7500 KB |
Output is correct |
2 |
Correct |
5 ms |
7372 KB |
Output is correct |
3 |
Correct |
5 ms |
7372 KB |
Output is correct |
4 |
Correct |
4 ms |
7372 KB |
Output is correct |
5 |
Correct |
5 ms |
7372 KB |
Output is correct |
6 |
Correct |
6 ms |
7636 KB |
Output is correct |
7 |
Correct |
7 ms |
7628 KB |
Output is correct |
8 |
Correct |
5 ms |
7372 KB |
Output is correct |
9 |
Correct |
5 ms |
7372 KB |
Output is correct |
10 |
Correct |
5 ms |
7372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
21484 KB |
Output is correct |
2 |
Correct |
83 ms |
22672 KB |
Output is correct |
3 |
Correct |
315 ms |
41560 KB |
Output is correct |
4 |
Correct |
133 ms |
24616 KB |
Output is correct |
5 |
Correct |
178 ms |
24616 KB |
Output is correct |
6 |
Correct |
250 ms |
34512 KB |
Output is correct |
7 |
Correct |
329 ms |
41460 KB |
Output is correct |
8 |
Correct |
297 ms |
41788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7500 KB |
Output is correct |
2 |
Correct |
5 ms |
7372 KB |
Output is correct |
3 |
Correct |
5 ms |
7372 KB |
Output is correct |
4 |
Correct |
4 ms |
7372 KB |
Output is correct |
5 |
Correct |
5 ms |
7372 KB |
Output is correct |
6 |
Correct |
6 ms |
7636 KB |
Output is correct |
7 |
Correct |
7 ms |
7628 KB |
Output is correct |
8 |
Correct |
5 ms |
7372 KB |
Output is correct |
9 |
Correct |
5 ms |
7372 KB |
Output is correct |
10 |
Correct |
5 ms |
7372 KB |
Output is correct |
11 |
Correct |
97 ms |
21484 KB |
Output is correct |
12 |
Correct |
83 ms |
22672 KB |
Output is correct |
13 |
Correct |
315 ms |
41560 KB |
Output is correct |
14 |
Correct |
133 ms |
24616 KB |
Output is correct |
15 |
Correct |
178 ms |
24616 KB |
Output is correct |
16 |
Correct |
250 ms |
34512 KB |
Output is correct |
17 |
Correct |
329 ms |
41460 KB |
Output is correct |
18 |
Correct |
297 ms |
41788 KB |
Output is correct |
19 |
Correct |
101 ms |
21488 KB |
Output is correct |
20 |
Correct |
83 ms |
22760 KB |
Output is correct |
21 |
Correct |
292 ms |
41372 KB |
Output is correct |
22 |
Correct |
165 ms |
24564 KB |
Output is correct |
23 |
Correct |
140 ms |
24616 KB |
Output is correct |
24 |
Correct |
232 ms |
34516 KB |
Output is correct |
25 |
Correct |
305 ms |
41384 KB |
Output is correct |
26 |
Correct |
308 ms |
41788 KB |
Output is correct |
27 |
Incorrect |
81 ms |
22696 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7372 KB |
Output is correct |
2 |
Incorrect |
29 ms |
11608 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |