Submission #65424723


Source Code Expand

/*
~~ Alguma parte/frase foda de um livro/mangá para dar sorte ~~

Uma vez eu gritei, gradualmente, perdi minha voz.
Uma vez eu chorei, gradualmente, perdi minhas lágrimas.
Uma vez eu sofri, gradualmente, me tornei capaz de suportar tudo.
Uma vez me alegrei, gradualmente, me tornei indiferente ao mundo.
E agora, tudo o que me resta é um rosto sem expressão,
meu olhar é tão firme quanto um monólito,
apenas a perseverança permanece no meu coração.
Este sou eu, um personagem insignificante,
Fang Yuan — A Perseverança.

*/
#if defined(LOCAL) or not defined(LUOGU)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,unroll-loops")
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename T>
ostream& operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    for (size_t i = 0; i < v.size(); ++i) {
        os << v[i] << (i + 1 == v.size() ? "" : ", ");
    }
    os << "]";
    return os;
}

void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T)
{
    cerr << ' ' << H;
    dbg_out(T...);
}
#define dbg(...) cerr << "(" << _VA_ARGS_ << "):", dbg_out(_VA_ARGS_), cerr << endl

#define int long long
#define IOS                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(0)
#define TXTIO                           \
    freopen("entrada.in", "r", stdin);\
    freopen("saida.out", "w", stdout)
#define pb push_back
#define all(v) v.begin(), v.end()
#define f first
#define s second
#define Unique(v)                     \
    sort(all(v));                     \
    v.erase(unique(all(v)), v.end()); \
    v.shrink_to_fit()
#define sz(v) ((int)v.size())
#define sor(x) sort(all(x))
#define ft front()
#define bk back()
#define endl "\n"
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef tuple<int, int, int> tiii;
const int MAXN = 2e5 + 5;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const int mod = 1e9 + 7;
const int LOGN = 21;

#include <bits/stdc++.h>

using namespace std;

class DSU
{
    vector<int> parent;
    vector<int> rank;

public:
    DSU(int n)
    {
        parent.assign(n, -1);
        rank.assign(n, 1);
    }

    int find(int i)
    {
        if (parent[i] == -1)
            return i;

        return parent[i] = find(parent[i]);
    }

    void unite(int x, int y)
    {
        int s1 = find(x);
        int s2 = find(y);

        if (s1 != s2)
        {
            if (rank[s1] < rank[s2])
            {
                parent[s1] = s2;
            }
            else if (rank[s1] > rank[s2])
            {
                parent[s2] = s1;
            }
            else
            {
                parent[s2] = s1;
                rank[s1] += 1;
            }
        }
    }
};

void solve()
{
    int n, m; cin >> n >> m;
    DSU dsu(n+1);
    vi deg(n+1, 0);
    bool ok = true;
    rep(i, 0, m){
        int a, b; cin >> a >> b;
        deg[a]++;
        deg[b]++;
        if(dsu.find(a) != dsu.find(b)){
            dsu.unite(a, b);
        }
    }
    rep(i, 1, n+1) if(deg[i] != 2) ok = false;

    int r = dsu.find(1);
    rep(i, 2, n+1) if(dsu.find(i) != r) ok = false;

    cout << (ok ? "Yes" : "No") << endl;
}

int32_t main()
{
    IOS;
    int tt;
    tt = 1;
    while (tt --> 0)
        solve();
    return 0;
}

Submission Info

Submission Time
Task C - Cycle Graph?
User Marcux777
Language C++ 23 (gcc 12.2)
Score 300
Code Size 4224 Byte
Status AC
Exec Time 37 ms
Memory 7900 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 24
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
min.txt AC 1 ms 3600 KiB
random_01.txt AC 35 ms 7804 KiB
random_02.txt AC 4 ms 3608 KiB
random_03.txt AC 35 ms 7896 KiB
random_04.txt AC 9 ms 4572 KiB
random_05.txt AC 35 ms 7740 KiB
random_06.txt AC 2 ms 3580 KiB
random_07.txt AC 36 ms 7760 KiB
random_08.txt AC 12 ms 4848 KiB
random_09.txt AC 37 ms 7736 KiB
random_10.txt AC 32 ms 7524 KiB
random_11.txt AC 36 ms 7708 KiB
random_12.txt AC 20 ms 6044 KiB
random_13.txt AC 36 ms 7748 KiB
random_14.txt AC 3 ms 3568 KiB
random_15.txt AC 35 ms 7900 KiB
random_16.txt AC 17 ms 5700 KiB
random_17.txt AC 3 ms 7792 KiB
random_18.txt AC 5 ms 4372 KiB
random_19.txt AC 12 ms 6216 KiB
random_20.txt AC 17 ms 4936 KiB
random_21.txt AC 34 ms 7484 KiB
sample_01.txt AC 1 ms 3412 KiB
sample_02.txt AC 1 ms 3416 KiB