Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Gabriel Oliveira Taumaturgo
- 14/0140522
- */
- #include <bits/stdc++.h>
- using namespace std;
- vector<int> tempos;
- int tempo = 1;
- int visited[10000];
- int tempo_de_visita[10000];
- int tempo_de_saida[10000];
- int start = 5;
- map <int,vector<int>> graph;
- map <int,vector<int>> grapht;
- void dfs(int u){
- tempo_de_visita[u] = tempo;
- tempo++;
- visited[u] = 0;
- for(int v: graph[u]){
- grapht[v].push_back(u);
- if(visited[v]){
- dfs(v);
- }
- }
- tempo_de_saida[u] = tempo;
- tempo++;
- }
- void dfst(int u){
- printf("%d ",u );
- visited[u] = 0;
- for(int v: grapht[u]){
- if(visited[v]){
- dfst(v);
- }
- }
- }
- int main(){
- graph[1].push_back(2);
- graph[2].push_back(3);
- graph[2].push_back(5);
- graph[2].push_back(6);
- graph[3].push_back(4);
- graph[3].push_back(7);
- graph[4].push_back(3);
- graph[4].push_back(8);
- graph[5].push_back(1);
- graph[5].push_back(6);
- graph[6].push_back(7);
- graph[7].push_back(6);
- graph[7].push_back(8);
- graph[8].push_back(8);
- for (int i = 0; i < 10000; ++i)
- {
- visited[i] = 1;
- }
- for(pair<const int,vector<int>>& p: graph){
- if (visited[p.first])
- {
- dfs(p.first);
- }
- }
- vector<pair<int,int>> indicetempo;
- for (int i = 1; i < 9; ++i)
- indicetempo.push_back(make_pair(tempo_de_saida[i],i));
- sort(indicetempo.begin(),indicetempo.end(), greater<pair<int,int>>());
- for (int i = 0; i < 10000; ++i)
- {
- visited[i] = 1;
- }
- for(pair<int,int>& p: indicetempo){
- if (visited[p.second])
- {
- dfst(p.second);
- printf("\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement