Yam Code
Sign up
Login
New paste
Home
Trending
Archive
English
English
Tiếng Việt
भारत
Sign up
Login
New Paste
Browse
#include<iostream> #include <list> #include <limits.h> using namespace std; class DoThi { int V; list<int> *adj; bool coChuTrinhUtil(int v, bool danhdau[], int parent); public: DoThi(int V); // Constructor void themCanh(int v, int w); bool coChuTrinh(); }; DoThi::DoThi(int V) { this->V = V; adj = new list<int>[V]; } void DoThi::themCanh(int v, int w) { adj[v].push_back(w); adj[w].push_back(v); } // Su dung ham de quy va mang danh dau de phat hien // Chu ki duoc bat dau tu dinh v bool DoThi::coChuTrinhUtil(int v, bool danhdau[], int parent) { // Danh dau node hien tai danhdau[v] = true; list<int>::iterator i; for (i = adj[v].begin(); i != adj[v].end(); ++i) { // neu canh chua duoc danh dau thi no se kiem tra tu canh này if (!danhdau[*i]) { if (coChuTrinhUtil(*i, danhdau, v)) return true; } // Neu dinh lien ke duoc danh dau va khong lien quan den dinh hien tai thi no la mot chu ki else if (*i != parent) return true; } return false; } // Tra true neu do thi co chu trinh bool DoThi::coChuTrinh() { // Danh dau tat ca chua bool *danhdau = new bool[V]; for (int i = 0; i < V; i++) danhdau[i] = false; // Dung de quy de nhan ra chu trinh trong cay DFS for (int u = 0; u < V; u++) if (!danhdau[u]) // Neu den u thi danh dau if (coChuTrinhUtil(u, danhdau, -1)) return true; return false; } // Driver program to test above functions int main() { DoThi g1(5); g1.themCanh(1, 0); g1.themCanh(0, 2); g1.themCanh(2, 1); g1.themCanh(0, 3); g1.themCanh(3, 4); if (g1.coChuTrinh()){ cout << "Do Thi G1 co chu trinh" << endl; } else { cout << "Do Thi G1 khong co chu trinh" << endl; } DoThi g2(3); g2.themCanh(0, 1); g2.themCanh(1, 2); if (g2.coChuTrinh()){ cout << "Do Thi G2 co chu trinh" << endl; } else { cout << "Do Thi G2 khong co chu trinh" << endl; } return 0; }
Paste Settings
Paste Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax Highlighting :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Paste Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create New Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English
Tiếng Việt
भारत