Answered step by step
Verified Expert Solution
Question
1 Approved Answer
i want c code first line i input N N is the number of i need to check second line i input [ a ,
i want c code
first line i input N
N is the number of i need to check
second line i input abbc etc then a b c all of them are the natural numbers.
if mean if i want to check then i need to pass
so for example i input line and line
then
i need to pass to pass
i need to pass to pass
i need to pass to pass
so i pass or the other or
this example output True
but if i input line line
then i need to pass to pass
i need to pass to pass
so i can't pass all of thembecause if i want to pass i need pass but i need to pass before pass
in this case output False
ofcourse s output is Flasebecause i can't pass
There are my failure code
#include
#include
#include
using namespace std;
bool canFinishint numCourses, vector& prerequisites
vector graphnumCourses;
vector inDegreenumCourses;
for auto& pre : prerequisites
graphpresecondpushbackprefirst;
inDegreeprefirst;
queue zeroIndegree;
for int i ; i numCourses; i
if inDegreei
zeroIndegree.pushi;
int visited ;
while zeroIndegree.empty
int course zeroIndegree.front;
zeroIndegree.pop;
visited;
for int next : graphcourse
if inDegreenext
zeroIndegree.pushnext;
True, False
return visited numCourses;
int main
int N;
cin N;
vector prerequisites;
int a b;
while cin a b
prerequisites.pushbacka b;
cout canFinishN prerequisites "True" : "False" endl;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started