█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 2597

Problema 0x53 - Encontrar ciclos en un grafo dirigido

  • Autor: S8Vega
  • Fecha: 2021-01-13 05:35:05 UTC (Hace casi 4 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.007 s 19 KBi
#2
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.008 s 2 KBi
#3
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.007 s 2 KBi
#4
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.006 s 2 KBi
#5
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.007 s 2 KBi
#6
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.006 s 2 KBi
#7
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.006 s 2 KBi
#8
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.008 s 2 KBi
#9
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.006 s 2 KBi
#10
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.006 s 2 KBi
#11
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.005 s 2 KBi
#12
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.007 s 2 KBi
#13
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.008 s 2 KBi
#14
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.007 s 20 KBi
#15
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.007 s 1 KBi
#16
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.007 s 16 KBi
#17
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.006 s 18 KBi
#18
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.007 s 2 KBi
#19
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.008 s 2 KBi
#20
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.006 s 2 KBi
#21
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.007 s 2 KBi
#22
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.007 s 2 KBi
#23
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.008 s 2 KBi
#24
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.006 s 2 KBi
#25
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.007 s 2 KBi
#26
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.006 s 2 KBi
#27
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.036 s 2 KBi
#28
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.006 s 2 KBi
#29
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.049 s 2 KBi
#30
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.006 s 2 KBi
#31
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.012 s 2 KBi
#32
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.037 s 2 KBi
#33
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.012 s 3 KBi
#34
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.022 s 2 KBi
#35
Correcto
                      main.cpp:46:9: warning: 'dbg' macro redefined [-Wmacro-redefined]
#define dbg(...) 18
        ^
main.cpp:11:9: note: previous definition is here
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
        ^
1 warning generated.

                    
0.044 s 3 KBi
Puntos totales: 100 / 100

Código

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define forn(i, a, b) for (int i = a; i < b; ++i)
#define SZ(x) int(x.size())
#define pb push_back
#define F first
#define S second
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}

const int N = 1e4 + 10;
bool cycle;
int n, m, vis[N];
vector<int> g[N];

void dfs(int u) {
  if (cycle) return;
  vis[u] = 1;
  for (int &v : g[u]) {
    if (!vis[v])
      dfs(v);
    else if (vis[v] == 1) {
      cycle = true;
      break;
    }
  }
  vis[u] = 2;
}

int main() {
#ifdef LOCAL
  freopen("a.txt", "r", stdin);
// freopen("main.txt", "w", stdout);
#else
  ios::sync_with_stdio(0);
  cin.tie(0);
#define endl '\n'
#define dbg(...) 18
#endif
  cin >> n >> m;
  int u, v;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    g[u].pb(v);
  }
  for (int i = 0; i < n; i++) {
    if (!vis[i]) {
      dfs(i);
    }
  }
  if (cycle)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

/*
g++ -pthread -Wall -Wshadow -std=c++17 -o main a.cpp -DLOCAL && ./main
*/