提出 #56576323


ソースコード 拡げる

/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#ifdef EMT
#include "Header/stdc++.h"
#else
#include <bits/stdc++.h>
#endif
using namespace std;

#ifdef EMT
#define debug(x) cerr << "\e[1;31m" << #x << " = " << (x) << "\e[0m\n"
#define print(x) emilia_mata_tenshi(#x, begin(x), end(x))
template<typename T, typename T2> ostream& operator<<(ostream &os, const pair<T, T2> &obj) {
    return os << '{' << obj.first << ',' << obj.second << '}';
}
template<class TupType, size_t... I> void lamy_kawaii(ostream& os, const TupType& _tup, index_sequence<I...>) {
    // source: https://stackoverflow.com/a/41171552
    os << '{';
    (..., (cerr << (I == 0? "" : ",") << get<I>(_tup)));
    os << '}';
}
template<class... T> ostream& operator<<(ostream &os, const tuple<T...>& _tup) {
    lamy_kawaii(os, _tup, make_index_sequence<sizeof...(T)>());
    return os;
}
template<typename T> void emilia_mata_tenshi(const char *s, T l, T r) {
    cerr << "\e[1;33m" << s << " = [";
    while (l != r) {
        cerr << *l;
        cerr << (++l == r ? ']' : ',');
    }
    cerr << "\e[0m\n";
}
#else
#define debug(x) 48763
#define print(x) 48763
#endif

template<typename T, typename T2> istream& operator>>(istream &is, pair<T, T2> &obj) {
    is >> obj.first >> obj.second;
    return is;
}
template<typename T> istream& operator>>(istream &is, vector<T> &obj) {
    for (auto &x : obj)
        is >> x;
    return is;
}

#define YN(x) ((x) ? "YES" : "NO")
#define Yn(x) ((x) ? "Yes" : "No")
#define yn(x) ((x) ? "yes" : "no")
#define emilia_my_wife ios::sync_with_stdio(0); cin.tie(NULL);
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
template<typename T>
using base_type = remove_cv_t<remove_reference_t<T>>;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
static int Lamy_is_cute = []() {
    emilia_my_wife
    return 48763;
}();
/*--------------------------------------------------------------------------------------*/

// Returns n - rank
int gauss_elimination(vector<bitset<61>> &d) {
    int n = d.size(), m = d[0].size();
    int r = 0;
    for (int i = 0; i < m; ++i) {
        int p = -1;
        for (int j = r; j < n; ++j) {
            if (!d[j][i])
                continue;
            if (p == -1 || d[j][i] > d[p][i]) p = j;
        }
        if (p == -1) continue;
        swap(d[p], d[r]);
        for (int j = 0; j < n; ++j) {
            if (r == j) continue;
            int z = d[j][i];
            for (int k = 0; k < m; ++k) d[j][k] = d[j][k] ^ (z & d[r][k]);
        }
        r++;
    }
    return r;
}

signed main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> arr(n);
    for (int i = 0; i < m; i++) {
        int u, v;
         cin >> u >> v;
         u--; v--;
         arr[u].push_back(v);
         arr[v].push_back(u);
    }
    vector<ull> ans(n);
    for (int u = 0; u < n; u++) {
        vector<bitset<61>> matrix(n + 1);
        for (int i = 0; i < n; i++) {
            for (int v : arr[i]) {
                matrix[i][v] = true;
            }
        }
        matrix[n][u] = true;
        matrix[n][60] = true;
        int x = gauss_elimination(matrix);
        // debug(x);
        // for (int i = 0; i <= n; i++)
        //     cerr << matrix[i] << '\n';
        for (int i = 0; i < x; i++) {
            int w = 0;
            while (matrix[i][w] == 0)
                w++;
            if (w >= n) {
                cout << "No\n";
                return 0;
            }
            ans[w] |= ull(matrix[i][60]) << u;
        }
    }
    for (int i = 0; i < n; i++) {
        ull sum = 0;
        for (int v : arr[i])
            sum ^= ans[v];
        assert(sum == 0);
    }
    cout << "Yes\n";
    for (int i = 0; i < n; i++)
        cout << ans[i] << " \n"[i + 1 == n];
}

提出情報

提出日時
問題 G - XOR Neighbors
ユーザ JiKuai
言語 C++ 20 (gcc 12.2)
得点 600
コード長 4490 Byte
結果 AC
実行時間 17 ms
メモリ 3648 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 4
AC × 46
セット名 テストケース
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.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, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt, 02_handmade_07.txt, 02_handmade_08.txt, 02_handmade_09.txt, 02_handmade_10.txt, 02_handmade_11.txt, 02_handmade_12.txt
ケース名 結果 実行時間 メモリ
00_sample_01.txt AC 1 ms 3520 KiB
00_sample_02.txt AC 1 ms 3572 KiB
00_sample_03.txt AC 1 ms 3504 KiB
00_sample_04.txt AC 1 ms 3520 KiB
01_random_01.txt AC 1 ms 3520 KiB
01_random_02.txt AC 1 ms 3564 KiB
01_random_03.txt AC 1 ms 3472 KiB
01_random_04.txt AC 1 ms 3500 KiB
01_random_05.txt AC 1 ms 3540 KiB
01_random_06.txt AC 1 ms 3504 KiB
01_random_07.txt AC 1 ms 3648 KiB
01_random_08.txt AC 1 ms 3580 KiB
01_random_09.txt AC 1 ms 3432 KiB
01_random_10.txt AC 4 ms 3440 KiB
01_random_11.txt AC 1 ms 3528 KiB
01_random_12.txt AC 1 ms 3412 KiB
01_random_13.txt AC 1 ms 3412 KiB
01_random_14.txt AC 1 ms 3580 KiB
01_random_15.txt AC 1 ms 3448 KiB
01_random_16.txt AC 1 ms 3556 KiB
01_random_17.txt AC 1 ms 3524 KiB
01_random_18.txt AC 3 ms 3440 KiB
01_random_19.txt AC 1 ms 3520 KiB
01_random_20.txt AC 1 ms 3484 KiB
01_random_21.txt AC 1 ms 3428 KiB
01_random_22.txt AC 6 ms 3584 KiB
01_random_23.txt AC 2 ms 3368 KiB
01_random_24.txt AC 1 ms 3432 KiB
01_random_25.txt AC 2 ms 3536 KiB
01_random_26.txt AC 1 ms 3516 KiB
01_random_27.txt AC 2 ms 3512 KiB
01_random_28.txt AC 1 ms 3428 KiB
01_random_29.txt AC 1 ms 3428 KiB
01_random_30.txt AC 1 ms 3496 KiB
02_handmade_01.txt AC 8 ms 3416 KiB
02_handmade_02.txt AC 10 ms 3380 KiB
02_handmade_03.txt AC 10 ms 3588 KiB
02_handmade_04.txt AC 9 ms 3528 KiB
02_handmade_05.txt AC 1 ms 3524 KiB
02_handmade_06.txt AC 2 ms 3436 KiB
02_handmade_07.txt AC 17 ms 3520 KiB
02_handmade_08.txt AC 16 ms 3528 KiB
02_handmade_09.txt AC 1 ms 3580 KiB
02_handmade_10.txt AC 1 ms 3524 KiB
02_handmade_11.txt AC 1 ms 3540 KiB
02_handmade_12.txt AC 17 ms 3532 KiB