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

Envío 7009

Problema 0x53 - Encontrar ciclos en un grafo dirigido

  • Autor: danidiaztech
  • Fecha: 2023-06-07 16:19:47 UTC (Hace más de 1 año)
Caso # Resultado Tiempo Memoria
#1
Incorrecto
0.002 s 0 KBi
#2
Incorrecto
0.002 s 1 KBi
#3
Incorrecto
0.002 s 1 KBi
#4
Incorrecto
0.001 s 1 KBi
#5
Incorrecto
0.004 s 1 KBi
#6
Incorrecto
0.004 s 1 KBi
#7
Incorrecto
0.004 s 1 KBi
#8
Incorrecto
0.004 s 2 KBi
#9
Incorrecto
0.006 s 1 KBi
#10
Incorrecto
0.005 s 1 KBi
#11
Incorrecto
0.002 s 0 KBi
#12
Incorrecto
0.007 s 1 KBi
#13
Incorrecto
0.004 s 1 KBi
#14
Incorrecto
0.005 s 2 KBi
#15
Incorrecto
0.004 s 2 KBi
#16
Incorrecto
0.004 s 2 KBi
#17
Incorrecto
0.005 s 1 KBi
#18
Incorrecto
0.004 s 1 KBi
#19
Incorrecto
0.004 s 1 KBi
#20
Incorrecto
0.006 s 1 KBi
#21
Incorrecto
0.005 s 1 KBi
#22
Incorrecto
0.004 s 1 KBi
#23
Incorrecto
0.002 s 1 KBi
#24
Incorrecto
0.002 s 1 KBi
#25
Incorrecto
0.005 s 1 KBi
#26
Incorrecto
0.002 s 1 KBi
#27
Incorrecto
0.023 s 2 KBi
#28
Incorrecto
0.006 s 1 KBi
#29
Incorrecto
0.023 s 2 KBi
#30
Incorrecto
0.005 s 1 KBi
#31
Incorrecto
0.004 s 1 KBi
#32
Incorrecto
0.022 s 2 KBi
#33
Incorrecto
0.013 s 2 KBi
#34
Incorrecto
0.015 s 1 KBi
#35
Incorrecto
0.028 s 3 KBi
Puntos totales: 0 / 100

Código

// Made by Daniel Diaz (@Danidiaztech)
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define forn(i, n) for (int i = 0; i < n; i++) // for in range in python
#define fore(i, a, b) for (int i = a; i < b; i++) // for in range in python
#define int long long int
#define double long double
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size() 

typedef pair<int, int> pii;
typedef vector<int> vii;

const int MAX = 10100;
const int MIN = -MAX;
const int oo = LLONG_MAX / 2;
const int ooo = LLONG_MIN / 2;
const int mod = 1e9 + 7;

vii g[MAX];
int vis[MAX];
bool f = 0;
void dfs(int u){
  if (f) return;
  vis[u] = 1;
  for (auto x: g[u]){
    if (!vis[x]){
      dfs(x);
    }
    if (vis[x] == 1){
      // Found
      if (!f)
        cout << "YES";
      f = 1;
      return;
    }
  }
  vis[u] = 2;
}
void solve(){
  int n,m;
  cin >> n >> m;
  forn(i,m){
    int a, b; cin >> a >> b;
    g[a].pb(b);
  }
  forn(i,n){
    if (f) return;
    dfs(i);
  }
  if (!f)
    cout << "NO";
}

int32_t main() {
  fastInp;
  #if LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif

  int tc = 1;
  // cin >> tc;

  for (int t = 1; t <= tc; t++){
    // cout << "Case #" << t << ": ";
    solve();
  }
  return 0;
}