CSES Graph Grith
// compile: make data
// run: ./data < data.in
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#ifdef LOCAL
#include <debug/codeforces.h>
#define debug(x...) _debug_print(#x, x);
#define Debug(x...) _debug_print_format(#x, x);
std::ifstream terminal("/dev/tty");
#define PP cerr<<"\033[1;30mpause...\e[0m",terminal.ignore();
#else
#define debug(x...)
#define Debug(x...)
#define PP
#endif
template<typename...Args> void print_(Args...args){((cout<<args<<" "),...)<<endl;}
#define rep(i,a,b) for(int i=(a);i<(int)(b);++i)
#define sz(v) ((int)(v).size())
#define print(...) print_(__VA_ARGS__);
#define FIND(a, x) ((find(a.begin(),a.end(),(x))!=a.end())?1:0)
#define cmin(x,...) x=min({(x),__VA_ARGS__})
#define cmax(x,...) x=max({(x),__VA_ARGS__})
#define INTMAX (int)(9223372036854775807)
#define INF (int)(1152921504606846976)
#define NaN (int)(0x8b88e1d0595d51d1)
#define double long double
#define int long long
#define uint unsigned long long
#define MAXN 200010

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int n, m; cin >> n >> m;
    vector<vector<int>> a(n, vector<int>(n, 0));
    vector<vector<int>> e(n);
    rep(i, 0, m) {
        int u, v; cin >> u >> v; --u, --v;
        e[u].push_back(v), e[v].push_back(u);
        a[u][v] = a[v][u] = 1;
    }
    auto bfs = [&](int s, int t) -> int {
        vector<int> dis(n, INF); dis[s] = 0;
        queue<int> q; q.push(s);
        while (!q.empty()) {
            int u = q.front(); q.pop();
            for (auto v: e[u]) {
                if (!a[u][v] || dis[v] != INF) continue;
                dis[v] = dis[u] + 1;
                q.push(v);
                if (v == t) return dis[v];
            }
        }
        return INF;
    };
    int res = INF;
    rep(i, 0, n) rep(j, i+1, n) {
        if (!a[i][j]) continue;
        a[i][j] = a[j][i] = 0;
        cmin(res, bfs(i, j) + 1);
        a[i][j] = a[j][i] = 1;
    }
    cout << (res!=INF ? res : -1) << endl;

    return 0;
}

Comments

  1. 11 months ago
    2025-12-06 2:46:27

    Got the RR888APK on my phone. Easy to download and install. So far so good. You wanna? Check out the apk download here: rr888apk

  2. 11 months ago
    2025-12-19 14:00:46

    Okay, jjwinlogin makes it so easy to jump right into the games. The login process is a breeze. I’m all about it! jjwinlogin

  3. 10 months ago
    2025-12-29 6:29:04

    Heard some folks talking about bet7788 the other day. Seems like a decent place to check out for some action. Gonna give it a whirl and see what all the fuss is about! Check it out: bet7788

  4. 1 month ago
    2026-9-25 9:39:24

    I’ve tried a few platforms lately, but this one really stands out for its smooth interface. Definitely worth checking out if you want a hassle-free experience. Check it out at bdke999

  5. 4 weeks ago
    2026-10-05 1:47:30

    Super impressed with the security features here. I feel safe depositing my funds and the games are incredibly addictive. tg77722login is the way to go.

  6. 4 weeks ago
    2026-10-08 15:56:32

    [3550]1xbet লগইন এবং অ্যাপ ডাউনলোড | বিকাশ দিয়ে ক্যাসিনো ডিপোজিট,1xbet লগইন করার নিয়ম জানুন এবং অ্যাপ ডাউনলোড করে অনলাইন স্লট গেম খেলার নিয়ম শিখুন। বিকাশ দিয়ে দ্রুত ডিপোজিট করে গেম শুরু করুন। visit: 1xbet

  7. 2 weeks ago
    2026-10-17 15:08:58

    I play here whenever I want a bit of excitement without the stress. The game selection is massive yet everything runs perfectly on my older tablet. Cashouts are always on time and the vibe is top notch j88com33

Send Comment Edit Comment


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
Previous
Next