Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
793 B
4
Indexable
Never
#include<bits/stdc++.h>

using namespace std;

#define ll long long

void inputOutput(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
}

void dfs(int u, bool* visited, vector<int>* arr){
	visited[u]=1;
	for(int i=0;i<arr[u].size();i++){
		int v=arr[u][i];
		cout<<u<<" "<<v<<" "<<visited[v]<<endl;
		if(visited[v]==1)
			continue;
		else
			dfs(v,visited,arr);
	}
	return;
}

int main(){
	inputOutput();

	int n,e;
	cin>>n>>e;

	bool visited[n+1];
	memset(visited,false,n+1);
	vector<int> arr[n+1];  // Array of vectors

	while(e--){
		int u,v;
		cin>>u>>v;

		arr[u].push_back(v);
		arr[v].push_back(u);
	}

	int ans=0;

	for(int i=1;i<n+1;i++){
		if(visited[i]==0)
		{
			ans++;
			dfs(i,visited,arr);
		}
	}

	cout<<ans;

	return 0;
}