Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #define NMAX 103
- int n, m;
- int ad[NMAX][NMAX], roy[NMAX][NMAX];
- void read() {
- cin >> n >> m;
- for (int i = 0; i < m; i++) {
- int a, b;
- cin >> a >> b;
- ad[a][b] = 1;
- }
- }
- void RoyWarshall() {
- for (int k = 1; k <= n; k++) {
- for (int i = 1; i <= n; i++) {
- for (int j = 1; j <= n; j++) {
- if (!roy[i][j]) {
- roy[i][j] = roy[i][k] * roy[k][j];
- }
- }
- }
- }//*/
- }
- void solveA() {
- cout << "1.Exista circuit:";
- for (int i = 1; i <= n; i++) {
- if (roy[i][i]) {
- cout << "DA" << endl;
- return;
- }
- }
- cout << "NU" << endl;
- }
- void solveB() {
- cout << "varfurile intre care nu exista drumuri:" << endl;
- for (int i = 1; i <= n; i++) {
- for (int j = 1; j <= n; j++) {
- if (!roy[i][j]) {
- cout << i << '-' << j << endl;
- }
- }
- }
- }
- void solveC() {
- bool ok = true;
- for (int i = 1; i <= n && ok; i++) {
- for (int j = i + 1; j <= n && ok; j++) {
- if ((ad[i][j] && ad[j][i]) || (!ad[i][j] && !ad[j][i])) {
- ok = false;
- }
- }
- }
- if (!ok) {
- cout << "nu ";
- }
- cout << "e turneu!" << endl;
- }
- void solveD() {
- bool ok = true;
- for (int i = 1; i < n && ok; i++) {
- for (int j = i + 1; j <= n && ok; j++) {
- if (!ad[i][j] && !ad[j][i]) {
- ok = false;
- }
- }
- }
- if (!ok) {
- cout << "nu ";
- }
- cout << "e complet!" << endl;
- }
- int main() {
- read();
- memcpy(roy, ad, sizeof ad);
- RoyWarshall();
- solveA();
- solveB();
- solveC();
- solveD();
- return 0;
- }
Add Comment
Please, Sign In to add comment