Submission #58946727


Source Code Expand

/// Msaa el 5ra
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define F first
#define S second
#define f(i, a, b) for (int i = a; i < b; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define mp(x, y) make_pair(x, y)
#define popCnt(x) (__builtin_popcountll(x))
//#define int ll

using ll = long long;
using ii = pair<int, int>;
using ull = unsigned long long;

const int N = 2e5 + 5, A = 26, LG = 19, MOD = (119 << 23) +1, MOD2 = 1e9 + 7;
const long double PI = acos(-1);
const long double EPS = 1e-7;

const ll MAX = 1e15;

vector<int> adj[N];

void doWork() {
    int n, m;
    cin >> n >> m;
    while(m--) {
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
    }
    vector<int> dist(n + 1, -1);
    queue<int> q;
    q.push(1);

    while(q.size()) {

        auto cur = q.front();
        q.pop();
        if(cur == 1 && dist[cur] != -1) {
            cout << dist[cur] + 1 << "\n";
            return;
        }

        for(auto v : adj[cur]) {
            if(dist[v] == -1) {
                dist[v] = dist[cur] + 1;
                q.push(v);
            }
        }

    }

    cout << "-1\n";

}

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
//  cin >> t;
  while (t--) {
    doWork();
  }
}

Submission Info

Submission Time
Task D - Cycle
User triplem5ds
Language C++ 20 (gcc 12.2)
Score 400
Code Size 1400 Byte
Status AC
Exec Time 96 ms
Memory 14768 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 39
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 02_cycle_00.txt, 02_cycle_01.txt, 03_path_00.txt, 03_path_01.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 2 ms 3536 KiB
00_sample_01.txt AC 2 ms 3528 KiB
00_sample_02.txt AC 2 ms 3440 KiB
01_random_00.txt AC 58 ms 12656 KiB
01_random_01.txt AC 20 ms 4932 KiB
01_random_02.txt AC 38 ms 11496 KiB
01_random_03.txt AC 15 ms 4728 KiB
01_random_04.txt AC 57 ms 12976 KiB
01_random_05.txt AC 27 ms 5408 KiB
01_random_06.txt AC 41 ms 11916 KiB
01_random_07.txt AC 25 ms 7488 KiB
01_random_08.txt AC 55 ms 12588 KiB
01_random_09.txt AC 22 ms 5152 KiB
01_random_10.txt AC 40 ms 11816 KiB
01_random_11.txt AC 21 ms 4988 KiB
01_random_12.txt AC 55 ms 12588 KiB
01_random_13.txt AC 17 ms 4744 KiB
01_random_14.txt AC 39 ms 11820 KiB
01_random_15.txt AC 21 ms 5036 KiB
01_random_16.txt AC 59 ms 12584 KiB
01_random_17.txt AC 14 ms 4572 KiB
01_random_18.txt AC 52 ms 12212 KiB
01_random_19.txt AC 17 ms 4620 KiB
01_random_20.txt AC 56 ms 12644 KiB
01_random_21.txt AC 39 ms 8692 KiB
01_random_22.txt AC 39 ms 11756 KiB
01_random_23.txt AC 12 ms 4516 KiB
01_random_24.txt AC 55 ms 12544 KiB
01_random_25.txt AC 36 ms 7136 KiB
01_random_26.txt AC 49 ms 12344 KiB
01_random_27.txt AC 25 ms 5464 KiB
01_random_28.txt AC 60 ms 12596 KiB
01_random_29.txt AC 30 ms 5956 KiB
01_random_30.txt AC 35 ms 11596 KiB
01_random_31.txt AC 16 ms 4608 KiB
02_cycle_00.txt AC 72 ms 14768 KiB
02_cycle_01.txt AC 96 ms 14728 KiB
03_path_00.txt AC 28 ms 14696 KiB
03_path_01.txt AC 57 ms 14660 KiB