Demo entry 6758420

aaaaaaaaaaaaaaaaaaaaa

   

Submitted by bbbbbbbbbbbbbbbbbb on Aug 14, 2018 at 02:57
Language: C++. Code size: 1.0 kB.

#include <stdio.h>
#include <iostream>
#include <vector>

#define WHITE 1
#define GRAY 2
#define BLACK 3

using namespace std;

int adj[100][100], color[100], startingTime[100], finishingTime[100];
int node, edge, Time = 1;

void dfsVisit (int x) {
    startingTime[x] = Time++;
    color[x] = GRAY;

    for (int i = 0; i < node; ++i) {
        if (adj[x][i] == 1) {
            if (color[i] == WHITE) {
                dfsVisit(i);
            }
        }
    }

    color[x] = BLACK;
    finishingTime[x] = Time++;
}

void dfs() {
    for (int i = 0; i < node; ++i) {
        color[i] = WHITE;
    }
    for (int i = 0; i < node; ++i) {
        if (color[i] == WHITE) {
            dfsVisit(i);
        }
    }
}

int main()
{
// freopen("input", "r", stdin);
    scanf("%d %d", &node, &edge);
    int n1, n2;
    for (int i = 0; i < edge; ++i) {
        scanf("%d %d", &n1, &n2);
        adj[n1][n2] = 1;
        adj[n2][n1] = 1;
    }
    
    dfs();


    return 0;
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).