TOPIC

wrong answer 30%

jcampos9 asked 6 years ago

//============================================================================
// Name        : uri2562.cpp
// Author      : Julia
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <list>
#include <algorithm>

using namespace std;

class Grafo{

    int v;
    list<int> *adj;

public:

    Grafo(int v);
    void adicionaAresta(int v1, int v2);
    bool existeVizinho(int v1, int v2);

};

Grafo::Grafo(int v){
    this->v = v;
    adj = new list<int>[v];
}

void Grafo::adicionaAresta(int v1, int v2){
    adj[v1].push_back(v2);
}

bool Grafo::existeVizinho(int v1, int v2){

    if(find(adj[v1].begin(), adj[v1].end(), v2) != adj[v1].end()){
        return true;
    }
    else
        return false;

}

int main() {
    int n, m; // numero de especies e numero de informacoes presentes no manual
    int a=0, b=0; //especie a e b sao do mesmo tipo
    int e;
    int cont;
    int c=0;

    cin>> n >> m;

    Grafo grafo(m);

    while(c != m){

        cin>> e;

        grafo.adicionaAresta(a,b);

        if(grafo.existeVizinho(a,b)){
            cont++;
        }

        c++;

    }

    cout<< cont << endl;

    return 0;
}

This topic has not been answered yet. Be the first!

Remember not post solutions. Your post may be reviewed by our moderators.