CSES - Datatähti 2018 loppu - Results
Submission details
Task:Tietoverkko
Sender:Yytsi
Submission time:2018-01-18 17:14:59 +0200
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'void dfs(int, int)':
input/code.cpp:30:9: error: request for member 'size' in 'u', which is of non-class type 'int'
   if (u.size() >= 2 || u == x) dfs(u, p);
         ^

Code

#include <iostream>
#include <utility>
#include <vector>
#include <map>
using namespace std;

#define N 100001
vector<int> adj[N];
vector<pair<int,int> > inp;
int x = 0;
bool found = false;
int from = 0;
int to = 0;
map<int,bool> m;

void dfs(int p,int e) {
	if (p == x) {
		found = true;
		return;
	}
	m[p] = true;
	
	
	for (int i = 0; i < (int)adj[p].size(); i++) {
		if (found) break;
		int u = adj[p][i];
		if (u == e) {continue;}
		if ((p == from && to == u) || (p==to&&u==from)) {continue;}
		if (m[u]) continue;
		if (u.size() >= 2 || u == x) dfs(u, p);
	}
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n; cin.ignore();
	
	for (int i = 1; i <= n; i++) {
		int a, b; cin >> a >> b; cin.ignore();
		inp.push_back(make_pair(a,b));
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	
	int res = 0;
	for (int i = 0; i < n; i++) {
		pair<int,int> p = inp[i];
		int a=p.first,b=p.second;
		m.clear();
		from=a,to=b;
		x=b;
		found=false;
		dfs(a,0);
		if (!found) {
			res++;
		}
		
	}
	cout<<res;
	return 0;
}