提出 #65474638


ソースコード 拡げる

#ifdef LOCAL
#define _GLIBCXX_DEBUG 1
#endif
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using ull = unsigned long long;
using ld = long double;
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define rep(X, a, b) for(int X = a; X < b; ++X)
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
#define fi first
#define se second

#ifdef LOCAL
#define ZTMYACANESOCUTE // freopen("in.txt", "r", stdin);
#define debug(...) {cerr << #__VA_ARGS__ << " = "; dbg(__VA_ARGS__);}
#else
#define ZTMYACANESOCUTE ios_base::sync_with_stdio(0), cin.tie(0);
#define debug(...) 6;
#endif

void dbg() { cerr << '\n'; }
template<typename T, typename ...U>
void dbg(T t, U ...u) { cerr << t << ' '; dbg(u...); }

pii operator + (const pii &p1, const pii &p2) { return make_pair(p1.fi + p2.fi, p1.se + p2.se); }
pii operator - (const pii &p1, const pii &p2) { return make_pair(p1.fi - p2.fi, p1.se - p2.se); }
pll operator + (const pll &p1, const pll &p2) { return make_pair(p1.fi + p2.fi, p1.se + p2.se); }
pll operator - (const pll &p1, const pll &p2) { return make_pair(p1.fi - p2.fi, p1.se - p2.se); }

template<class T> bool chmin(T &a, T b) { return (b < a && (a = b, true)); }
template<class T> bool chmax(T &a, T b) { return (a < b && (a = b, true)); }

#define lpos pos << 1
#define rpos pos << 1 | 1
 
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << "," << p.second << ')'; }
template<typename A> ostream& operator << (ostream &os, const vector<A> &p) { for(const auto &a : p) os << a << " "; os << '\n'; return os; }
 
const int MAXN = 2e5 + 5, MOD = 998244353, IINF = 1e9 + 7, MOD2 = 1000000007;
const double eps = 1e-9;
const ll LINF = 1e18L + 5;
const int B = 320;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// int get_rand(int l, int r){ return uniform_int_distribution<int>(l, r)(rng); }
 
ll fpow (ll x, ll exp, ll mod = LLONG_MAX) { if (x == 0) return 0; ll res = 1; while (exp > 0) { if (exp & 1) res = res * x % mod; x = x * x % mod; exp >>= 1; } return res; }

void solve() {
    int n, m; cin >> n >> m;
    if (n != m) {
        cout << "No\n";
        return;
    }
    int cc = n;
    vector<vector<int>> adj(n + 1);
    rep (i, 0, m) {
        int a, b; cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    vector<bool> vis(n + 1, 0);
    bool f = 0;
    auto dfs = [&](auto self, int u) -> void {
        vis[u] = 1;
        int cnt = 0;
        for (int v : adj[u])if (!vis[v]) {
            self(self, v);
        }
    };
    dfs(dfs, 1);
    rep (i, 1, n + 1) if (!vis[i] || (adj[i].size() != 2)) {
        cout << "No\n";
        return;
    }
    cout << "Yes\n";
}
 
int main() {
    ZTMYACANESOCUTE;
    int T = 1;
    // cin >> T;
    while (T--) {
        solve();
    }
}

提出情報

提出日時
問題 C - Cycle Graph?
ユーザ Justinshao
言語 C++ 20 (gcc 12.2)
得点 300
コード長 3043 Byte
結果 AC
実行時間 79 ms
メモリ 18972 KiB

コンパイルエラー

Main.cpp: In function ‘void solve()’:
Main.cpp:62:9: warning: unused variable ‘cc’ [-Wunused-variable]
   62 |     int cc = n;
      |         ^~
Main.cpp:70:10: warning: unused variable ‘f’ [-Wunused-variable]
   70 |     bool f = 0;
      |          ^
Main.cpp: In instantiation of ‘solve()::<lambda(auto:53, int)> [with auto:53 = solve()::<lambda(auto:53, int)>]’:
Main.cpp:78:8:   required from here
Main.cpp:73:13: warning: unused variable ‘cnt’ [-Wunused-variable]
   73 |         int cnt = 0;
      |             ^~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 2
AC × 24
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
min.txt AC 1 ms 3584 KiB
random_01.txt AC 72 ms 18056 KiB
random_02.txt AC 6 ms 4652 KiB
random_03.txt AC 70 ms 18916 KiB
random_04.txt AC 17 ms 8128 KiB
random_05.txt AC 66 ms 17636 KiB
random_06.txt AC 2 ms 3724 KiB
random_07.txt AC 72 ms 18764 KiB
random_08.txt AC 22 ms 9464 KiB
random_09.txt AC 73 ms 18348 KiB
random_10.txt AC 55 ms 16768 KiB
random_11.txt AC 77 ms 18972 KiB
random_12.txt AC 37 ms 12876 KiB
random_13.txt AC 61 ms 15680 KiB
random_14.txt AC 4 ms 4236 KiB
random_15.txt AC 79 ms 18904 KiB
random_16.txt AC 32 ms 11752 KiB
random_17.txt AC 1 ms 3512 KiB
random_18.txt AC 1 ms 3448 KiB
random_19.txt AC 1 ms 3520 KiB
random_20.txt AC 1 ms 3340 KiB
random_21.txt AC 1 ms 3384 KiB
sample_01.txt AC 1 ms 3500 KiB
sample_02.txt AC 1 ms 3512 KiB