Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int a[100][100], i, j, n, p, viz[10];
- void citire();
- int grad(int a);
- int hemiltonian();
- int main()
- {
- citire();
- if(hemiltonian())
- cout<<" ** Graficul nu este hemiltonian ** ";
- else cout<<" ** Graficul este hemiltonian ** ";
- return 0;
- }
- void citire()
- {
- ifstream f("c.in");
- f>>n>>p;
- for(i=1; i<=n; i++)
- for(j=1; j<=n; j++)
- f>>a[i][j];
- f.close();
- }
- int grad(int i)
- {
- int gr=0;
- for(j=1; j<=n; j++)
- if(a[i][j] == 1)
- gr++;
- return gr;
- }
- int hemiltonian()
- {
- for(i=1; i<=n; i++)
- if(grad(i)<=n/2)
- return 0;
- return 1;
- }
- /* citire.in */
- 8 1
- 0 1 0 1 0 0 0 0
- 1 0 1 0 1 0 0 1
- 0 1 0 0 0 0 0 1
- 1 0 0 0 1 1 1 0
- 0 1 0 1 0 0 1 1
- 0 0 0 1 0 0 1 0
- 0 0 0 1 1 1 0 1
- 0 1 1 0 1 0 1 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement