TOPIC

Help with TLE!

Ulises García asked 1 year ago

I implemented this with DFS but i had a TLE. Is there an other form to do it? Or how can i optimize my code?

I used a vector<vector > G;

for(int i=0; i<m; i++){ int node, edge; cin >> node >> edge; node--; edge--; G[node].push_back(edge); G[edge].push_back(node); }

for(int i=0; i<q; i++){
    flag = false;
    int node, edge;
    cin >> node >> edge;
    node--; edge--;
    dfs_num.assign(n, 0);
    DFS(node, edge); // Change the flag if i visit the edge
    if(flag) cout << "Lets que lets\n";
    else cout << "Deu ruim\n";
}

This topic was solved and cannot recieve new replies.

  • Edgar Almeida replied 1 year ago

    Try doing this problem with Floyd Warshall algorithm.