CSES - Aalto Competitive Programming 2024 - wk7 - Mon - Results
Submission details
Task:Distinct Routes
Sender:HFalke
Submission time:2024-10-21 17:50:05 +0300
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'bool dfs(int, std::vector<std::vector<int> >&, std::vector<std::vector<int> >&)':
input/code.cpp:33:49: error: expected primary-expression before '&' token
   33 |                         if(!dfs(next,vector<vi> &adj, vector<vi> &paths)){
      |                                                 ^
input/code.cpp:33:66: error: expected primary-expression before '&' token
   33 |                         if(!dfs(next,vector<vi> &adj, vector<vi> &paths)){
      |                                                                  ^
input/code.cpp: In function 'int main()':
input/code.cpp:6:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 | #define REP(i,a,b) for (int i = a; i < b; i++)
      |                                      ^
input/code.cpp:74:9: note: in expansion of macro 'REP'
   74 |         REP(i,0,paths.size()){
      |         ^~...

Code

#include <bits/stdc++.h>

using namespace std;

//Definitions for quicker writing
#define REP(i,a,b) for (int i = a; i < b; i++)
#define PB push_back
#define MP make_pair
#define F first
#define S second

//Typedefs for quicker writing
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
typedef pair<long long, long long> pl;

//Max values
const long long lmx = LLONG_MAX;
const int imx = INT_MAX;

vector<bool> viscur(500,false);
vector<vector<bool>> used;

bool dfs(int cur, vector<vi> &adj, vector<vi> &paths){
	viscur[cur] = true;
	for(auto next: adj[cur]){
		if(viscur[next] == true){
			return false;
		}	
		else if(viscur[next] == false && !used[cur][next]){
			if(!dfs(next,vector<vi> &adj, vector<vi> &paths)){
				return false;
			}
			else{
				used[cur][next] = true;
			}
		}
	}
	return true;
	
}	

int main() {
	//IO optimization
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	//Input definition
	int n;
	int m;

	//Read In
	cin >> n >> m;

	vector<vi> adj;
	vector<vi> paths;

	int a,b;
	REP(i,0,m){
		cin >> a >> b;
		adj[a].PB(b);
		used[a][b] = false;
	}

	//Main part
	while(dfs(0,adj,paths)){
		REP(i,1,500) viscur[i] = false;
	}

	//Write out
	cout << paths.size() << "\n";
	REP(i,0,paths.size()){
		cout << paths[i].size() << "\n";
		REP(j,0,paths[i].size()){ 
			cout << paths[i][j] << " ";
		}
		cout << endl;
	}
		
	//Return
	return 0;

}