Submission #13307066


Source Code Expand

Copy
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

const int N = 2e5 + 10;
vector<int> a[N];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  while (m--) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x; --y;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  queue<int> Q;
  vector<int> visit(n, -1);
  visit[0] = 0;
  Q.push(0);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (auto& v : a[u]) {
      if (visit[v] >= 0) continue;
      visit[v] = u;
      Q.push(v);
    }
  }
  bool found = false;
  for (int i = 0; i < n; ++i) {
    if (visit[i] < 0) found = true;
  }
  if (found) {
    puts("No");
  } else {
    puts("Yes");
    for (int i = 1; i < n; ++i) {
      printf("%d\n", visit[i] + 1);
    }
  }
  return 0;
}

Submission Info

Submission Time
Task D - .. (Double Dots)
User cuiaoxiang
Language C++ (Clang 10.0.0)
Score 400
Code Size 3190 Byte
Status AC
Exec Time 74 ms
Memory 12152 KB

Compile Error

./Main.cpp:77:11: warning: unused variable 'INF' [-Wunused-const-variable]
const int INF = 1 << 29;
          ^
./Main.cpp:78:11: warning: unused variable 'MOD' [-Wunused-const-variable]
const int MOD = 1e9 + 7;
          ^
2 warnings generated.

Judge Result

Set Name Sample Subtask1
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 39
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
Subtask1 sample_01.txt, sample_02.txt, sub1_01.txt, sub1_02.txt, sub1_03.txt, sub1_04.txt, sub1_05.txt, sub1_06.txt, sub1_07.txt, sub1_08.txt, sub1_09.txt, sub1_10.txt, sub1_11.txt, sub1_12.txt, sub1_13.txt, sub1_14.txt, sub1_15.txt, sub1_16.txt, sub1_17.txt, sub1_18.txt, sub1_19.txt, sub1_20.txt, sub1_21.txt, sub1_22.txt, sub1_23.txt, sub1_24.txt, sub1_25.txt, sub1_26.txt, sub1_27.txt, sub1_28.txt, sub1_29.txt, sub1_30.txt, sub1_31.txt, sub1_32.txt, sub1_33.txt, sub1_34.txt, sub1_35.txt, sub1_36.txt, sub1_37.txt
Case Name Status Exec Time Memory
sample_01.txt AC 9 ms 7784 KB
sample_02.txt AC 4 ms 7932 KB
sub1_01.txt AC 36 ms 9532 KB
sub1_02.txt AC 25 ms 9156 KB
sub1_03.txt AC 50 ms 10736 KB
sub1_04.txt AC 42 ms 10396 KB
sub1_05.txt AC 13 ms 8252 KB
sub1_06.txt AC 32 ms 9632 KB
sub1_07.txt AC 22 ms 8676 KB
sub1_08.txt AC 46 ms 11524 KB
sub1_09.txt AC 48 ms 10908 KB
sub1_10.txt AC 51 ms 11096 KB
sub1_11.txt AC 55 ms 10956 KB
sub1_12.txt AC 41 ms 11696 KB
sub1_13.txt AC 55 ms 11072 KB
sub1_14.txt AC 52 ms 11068 KB
sub1_15.txt AC 42 ms 11420 KB
sub1_16.txt AC 60 ms 11036 KB
sub1_17.txt AC 36 ms 9580 KB
sub1_18.txt AC 56 ms 10808 KB
sub1_19.txt AC 38 ms 9892 KB
sub1_20.txt AC 15 ms 8272 KB
sub1_21.txt AC 66 ms 11360 KB
sub1_22.txt AC 40 ms 9820 KB
sub1_23.txt AC 23 ms 8920 KB
sub1_24.txt AC 60 ms 11264 KB
sub1_25.txt AC 74 ms 11944 KB
sub1_26.txt AC 55 ms 10968 KB
sub1_27.txt AC 69 ms 12152 KB
sub1_28.txt AC 72 ms 11916 KB
sub1_29.txt AC 12 ms 7840 KB
sub1_30.txt AC 37 ms 10636 KB
sub1_31.txt AC 61 ms 11068 KB
sub1_32.txt AC 59 ms 11060 KB
sub1_33.txt AC 60 ms 10952 KB
sub1_34.txt AC 41 ms 10808 KB
sub1_35.txt AC 39 ms 10792 KB
sub1_36.txt AC 69 ms 11576 KB
sub1_37.txt AC 6 ms 7736 KB