AtCoder-abc366_g.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. ios::sync_with_stdio(false);
  5. cin.tie(nullptr);
  6. int n, m;
  7. cin >> n >> m;
  8. vector<unsigned long long> row(n, 0);
  9. for (int i = 0; i < m; ++i) {
  10. int u, v;
  11. cin >> u >> v;
  12. --u; --v;
  13. row[u] ^= 1ULL << v;
  14. row[v] ^= 1ULL << u;
  15. }
  16. vector<int> pivot_column;
  17. int rank = 0;
  18. for (int column = 0; column < n; ++column) {
  19. int pivot = rank;
  20. while (pivot < n && ((row[pivot] >> column) & 1ULL) == 0) ++pivot;
  21. if (pivot == n) continue;
  22. swap(row[rank], row[pivot]);
  23. for (int r = 0; r < n; ++r) {
  24. if (r != rank && ((row[r] >> column) & 1ULL)) row[r] ^= row[rank];
  25. }
  26. pivot_column.push_back(column);
  27. ++rank;
  28. }
  29. vector<char> is_pivot(n, false);
  30. for (int column : pivot_column) is_pivot[column] = true;
  31. vector<unsigned long long> answer(n, 0);
  32. int basis_index = 0;
  33. for (int free_column = 0; free_column < n; ++free_column) {
  34. if (is_pivot[free_column]) continue;
  35. unsigned long long vector_value = 1ULL << free_column;
  36. for (int r = 0; r < rank; ++r) {
  37. if ((row[r] >> free_column) & 1ULL) {
  38. vector_value |= 1ULL << pivot_column[r];
  39. }
  40. }
  41. for (int v = 0; v < n; ++v) {
  42. if ((vector_value >> v) & 1ULL) answer[v] |= 1ULL << basis_index;
  43. }
  44. ++basis_index;
  45. }
  46. if (find(answer.begin(), answer.end(), 0ULL) != answer.end()) {
  47. cout << "No\n";
  48. return 0;
  49. }
  50. cout << "Yes\n";
  51. for (int i = 0; i < n; ++i) {
  52. if (i) cout << ' ';
  53. cout << answer[i];
  54. }
  55. cout << '\n';
  56. return 0;
  57. }