problem_id stringlengths 6 6 | language stringclasses 2 values | original_status stringclasses 3 values | original_src stringlengths 19 243k | changed_src stringlengths 19 243k | change stringclasses 3 values | i1 int64 0 8.44k | i2 int64 0 8.44k | j1 int64 0 8.44k | j2 int64 0 8.44k | error stringclasses 270 values | stderr stringlengths 0 226k |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02678 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int inf = 1001001001;
int main() {
int n, m;
cin >> n >> m;
int a, b;
vector<int> to[100005];
for (int i = 0; i < m; i++) {
cin >> a >> b;
a--;
b--;
to[a].push_back(b);
to[b].push_back(a);
}
queue<int> q;
vector<int> dist(n, inf);
vector<int> pre(n, -1);
dist[0] = 0;
q.push(0);
while (!q.empty()) {
int v = q.front();
q.pop();
for (int u : to[v]) {
dist[u] = dist[v] + 1;
pre[u] = v;
q.push(u);
}
}
cout << "Yes" << endl;
for (int i = 0; i < n; i++) {
if (i == 0)
continue;
int ans = pre[i];
ans++;
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int inf = 1001001001;
int main() {
int n, m;
cin >> n >> m;
int a, b;
vector<int> to[100005];
for (int i = 0; i < m; i++) {
cin >> a >> b;
a--;
b--;
to[a].push_back(b);
to[b].push_back(a);
}
queue<int> q;
vector<int> dist(n, inf);
vector<int> pre(n, -1);
dist[0] = 0;
q.push(0);
while (!q.empty()) {
int v = q.front();
q.pop();
for (int u : to[v]) {
if (dist[u] != inf)
continue;
dist[u] = dist[v] + 1;
pre[u] = v;
q.push(u);
}
}
cout << "Yes" << endl;
for (int i = 0; i < n; i++) {
if (i == 0)
continue;
int ans = pre[i];
ans++;
cout << ans << endl;
}
return 0;
}
| insert | 24 | 24 | 24 | 26 | TLE | |
p02678 | C++ | Time Limit Exceeded | #include <iostream>
#include <queue>
#include <vector>
using namespace std;
int main() {
int n, m, a, b;
cin >> n >> m;
vector<int> to[100005];
for (int i = 0; i < m; i++) {
cin >> a >> b;
a--;
b--;
to[a].push_back(b);
to[b].push_back(a);
}
queue<int> q;
vector<int> dist(n, 100005);
vector<int> pre(n, -1);
dist[0] = 0;
q.push(0);
while (!q.empty()) {
int v = q.front();
q.pop();
for (int u = 0; u < n; v++) {
if (dist[u] != 100005)
continue;
dist[u] = dist[v] + 1;
pre[u] = v;
q.push(u);
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
int ans = pre[i];
ans++;
cout << ans << endl;
}
return 0;
}
| #include <iostream>
#include <queue>
#include <vector>
using namespace std;
int main() {
int n, m, a, b;
cin >> n >> m;
vector<int> to[100005];
for (int i = 0; i < m; i++) {
cin >> a >> b;
a--;
b--;
to[a].push_back(b);
to[b].push_back(a);
}
queue<int> q;
vector<int> dist(n, 100005);
vector<int> pre(n, -1);
dist[0] = 0;
q.push(0);
while (!q.empty()) {
int v = q.front();
q.pop();
for (int u : to[v]) {
if (dist[u] != 100005)
continue;
dist[u] = dist[v] + 1;
pre[u] = v;
q.push(u);
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
int ans = pre[i];
ans++;
cout << ans << endl;
}
return 0;
}
| replace | 23 | 24 | 23 | 24 | TLE | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b) { return a ? GCD(b % a, a) : b; }
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m), b(m);
for (int i = 0; i < m; i++)
cin >> a[i] >> b[i];
vector<vector<int>> G(n);
for (int i = 0; i < n; i++) {
G[a[i] - 1].push_back(b[i] - 1);
G[b[i] - 1].push_back(a[i] - 1);
}
vector<int> color(n, 1e9);
vector<bool> seen(n, false);
queue<int> q;
q.push(0);
while (!q.empty()) {
int v = q.front();
q.pop();
for (auto i : G[v]) {
if (seen[i])
continue;
q.push(i);
seen[i] = true;
color[i] = v;
}
}
for (int i = 0; i < n; i++) {
if (!seen[i]) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
cout << color[i] + 1 << endl;
}
} | #include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b) { return a ? GCD(b % a, a) : b; }
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m), b(m);
for (int i = 0; i < m; i++)
cin >> a[i] >> b[i];
vector<vector<int>> G(n);
for (int i = 0; i < m; i++) {
G[a[i] - 1].push_back(b[i] - 1);
G[b[i] - 1].push_back(a[i] - 1);
}
vector<int> color(n, 1e9);
vector<bool> seen(n, false);
queue<int> q;
q.push(0);
while (!q.empty()) {
int v = q.front();
q.pop();
for (auto i : G[v]) {
if (seen[i])
continue;
q.push(i);
seen[i] = true;
color[i] = v;
}
}
for (int i = 0; i < n; i++) {
if (!seen[i]) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
cout << color[i] + 1 << endl;
}
} | replace | 11 | 12 | 11 | 12 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define FORD(i, a, n) for (int i = (a); i >= (n); i--)
#define REPD(i, n) FOR(i, n, 0)
#define ALL(o) (o).begin(), (o).end()
template <class T> using V = vector<T>;
template <class T, class U> using P = pair<T, U>;
template <class T> using PQ = priority_queue<T>;
template <class T> using PQR = priority_queue<T, vector<T>, greater<T>>;
const string YES = "Yes";
V<V<int>> m;
void solve(int N, int M) {
V<int> ans(N + 1);
queue<int> q;
q.push(1);
int tmp, n;
while (!q.empty()) {
n = q.front();
q.pop();
REP(i, m[n].size()) {
tmp = m[n][i];
if (ans[tmp] == 0) {
ans[tmp] = n;
q.push(tmp);
}
}
}
cout << "Yes" << endl;
FOR(i, 2, N + 1) { cout << ans[i] << endl; }
}
int main() {
int N, M;
cin >> N >> M;
REP(i, M + 1) {
V<int> a;
m.push_back(a);
}
int a, b;
for (int i = 0; i < M; i++) {
cin >> a >> b;
m[a].push_back(b);
m[b].push_back(a);
}
solve(N, M);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define FORD(i, a, n) for (int i = (a); i >= (n); i--)
#define REPD(i, n) FOR(i, n, 0)
#define ALL(o) (o).begin(), (o).end()
template <class T> using V = vector<T>;
template <class T, class U> using P = pair<T, U>;
template <class T> using PQ = priority_queue<T>;
template <class T> using PQR = priority_queue<T, vector<T>, greater<T>>;
const string YES = "Yes";
V<V<int>> m;
void solve(int N, int M) {
V<int> ans(N + 1);
queue<int> q;
q.push(1);
int tmp, n;
while (!q.empty()) {
n = q.front();
q.pop();
REP(i, m[n].size()) {
tmp = m[n][i];
if (ans[tmp] == 0) {
ans[tmp] = n;
q.push(tmp);
}
}
}
cout << "Yes" << endl;
FOR(i, 2, N + 1) { cout << ans[i] << endl; }
}
int main() {
int N, M;
cin >> N >> M;
REP(i, N + 1) {
V<int> a;
m.push_back(a);
}
int a, b;
for (int i = 0; i < M; i++) {
cin >> a >> b;
m[a].push_back(b);
m[b].push_back(a);
}
solve(N, M);
return 0;
}
| replace | 43 | 44 | 43 | 44 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main(int argc, const char *argv[]) {
int n, m;
cin >> n >> m;
vector<vector<int>> g(m);
for (int i = 0; i < m; ++i) {
int a, b;
cin >> a >> b;
a--, b--;
g[a].push_back(b);
g[b].push_back(a);
}
vector<int> ans(n, -1);
queue<int> q;
q.push(0);
while (!q.empty()) {
auto idx = q.front();
q.pop();
for (int i = 0; i < g[idx].size(); ++i) {
if (ans[g[idx][i]] != -1 || g[idx][i] == 0) {
continue;
}
ans[g[idx][i]] = idx;
q.push(g[idx][i]);
}
}
cout << "Yes" << '\n';
for (int i = 1; i < n; ++i) {
cout << ans[i] + 1 << '\n';
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(int argc, const char *argv[]) {
int n, m;
cin >> n >> m;
vector<vector<int>> g(n);
for (int i = 0; i < m; ++i) {
int a, b;
cin >> a >> b;
a--, b--;
g[a].push_back(b);
g[b].push_back(a);
}
vector<int> ans(n, -1);
queue<int> q;
q.push(0);
while (!q.empty()) {
auto idx = q.front();
q.pop();
for (int i = 0; i < g[idx].size(); ++i) {
if (ans[g[idx][i]] != -1 || g[idx][i] == 0) {
continue;
}
ans[g[idx][i]] = idx;
q.push(g[idx][i]);
}
}
cout << "Yes" << '\n';
for (int i = 1; i < n; ++i) {
cout << ans[i] + 1 << '\n';
}
return 0;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<vector<int>> graph(N);
for (int i = 0; i < N; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
graph[a].push_back(b);
graph[b].push_back(a);
}
vector<int> dist(N, 1e9);
dist[0] = 0;
queue<int> que;
que.push(0);
while (!que.empty()) {
int u = que.front();
que.pop();
for (int v : graph[u]) {
if (dist[v] > dist[u] + 1) {
dist[v] = dist[u] + 1;
que.push(v);
}
}
}
vector<int> ans(N, 0);
for (int i = 1; i < N; i++) {
for (int v : graph[i]) {
if (dist[v] == dist[i] - 1) {
ans[i] = v + 1;
}
}
}
cout << "Yes" << endl;
for (int i = 1; i < N; i++) {
cout << ans[i] << endl;
}
}
| #include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<vector<int>> graph(N);
for (int i = 0; i < M; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
graph[a].push_back(b);
graph[b].push_back(a);
}
vector<int> dist(N, 1e9);
dist[0] = 0;
queue<int> que;
que.push(0);
while (!que.empty()) {
int u = que.front();
que.pop();
for (int v : graph[u]) {
if (dist[v] > dist[u] + 1) {
dist[v] = dist[u] + 1;
que.push(v);
}
}
}
vector<int> ans(N, 0);
for (int i = 1; i < N; i++) {
for (int v : graph[i]) {
if (dist[v] == dist[i] - 1) {
ans[i] = v + 1;
}
}
}
cout << "Yes" << endl;
for (int i = 1; i < N; i++) {
cout << ans[i] << endl;
}
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p02678 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define MAX 300005
#define endl "\n"
vector<lli> adj[MAX + 5];
lli ans[MAX];
queue<lli> q;
lli N, M;
void BFS(int source, vector<lli> adj[MAX + 5], vector<bool> &visited) {
visited[source] = true;
q.push(source);
while (!q.empty()) {
source = q.front();
visited[source] = true;
for (auto i = adj[source].begin(); i != adj[source].end(); i++) {
if (!visited[*i]) {
BFS(*i, adj, visited);
ans[*i] = source;
q.push(*i);
}
}
q.pop();
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> N >> M;
for (lli i = 0; i < M; i++) {
lli A, B;
cin >> A >> B;
adj[A].push_back(B);
adj[B].push_back(A);
}
vector<bool> visited(N + 5, 0);
BFS(1, adj, visited);
// cout<<endl;
bool flag = true;
for (lli i = 2; i <= N; i++) {
if (!ans[i])
flag = false;
}
if (flag) {
cout << "Yes" << endl;
for (lli i = 2; i <= N; i++)
cout << ans[i] << endl;
} else {
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define MAX 300005
#define endl "\n"
vector<lli> adj[MAX + 5];
lli ans[MAX];
queue<lli> q;
lli N, M;
void BFS(int source, vector<lli> adj[MAX + 5], vector<bool> &visited) {
visited[source] = true;
q.push(source);
while (!q.empty()) {
source = q.front();
visited[source] = true;
for (auto i = adj[source].begin(); i != adj[source].end(); i++) {
if (!visited[*i]) {
visited[*i] = true;
ans[*i] = source;
q.push(*i);
}
}
q.pop();
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> N >> M;
for (lli i = 0; i < M; i++) {
lli A, B;
cin >> A >> B;
adj[A].push_back(B);
adj[B].push_back(A);
}
vector<bool> visited(N + 5, 0);
BFS(1, adj, visited);
// cout<<endl;
bool flag = true;
for (lli i = 2; i <= N; i++) {
if (!ans[i])
flag = false;
}
if (flag) {
cout << "Yes" << endl;
for (lli i = 2; i <= N; i++)
cout << ans[i] << endl;
} else {
cout << "No" << endl;
}
} | replace | 17 | 18 | 17 | 18 | TLE | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const int INF = 1001001001;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> g;
rep(i, m) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].push_back(b);
g[b].push_back(a);
}
vector<int> prev(n, -1);
vector<int> dist(n, INF);
dist[0] = 0;
queue<int> q;
q.push(0);
while (!q.empty()) {
int v = q.front();
q.pop();
for (auto nv : g[v]) {
if (dist[nv] == INF) {
dist[nv] = dist[v] + 1;
q.push(nv);
prev[nv] = v;
}
}
}
for (int i = 1; i < n; i++) {
if (prev[i] == -1) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
cout << prev[i] + 1 << endl;
}
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const int INF = 1001001001;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> g(n);
rep(i, m) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].push_back(b);
g[b].push_back(a);
}
vector<int> prev(n, -1);
vector<int> dist(n, INF);
dist[0] = 0;
queue<int> q;
q.push(0);
while (!q.empty()) {
int v = q.front();
q.pop();
for (auto nv : g[v]) {
if (dist[nv] == INF) {
dist[nv] = dist[v] + 1;
q.push(nv);
prev[nv] = v;
}
}
}
for (int i = 1; i < n; i++) {
if (prev[i] == -1) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
cout << prev[i] + 1 << endl;
}
}
| replace | 24 | 25 | 24 | 25 | -11 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const ll N = 1e5;
ll n, m, cnt, a;
vector<int> g[N];
ll used[N], p[N];
string s;
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
ll x, y;
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
queue<int> q;
q.push(1);
p[1] = 1;
used[1] = 1;
while (!q.empty()) {
int v = q.front();
q.pop();
for (int i = 0; i < g[v].size(); i++) {
int to = g[v][i];
if (!used[to]) {
used[to]++;
q.push(to);
p[to] = (v);
}
}
}
for (int i = 2; i <= n; i++) {
if (!used[i])
return cout << "No", 0;
}
cout << "Yes" << endl;
for (int i = 2; i <= n; i++) {
cout << p[i] << "\n";
}
}
| #include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const ll N = 2e6 + 7;
ll n, m, cnt, a;
vector<int> g[N];
ll used[N], p[N];
string s;
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
ll x, y;
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
queue<int> q;
q.push(1);
p[1] = 1;
used[1] = 1;
while (!q.empty()) {
int v = q.front();
q.pop();
for (int i = 0; i < g[v].size(); i++) {
int to = g[v][i];
if (!used[to]) {
used[to]++;
q.push(to);
p[to] = (v);
}
}
}
for (int i = 2; i <= n; i++) {
if (!used[i])
return cout << "No", 0;
}
cout << "Yes" << endl;
for (int i = 2; i <= n; i++) {
cout << p[i] << "\n";
}
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
string explanation1 = "これは幅優先探索の問題!";
string explanation2 =
"参考URL:https://qiita.com/drken/items/996d80bcae64649a6580";
const int INF = 1001001001;
int main() {
int n, m;
cin >> n >> m;
// グラフ入力受け取り
Graph G(m);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--;
b--; // distで0と1のズレを直しておくため
G[a].push_back(b); // 有向グラフ
G[b].push_back(a); // 無向グラフなのでこれも追加
}
// BFSのためのデータ構造
vector<int> dist(n, INF); // 全頂点を「未訪問」に初期化
queue<int> que; // キュー
vector<int> pre(n, -1);
// 初期条件(頂点1をノードとする)
dist[0] = 0;
que.push(0); // 1を橙色頂点にする
// BFS開始(キューが空になるまで探索を行う)
while (!que.empty()) {
int v = que.front(); // キューから先頭頂点を取り出す
que.pop(); // 先頭要素を削除
// v から辿れる頂点をすべて調べる
for (int u : G[v]) { // 拡張for文 変数uにG[v]の値を入れてる
if (dist[u] != INF)
continue; // すでに発見済みの頂点は探索しない
// 新たな白色頂点uについて距離情報を更新してキューに追加する
dist[u] = dist[v] + 1;
pre[u] = v;
que.push(u);
}
}
for (int i = 1; i < n; i++) {
if (pre[i] == -1) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
for (int i = 0; i < n; i++) {
if (i == 0)
continue;
int ans = pre[i];
ans++; // 18,19行目で1減らしてたのを元に戻す
cout << ans << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
string explanation1 = "これは幅優先探索の問題!";
string explanation2 =
"参考URL:https://qiita.com/drken/items/996d80bcae64649a6580";
const int INF = 1001001001;
int main() {
int n, m;
cin >> n >> m;
// グラフ入力受け取り
Graph G(100005);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--;
b--; // distで0と1のズレを直しておくため
G[a].push_back(b); // 有向グラフ
G[b].push_back(a); // 無向グラフなのでこれも追加
}
// BFSのためのデータ構造
vector<int> dist(n, INF); // 全頂点を「未訪問」に初期化
queue<int> que; // キュー
vector<int> pre(n, -1);
// 初期条件(頂点1をノードとする)
dist[0] = 0;
que.push(0); // 1を橙色頂点にする
// BFS開始(キューが空になるまで探索を行う)
while (!que.empty()) {
int v = que.front(); // キューから先頭頂点を取り出す
que.pop(); // 先頭要素を削除
// v から辿れる頂点をすべて調べる
for (int u : G[v]) { // 拡張for文 変数uにG[v]の値を入れてる
if (dist[u] != INF)
continue; // すでに発見済みの頂点は探索しない
// 新たな白色頂点uについて距離情報を更新してキューに追加する
dist[u] = dist[v] + 1;
pre[u] = v;
que.push(u);
}
}
for (int i = 1; i < n; i++) {
if (pre[i] == -1) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
for (int i = 0; i < n; i++) {
if (i == 0)
continue;
int ans = pre[i];
ans++; // 18,19行目で1減らしてたのを元に戻す
cout << ans << endl;
}
return 0;
}
| replace | 14 | 15 | 14 | 15 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
const ll INF = 1e9;
using Graph = vector<vector<int>>;
int N, M;
Graph G;
int main() {
cin >> N >> M;
G.assign(N, vector<int>());
rep(i, 0, N) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].push_back(b);
G[b].push_back(a);
}
vector<int> ans(N, INF);
ans[0] = -1;
queue<int> que;
que.push(0);
while (que.size()) {
int v = que.front();
que.pop();
for (auto &nv : G[v]) {
if (ans[nv] == INF) {
que.push(nv);
ans[nv] = v;
}
}
}
cout << "Yes" << endl;
for (auto &v : ans) {
if (v == -1)
continue;
cout << v + 1 << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
const ll INF = 1e9;
using Graph = vector<vector<int>>;
int N, M;
Graph G;
int main() {
cin >> N >> M;
G.assign(N, vector<int>());
rep(i, 0, M) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].push_back(b);
G[b].push_back(a);
}
vector<int> ans(N, INF);
ans[0] = -1;
queue<int> que;
que.push(0);
while (que.size()) {
int v = que.front();
que.pop();
for (auto &nv : G[v]) {
if (ans[nv] == INF) {
que.push(nv);
ans[nv] = v;
}
}
}
cout << "Yes" << endl;
for (auto &v : ans) {
if (v == -1)
continue;
cout << v + 1 << endl;
}
} | replace | 14 | 15 | 14 | 15 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define MOD = 998244353;
#define int long long int
#define inf (int)(1e15)
#define all(x) (x).begin(), (x).end()
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define isYes(x) printf("%s\n", (x) ? "Yes" : "No")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define isIn(x, y, h, w) (x >= 0 && x < h && y >= 0 && y < w)
#define pair pair<int, int>
typedef vector<int> vi; // Vector of long long
typedef vector<vi> vvi; // Vector of vi
typedef vector<pair> vii; // Vector of pairs
typedef vector<vii> vvii; // Vector of Vector of pairs
typedef vector<bool> vb; // Vector of bool
#define pq \
priority_queue // Max heap (To convert to min heap, use negative sign before
// every value)
#define ff first // For pairs
#define ss second
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, -1, 0, 1};
const int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1},
dy8[] = {1, -1, 1, 0, -1, 1, -0, -1};
#define testcases(t) \
int(t); \
cin >> (t); \
while ((t)--)
#define range(c, r) (c).begin(), (c).begin() + (r) // Mainly used in sorting
#define present(c, x) ((c).find(x) != (c).end()) // for sets, maps, multi-maps
#define cpresent(c, x) (find(all(c), x) != (c).end()) // for vectors
#define run(x, c) for ((x) = (c).begin(); (x) != (c).end(); (x)++)
vvi adj;
vi parent;
vb visited;
void bfs() {
queue<int> q;
q.push(1);
visited[1] = true;
while (q.size()) {
int current = q.front();
q.pop();
for (auto it : adj[current]) {
if (parent[it] == -1) {
q.push(it);
parent[it] = current;
visited[it] = true;
}
}
}
}
signed main() {
int n, m;
cin >> n >> m;
adj.resize(n + 1);
parent.assign(n + 1, -1);
while (m--) {
int u, v;
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
bfs();
for (int i = 1; i <= n; i++) {
if (visited[i])
continue;
cout << "No" << endl;
return 0;
}
Yes;
for (int i = 2; i <= n; i++) {
cout << parent[i] << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define MOD = 998244353;
#define int long long int
#define inf (int)(1e15)
#define all(x) (x).begin(), (x).end()
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define isYes(x) printf("%s\n", (x) ? "Yes" : "No")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define isIn(x, y, h, w) (x >= 0 && x < h && y >= 0 && y < w)
#define pair pair<int, int>
typedef vector<int> vi; // Vector of long long
typedef vector<vi> vvi; // Vector of vi
typedef vector<pair> vii; // Vector of pairs
typedef vector<vii> vvii; // Vector of Vector of pairs
typedef vector<bool> vb; // Vector of bool
#define pq \
priority_queue // Max heap (To convert to min heap, use negative sign before
// every value)
#define ff first // For pairs
#define ss second
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, -1, 0, 1};
const int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1},
dy8[] = {1, -1, 1, 0, -1, 1, -0, -1};
#define testcases(t) \
int(t); \
cin >> (t); \
while ((t)--)
#define range(c, r) (c).begin(), (c).begin() + (r) // Mainly used in sorting
#define present(c, x) ((c).find(x) != (c).end()) // for sets, maps, multi-maps
#define cpresent(c, x) (find(all(c), x) != (c).end()) // for vectors
#define run(x, c) for ((x) = (c).begin(); (x) != (c).end(); (x)++)
vvi adj;
vi parent;
vb visited;
void bfs() {
queue<int> q;
q.push(1);
visited[1] = true;
while (q.size()) {
int current = q.front();
q.pop();
for (auto it : adj[current]) {
if (parent[it] == -1) {
q.push(it);
parent[it] = current;
visited[it] = true;
}
}
}
}
signed main() {
int n, m;
cin >> n >> m;
adj.resize(n + 1);
parent.assign(n + 1, -1);
visited.assign(n + 1, false);
while (m--) {
int u, v;
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
bfs();
for (int i = 1; i <= n; i++) {
if (visited[i])
continue;
cout << "No" << endl;
return 0;
}
Yes;
for (int i = 2; i <= n; i++) {
cout << parent[i] << endl;
}
return 0;
} | insert | 62 | 62 | 62 | 63 | -11 | |
p02678 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define int long long
typedef long long ll;
using namespace std;
int N, M;
vector<vector<int>> G;
vector<int> ans;
void bfs() {
queue<ll> Q;
vector<ll> color(N, 0);
Q.push(0);
color[0] = 1;
while (!Q.empty()) {
ll u = Q.front();
Q.pop();
for (int i = 0; i < G[u].size(); i++) {
if (color[G[u][i]] == 0) {
Q.push(G[u][i]);
color[G[u][i]] = 1;
ans[G[u][i]] = u;
}
}
// cout << u << endl;
}
for (int i = 0; i < N; i++) {
if (color[i] == 0) {
cout << "No" << endl;
return;
}
}
cout << "Yes" << endl;
for (int i = 1; i < N; i++)
cout << ans[i] + 1 << endl;
}
signed main() {
cin >> N >> M;
G.resize(N);
ans.resize(N);
for (int i = 0; i < N; i++)
G[i].resize(N);
for (int i = 0; i < M; i++) {
int s, t;
cin >> s >> t;
s--;
t--;
G[s].push_back(t);
G[t].push_back(s);
}
// cout << "OK" << endl;
bfs();
return 0;
} | #include <bits/stdc++.h>
#define int long long
typedef long long ll;
using namespace std;
int N, M;
vector<vector<int>> G;
vector<int> ans;
void bfs() {
queue<ll> Q;
vector<ll> color(N, 0);
Q.push(0);
color[0] = 1;
while (!Q.empty()) {
ll u = Q.front();
Q.pop();
for (int i = 0; i < G[u].size(); i++) {
if (color[G[u][i]] == 0) {
Q.push(G[u][i]);
color[G[u][i]] = 1;
ans[G[u][i]] = u;
}
}
// cout << u << endl;
}
for (int i = 0; i < N; i++) {
if (color[i] == 0) {
cout << "No" << endl;
return;
}
}
cout << "Yes" << endl;
for (int i = 1; i < N; i++)
cout << ans[i] + 1 << endl;
}
signed main() {
cin >> N >> M;
G.resize(N);
ans.resize(N);
for (int i = 0; i < M; i++) {
int s, t;
cin >> s >> t;
s--;
t--;
G[s].push_back(t);
G[t].push_back(s);
}
// cout << "OK" << endl;
bfs();
return 0;
} | delete | 41 | 43 | 41 | 41 | TLE | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int s[205000];
vector<int> v[100];
int main() {
int n, m;
memset(s, -1, sizeof(s));
cin >> n >> m;
while (m--) {
int u, v1;
cin >> u >> v1;
v[u].push_back(v1);
v[v1].push_back(u);
}
queue<int> que;
s[1] = 0;
for (int i = 0; i < v[1].size(); i++) {
que.push(v[1][i]);
s[v[1][i]] = 1;
}
while (!que.empty()) {
int p = que.front();
que.pop();
for (int i = 0; i < v[p].size(); i++) {
int g = v[p][i];
if (s[g] == -1) {
s[g] = p;
que.push(g);
}
}
}
int flag = 1;
for (int i = 2; i <= n; i++) {
if (s[i] == -1) {
flag = 0;
break;
}
}
if (flag) {
cout << "Yes" << endl;
for (int i = 2; i <= n; i++) {
cout << s[i] << endl;
}
} else {
cout << "No" << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int s[205000];
vector<int> v[205000];
int main() {
int n, m;
memset(s, -1, sizeof(s));
cin >> n >> m;
while (m--) {
int u, v1;
cin >> u >> v1;
v[u].push_back(v1);
v[v1].push_back(u);
}
queue<int> que;
s[1] = 0;
for (int i = 0; i < v[1].size(); i++) {
que.push(v[1][i]);
s[v[1][i]] = 1;
}
while (!que.empty()) {
int p = que.front();
que.pop();
for (int i = 0; i < v[p].size(); i++) {
int g = v[p][i];
if (s[g] == -1) {
s[g] = p;
que.push(g);
}
}
}
int flag = 1;
for (int i = 2; i <= n; i++) {
if (s[i] == -1) {
flag = 0;
break;
}
}
if (flag) {
cout << "Yes" << endl;
for (int i = 2; i <= n; i++) {
cout << s[i] << endl;
}
} else {
cout << "No" << endl;
}
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02678 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int n, m;
bool v[100001], unvisited = false;
int ans[100001];
int dis[100001];
vector<int> adj[100001], newcurr;
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
newcurr.push_back(1);
int distance = 0;
while (0 == 0) {
vector<int> curr = newcurr;
newcurr.clear();
if (curr.size() == 0) {
break;
}
for (int i = 0; i < curr.size(); i++) {
v[curr[i]] = true;
dis[curr[i]] = distance;
}
distance++;
for (int i = 0; i < curr.size(); i++) {
for (int j = 0; j < adj[curr[i]].size(); j++) {
if (!v[adj[curr[i]][j]]) {
ans[adj[curr[i]][j]] = curr[i];
newcurr.push_back(adj[curr[i]][j]);
}
}
}
}
for (int i = 1; i <= n; i++) {
if (!v[i])
unvisited = true;
}
if (unvisited) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
for (int i = 2; i <= n; i++) {
cout << ans[i] << endl;
}
}
} | #include <bits/stdc++.h>
using namespace std;
int n, m;
bool v[100001], unvisited = false;
int ans[100001];
int dis[100001];
vector<int> adj[100001], newcurr;
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
newcurr.push_back(1);
int distance = 0;
while (0 == 0) {
vector<int> curr = newcurr;
newcurr.clear();
if (curr.size() == 0) {
break;
}
for (int i = 0; i < curr.size(); i++) {
v[curr[i]] = true;
dis[curr[i]] = distance;
}
distance++;
for (int i = 0; i < curr.size(); i++) {
for (int j = 0; j < adj[curr[i]].size(); j++) {
if (!v[adj[curr[i]][j]]) {
ans[adj[curr[i]][j]] = curr[i];
v[adj[curr[i]][j]] = true;
newcurr.push_back(adj[curr[i]][j]);
}
}
}
}
for (int i = 1; i <= n; i++) {
if (!v[i])
unvisited = true;
}
if (unvisited) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
for (int i = 2; i <= n; i++) {
cout << ans[i] << endl;
}
}
} | insert | 32 | 32 | 32 | 33 | TLE | |
p02678 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int N = 100010;
vector<int> G[N];
vector<int> D(N);
vector<int> B(N);
void dfs(int now) {
for (auto x : G[now]) {
int to = x;
if (D[to] > D[now] + 1) {
D[to] = D[now] + 1;
B[to] = now + 1;
dfs(to);
}
}
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
while (m--) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].push_back(b);
G[b].push_back(a);
}
for (int i = 0; i < N; i++) {
D[i] = 1e9;
}
D[0] = 0;
B[0] = -1;
dfs(0);
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
cout << B[i] << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 100010;
vector<int> G[N];
vector<int> D(N);
vector<int> B(N);
void dfs(int now) {
for (auto x : G[now]) {
int to = x;
if (D[to] > D[now] + 1) {
D[to] = D[now] + 1;
B[to] = now + 1;
dfs(to);
}
}
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
while (m--) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].push_back(b);
G[b].push_back(a);
}
for (int i = 0; i < N; i++) {
D[i] = 1e9;
}
D[0] = 0;
B[0] = -1;
queue<int> q;
q.push(0);
while (!q.empty()) {
int now = q.front();
q.pop();
for (auto x : G[now]) {
int to = x;
if (D[to] > D[now] + 1) {
D[to] = D[now] + 1;
B[to] = now + 1;
q.push(to);
}
}
}
dfs(0);
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
cout << B[i] << endl;
}
return 0;
} | insert | 40 | 40 | 40 | 55 | TLE | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> list(n, vector<int>(n));
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
--a;
--b;
list[a].push_back(b);
list[b].push_back(a);
}
queue<int> q;
vector<int> dist(n, INF);
vector<int> pre(n, -1);
dist[0] = 0;
q.push(0);
while (!q.empty()) {
int v = q.front();
q.pop();
for (int nv : list[v]) {
if (dist[nv] != INF) {
continue;
}
dist[nv] = dist[v] + 1;
pre[nv] = v;
q.push(nv);
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
cout << pre[i] + 1 << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> list(n);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
--a;
--b;
list[a].push_back(b);
list[b].push_back(a);
}
queue<int> q;
vector<int> dist(n, INF);
vector<int> pre(n, -1);
dist[0] = 0;
q.push(0);
while (!q.empty()) {
int v = q.front();
q.pop();
for (int nv : list[v]) {
if (dist[nv] != INF) {
continue;
}
dist[nv] = dist[v] + 1;
pre[nv] = v;
q.push(nv);
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
cout << pre[i] + 1 << endl;
}
return 0;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p02678 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
using namespace std;
int n, m, d[10005], tot;
vector<int> a[10005];
void bfs();
queue<int> q;
int main() {
cin >> n >> m;
for (int i = 1; i <= m; ++i) {
int x, y;
scanf("%d%d", &x, &y);
a[x].push_back(y);
a[y].push_back(x);
}
bfs();
return 0;
}
void bfs() {
d[1] = 1;
q.push(1);
while (!q.empty() && tot < n) {
int tmp = q.front();
q.pop();
++tot;
for (int i = 0; i < (int)a[tmp].size(); ++i) {
if (d[a[tmp][i]] != 0)
continue;
d[a[tmp][i]] = tmp;
q.push(a[tmp][i]);
}
}
if (tot == n) {
cout << "Yes\n";
for (int i = 2; i <= n; ++i)
printf("%d\n", d[i]);
return;
} else
cout << "No";
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
using namespace std;
int n, m, d[100005], tot;
vector<int> a[100005];
void bfs();
queue<int> q;
int main() {
cin >> n >> m;
for (int i = 1; i <= m; ++i) {
int x, y;
scanf("%d%d", &x, &y);
a[x].push_back(y);
a[y].push_back(x);
}
bfs();
return 0;
}
void bfs() {
d[1] = 1;
q.push(1);
while (!q.empty() && tot < n) {
int tmp = q.front();
q.pop();
++tot;
for (int i = 0; i < (int)a[tmp].size(); ++i) {
if (d[a[tmp][i]] != 0)
continue;
d[a[tmp][i]] = tmp;
q.push(a[tmp][i]);
}
}
if (tot == n) {
cout << "Yes\n";
for (int i = 2; i <= n; ++i)
printf("%d\n", d[i]);
return;
} else
cout << "No";
} | replace | 48 | 50 | 48 | 50 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(), x.end()
#define rep(i, j, n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
//(a+b-1)/b
using pl = pair<ll, ll>;
signed main() {
ll n, m;
cin >> n >> m;
vvl g(n, vl(n));
rep(i, 0, m) {
ll a, b;
cin >> a >> b;
--a;
--b;
g[a].push_back(b);
g[b].push_back(a);
}
vl ans(n);
vector<bool> seen(n);
seen[0] = 1;
queue<ll> q;
q.push(0);
while (!q.empty()) {
ll k = q.front();
q.pop();
for (auto c : g[k]) {
if (seen[c])
continue;
seen[c] = 1;
ans[c] = k;
q.push(c);
}
}
cout << "Yes" << endl;
rep(i, 1, n) cout << ans[i] + 1 << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(), x.end()
#define rep(i, j, n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
//(a+b-1)/b
using pl = pair<ll, ll>;
signed main() {
ll n, m;
cin >> n >> m;
vvl g(n, vl(0));
rep(i, 0, m) {
ll a, b;
cin >> a >> b;
--a;
--b;
g[a].push_back(b);
g[b].push_back(a);
}
vl ans(n);
vector<bool> seen(n);
seen[0] = 1;
queue<ll> q;
q.push(0);
while (!q.empty()) {
ll k = q.front();
q.pop();
for (auto c : g[k]) {
if (seen[c])
continue;
seen[c] = 1;
ans[c] = k;
q.push(c);
}
}
cout << "Yes" << endl;
rep(i, 1, n) cout << ans[i] + 1 << endl;
return 0;
} | replace | 30 | 31 | 30 | 31 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e7;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> graph(m);
for (int i = 0; i < m; ++i) {
int a, b;
cin >> a >> b;
// 配列の位置と入力の数値を統一する
--a;
--b;
// aからb,
// bからaの両方の方向を検討するために順番を入れ替えて二次元配列に代入する
graph.at(a).push_back(b);
graph.at(b).push_back(a);
/*
// aからb,
bからaの両方の方向を検討するために順番を入れ替えて二次元配列に代入する
graph.at(a).at(b);
graph.at(b).at(a);
*/
}
// BFSのためにキューを用意する
queue<int> q;
// 原点からの距離とどの部屋からその部屋に行けるかの位置を示す配列を用意
vector<int> dist(n, INF);
vector<int> pre(n, -1);
// 原点への距離を0で初期化
dist.at(0) = 0;
// キューに原点を始点として進むことのできる部屋を追加
q.push(0);
while (!q.empty()) {
// キューの先頭データをコピー
int v = q.front();
// 先頭データを削除
q.pop();
// キューに保存された場所から到達できる部屋について距離を確定させる
for (auto u : graph.at(v)) {
// すでに距離が更新されている場合は、何もしない
if (dist.at(u) != INF) {
continue;
}
// 点vから到達できる点uへの距離は、原点から点vまで到達するまでにかかる距離+1となる
dist.at(u) = dist.at(v) + 1;
// 点uにつながる点を記録
pre.at(u) = v;
// 点vから到達できる点uをキューに格納し、点uから再びBFSを実施
q.push(u);
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; ++i) {
// int ans = ++pre.at(i);
int ans = pre.at(i);
++ans;
cout << ans << endl;
}
return 0;
}
// 二次元配列の宣言方法の違い
// 10行0列の二次元配列の宣言方法
/*
int test_func(){
int a = 3, b = 2;
vector <int> to[10];
to[a].push_back(b);
to[a].push_back(a);
vector<vector<int>> test(10);
test.at(a).push_back(b);
test.at(a).push_back(a);
cout << "to is ..." << endl;
for (auto x: to[3]){
cout << x << endl;
}
cout << "test is ..." << endl;
for (auto x: test.at(3)){
cout << x << endl;
}
return 0;
}
*/ | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e7;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> graph(n);
for (int i = 0; i < m; ++i) {
int a, b;
cin >> a >> b;
// 配列の位置と入力の数値を統一する
--a;
--b;
// aからb,
// bからaの両方の方向を検討するために順番を入れ替えて二次元配列に代入する
graph.at(a).push_back(b);
graph.at(b).push_back(a);
/*
// aからb,
bからaの両方の方向を検討するために順番を入れ替えて二次元配列に代入する
graph.at(a).at(b);
graph.at(b).at(a);
*/
}
// BFSのためにキューを用意する
queue<int> q;
// 原点からの距離とどの部屋からその部屋に行けるかの位置を示す配列を用意
vector<int> dist(n, INF);
vector<int> pre(n, -1);
// 原点への距離を0で初期化
dist.at(0) = 0;
// キューに原点を始点として進むことのできる部屋を追加
q.push(0);
while (!q.empty()) {
// キューの先頭データをコピー
int v = q.front();
// 先頭データを削除
q.pop();
// キューに保存された場所から到達できる部屋について距離を確定させる
for (auto u : graph.at(v)) {
// すでに距離が更新されている場合は、何もしない
if (dist.at(u) != INF) {
continue;
}
// 点vから到達できる点uへの距離は、原点から点vまで到達するまでにかかる距離+1となる
dist.at(u) = dist.at(v) + 1;
// 点uにつながる点を記録
pre.at(u) = v;
// 点vから到達できる点uをキューに格納し、点uから再びBFSを実施
q.push(u);
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; ++i) {
// int ans = ++pre.at(i);
int ans = pre.at(i);
++ans;
cout << ans << endl;
}
return 0;
}
// 二次元配列の宣言方法の違い
// 10行0列の二次元配列の宣言方法
/*
int test_func(){
int a = 3, b = 2;
vector <int> to[10];
to[a].push_back(b);
to[a].push_back(a);
vector<vector<int>> test(10);
test.at(a).push_back(b);
test.at(a).push_back(a);
cout << "to is ..." << endl;
for (auto x: to[3]){
cout << x << endl;
}
cout << "test is ..." << endl;
for (auto x: test.at(3)){
cout << x << endl;
}
return 0;
}
*/ | replace | 11 | 12 | 11 | 12 | 0 | |
p02678 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
#define repa(i, a, b) for (auto i = (a); i <= (b); i++)
#define repd(i, a, b) for (auto i = (a); i >= (b); i--)
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define zero(a) memset((a), 0, sizeof(a))
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
constexpr auto inf = numeric_limits<int>().max();
constexpr auto llinf = numeric_limits<ll>().max();
template <typename ForwardIterator>
void dump(ForwardIterator st, ForwardIterator en) {
for (auto it = st; it != en; it++) {
cout << *it << " ";
}
cout << endl;
}
template <typename ForwardIterator>
void dump_map(ForwardIterator st, ForwardIterator en) {
for (auto it = st; it != en; it++) {
cout << (*it).first << ":" << (*it).second << " ";
}
cout << endl;
}
template <typename T> void debug(initializer_list<T> list) {
for (auto el : list) {
cout << el << " ";
}
cout << endl;
}
int n, m;
vvi adj;
constexpr int mxN = 100010;
bitset<mxN> visited;
vi parent;
void bfs(int st) {
queue<int> q;
q.push(st);
while (!q.empty()) {
auto u = q.front();
// debug({u});
q.pop();
// if (visited.test(u)) continue;
for (auto v : adj[u]) {
if (!visited.test(v)) {
if (parent[v] == -1) {
parent[v] = u;
}
q.push(v);
}
}
visited.set(u);
}
}
void solve() {
cin >> n >> m;
adj.resize(n + 1);
int a, b;
rep(i, m) {
cin >> a >> b;
adj[a].pb(b);
adj[b].pb(a);
}
// repa(i, 1, n) {
// cout << i << ": ";
// dump(all(adj[i]));
// }
visited.reset();
parent.resize(n + 1);
fill(all(parent), -1);
bfs(1);
if (find(parent.begin() + 2, parent.end(), -1) == parent.end()) {
cout << "Yes\n";
repa(i, 2, n) { cout << parent[i] << "\n"; }
} else {
cout << "No\n";
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
#define repa(i, a, b) for (auto i = (a); i <= (b); i++)
#define repd(i, a, b) for (auto i = (a); i >= (b); i--)
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define zero(a) memset((a), 0, sizeof(a))
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
constexpr auto inf = numeric_limits<int>().max();
constexpr auto llinf = numeric_limits<ll>().max();
template <typename ForwardIterator>
void dump(ForwardIterator st, ForwardIterator en) {
for (auto it = st; it != en; it++) {
cout << *it << " ";
}
cout << endl;
}
template <typename ForwardIterator>
void dump_map(ForwardIterator st, ForwardIterator en) {
for (auto it = st; it != en; it++) {
cout << (*it).first << ":" << (*it).second << " ";
}
cout << endl;
}
template <typename T> void debug(initializer_list<T> list) {
for (auto el : list) {
cout << el << " ";
}
cout << endl;
}
int n, m;
vvi adj;
constexpr int mxN = 100010;
bitset<mxN> visited;
vi parent;
void bfs(int st) {
queue<int> q;
q.push(st);
while (!q.empty()) {
auto u = q.front();
// debug({u});
q.pop();
if (visited.test(u))
continue;
for (auto v : adj[u]) {
if (!visited.test(v)) {
if (parent[v] == -1) {
parent[v] = u;
}
q.push(v);
}
}
visited.set(u);
}
}
void solve() {
cin >> n >> m;
adj.resize(n + 1);
int a, b;
rep(i, m) {
cin >> a >> b;
adj[a].pb(b);
adj[b].pb(a);
}
// repa(i, 1, n) {
// cout << i << ": ";
// dump(all(adj[i]));
// }
visited.reset();
parent.resize(n + 1);
fill(all(parent), -1);
bfs(1);
if (find(parent.begin() + 2, parent.end(), -1) == parent.end()) {
cout << "Yes\n";
repa(i, 2, n) { cout << parent[i] << "\n"; }
} else {
cout << "No\n";
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
| replace | 57 | 58 | 57 | 59 | TLE | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int inf = 10000000;
typedef pair<int, int> P;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> to(n);
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
to[a].push_back(b);
to[b].push_back(a);
}
vector<int> parent(n, inf);
queue<int> que;
for (int i = 0; i < to[0].size(); i++) {
que.push(to[0][i]);
parent[to[0][i]] = 1;
}
while (!que.empty()) {
int k = que.front();
que.pop();
for (int i = 0; i < to[k].size(); i++) {
if (parent[to[k][i]] == inf) {
que.push(to[k][i]);
parent[to[k][i]] = k + 1;
}
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; i++)
cout << parent[i] << endl;
} | #include <bits/stdc++.h>
using namespace std;
int inf = 10000000;
typedef pair<int, int> P;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> to(n);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
to[a].push_back(b);
to[b].push_back(a);
}
vector<int> parent(n, inf);
queue<int> que;
for (int i = 0; i < to[0].size(); i++) {
que.push(to[0][i]);
parent[to[0][i]] = 1;
}
while (!que.empty()) {
int k = que.front();
que.pop();
for (int i = 0; i < to[k].size(); i++) {
if (parent[to[k][i]] == inf) {
que.push(to[k][i]);
parent[to[k][i]] = k + 1;
}
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; i++)
cout << parent[i] << endl;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p02678 | C++ | Runtime Error | // C++(Clang 10.0.0)
// GCC用 ナゾです
// #pragma GCC target("avx")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <cassert> //assert(x>=0) -> x<0の時異常終了
#include <cmath>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <regex> //正規表現
#include <set>
#include <stdio.h>
#include <stdlib.h> //rand() 0~RAND_MAX2147483647
#include <time.h> //srand((unsigned int)time(NULL));
#include <tuple>
#include <unistd.h> //sleep
#include <unordered_map>
#include <vector>
using namespace std;
#define ll long long int
#define FOR(i, min, max) for (ll i = (min); i < (max); i++)
#define FOReq(i, min, max) for (ll i = (min); i <= (max); i++)
#define FORREV(i, max, min) for (ll i = (max)-1; i >= (min); i--)
#define FORREVeq(i, max, min) for (ll i = (max); i >= (min); i--)
#define all(vec) (vec).begin(), (vec).end()
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const int not0 = 1;
const int INF = 2000000001;
const ll INFll = 2e18;
// const int MAX_V=10000;
const double Micro = 1e-5;
int UnUsedVariable() {
if (INF || Micro || MOD || INFll || MOD2 || not0) {
;
}
return 0;
}
#define inarray(array, min, max) \
FOR(i, min, max) { cin >> array[i]; }
#define inarrayW(arrayA, arrayB, min, max) \
FOR(i, min, max) { cin >> arrayA[i] >> arrayB[i]; }
// #define br printf("\n");
#define br cout << "\n";
#define OutputAndReturn0(x) \
{ \
cout << (x) << endl; \
return 0; \
}
#define elif else if
#define issame(a, b, c, d) ((a) == (b) and (b) == (c) and (c) == (d))
#define isdiff3(a, b, c) ((a) != (b) and (b) != (c) and (c) != (a))
#define isdiff4(a, b, c, d) \
((a) != (b) and (b) != (c) and (c) != (a) and (d) != (a) and (d) != (b) and \
(d) != (c))
#define isdiff5(a, b, c, d, e) \
((a) != (b) and (b) != (c) and (c) != (a) and (d) != (a) and (d) != (b) and \
(d) != (c) and (e) != (a) and (e) != (b) and (e) != (c) and (e) != (d))
#define Func3(f, a, b, c) (f)((f)((a), (b)), (c))
#define Func4(f, a, b, c, d) (f)((f)((f)((a), (b)), (c)), (d))
inline int isEven(int x) { return x % 2 == 0; }
inline int isOdd(int x) { return x % 2 == 1; }
inline ll samepair(ll x) { return x * (x - 1) / 2; }
inline void printD(double d) { printf("%15.15lf ", d); }
inline ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
} // 最大公約数 なお一方が0なら答えは他方になるので番兵は0で良い
// また、負の数もOK -4%3=-1となるため
inline ll lcm(ll a, ll b) {
return a * b / gcd(a, b);
} // MODやオーバーフローには注意!
// inline ll ceil(double a){return (ll)a+1;}
// ans = accumulate(A, A+N, 0, [](int a, int b) {return gcd(a,b);});
// auto count = std::count_if(v.begin(), v.end(), [](int x) { return x == 1 || x
// == 3; } );
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};
// 番兵 累積和 しゃくとり法 木構造 DP
// キュー 乱択アルゴリズム 嘘解法 ハッシュ next_permulation
// 課題:DP 木構造 Xor
// 多い失敗:小数点以下表示しきれてない オーバーフロー そもそも嘘解法
// Nが10^6 → O(N)かO(N log N)
// Nが10^5 → O(N log N)かO(N log2 N)
// Nが3000 → O(N^2)
// Nが300 → O(N^3)(シンプルな処理)
// Nが100 → O(N^3)
// Nが50 → O(N^4)
// Nが20 → O(2^N)かO(N * 2^N)
ll probA() {
ll ans;
ans = 0;
ll N;
N = 0;
cin >> N;
ll one = N % 10;
if (one == 3) {
OutputAndReturn0("bon");
} else if (one == 0 or one == 1 or one == 6 or one == 8) {
OutputAndReturn0("pon");
} else
OutputAndReturn0("hon")
OutputAndReturn0(ans);
return 0;
}
ll probB() {
string ans;
ll K;
string S;
cin >> K >> S;
cout << S.substr(0, K);
if (K < S.length())
cout << "...";
br;
// OutputAndReturn0(ans);
return 0;
}
ll probC() {
double ans;
ans = 0;
double hourM, miniM, H, M;
cin >> hourM >> miniM >> H >> M;
const double pi = 3.14159265358979323846;
double hx, hy, mx, my;
mx = miniM * cos(2 * pi * M / 60);
my = miniM * sin(2 * pi * M / 60);
double nowmin = 60 * H + M;
double totalmin = 60 * 12;
hx = hourM * cos(2 * pi * nowmin / totalmin);
hy = hourM * sin(2 * pi * nowmin / totalmin);
ans = sqrt(pow((hx - mx), 2) + pow((hy - my), 2));
printf("%15.15lf \n", ans);
// OutputAndReturn0(ans);
return 0;
}
ll probD() {
ll ans;
ans = 0;
ll N;
N = 0;
cin >> N;
ll A[N], B[N];
inarrayW(A, B, 0, N);
double ratio[N];
const ll Ais0 = pow(10, 18) + 100;
const ll Bis0 = pow(10, 18) + 150;
const ll ABis0 = pow(10, 18) + 200;
FOR(i, 0, N) {
if (A[i] == 0) {
if (B[i] == 0) {
ratio[i] = ABis0;
} else {
ratio[i] = Ais0;
}
} else if (B[i] == 0) {
ratio[i] = Bis0;
} else
ratio[i] = A[i] / B[i];
}
OutputAndReturn0(ans);
return 0;
}
ll probE() {
ll ans;
ans = 0;
ll N, M;
cin >> N >> M;
vector<vector<ll>> Graph(M + 1);
for (ll i = 0; i < M; ++i) {
ll a, b;
cin >> a >> b;
Graph[b].push_back(a); // 逆向きに辺を張る
Graph[a].push_back(b);
}
cout << "Yes" << endl;
deque<ll> dq;
dq.push_back(1);
ll arrived[N + 1];
FOR(i, 0, N + 1) { arrived[i] = -1; }
arrived[0] = 0;
arrived[1] = 0;
while (!dq.empty()) {
ll now;
now = dq.front();
dq.pop_front();
for (auto &e : Graph[now]) {
if (arrived[e] == -1) {
arrived[e] = now;
dq.push_back(e);
}
}
}
FOR(i, 2, N + 1) { cout << arrived[i] << endl; }
// OutputAndReturn0(ans);
return 0;
}
ll probF() {
ll ans;
ans = 0;
ll N;
N = 0;
cin >> N;
OutputAndReturn0(ans);
return 0;
}
signed main() {
// cin.tie(0);
// //cinとcoutの結び付き解除(cout時にcinの内容を吐き出さなくなる)
// ios::sync_with_stdio(false);
// //coutとprintfの結び付き解除(coutとprintfを同時に使うな!)
probE();
// cout<<(ll)pow(10,18)+10 ;
return 0;
}
| // C++(Clang 10.0.0)
// GCC用 ナゾです
// #pragma GCC target("avx")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <cassert> //assert(x>=0) -> x<0の時異常終了
#include <cmath>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <regex> //正規表現
#include <set>
#include <stdio.h>
#include <stdlib.h> //rand() 0~RAND_MAX2147483647
#include <time.h> //srand((unsigned int)time(NULL));
#include <tuple>
#include <unistd.h> //sleep
#include <unordered_map>
#include <vector>
using namespace std;
#define ll long long int
#define FOR(i, min, max) for (ll i = (min); i < (max); i++)
#define FOReq(i, min, max) for (ll i = (min); i <= (max); i++)
#define FORREV(i, max, min) for (ll i = (max)-1; i >= (min); i--)
#define FORREVeq(i, max, min) for (ll i = (max); i >= (min); i--)
#define all(vec) (vec).begin(), (vec).end()
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const int not0 = 1;
const int INF = 2000000001;
const ll INFll = 2e18;
// const int MAX_V=10000;
const double Micro = 1e-5;
int UnUsedVariable() {
if (INF || Micro || MOD || INFll || MOD2 || not0) {
;
}
return 0;
}
#define inarray(array, min, max) \
FOR(i, min, max) { cin >> array[i]; }
#define inarrayW(arrayA, arrayB, min, max) \
FOR(i, min, max) { cin >> arrayA[i] >> arrayB[i]; }
// #define br printf("\n");
#define br cout << "\n";
#define OutputAndReturn0(x) \
{ \
cout << (x) << endl; \
return 0; \
}
#define elif else if
#define issame(a, b, c, d) ((a) == (b) and (b) == (c) and (c) == (d))
#define isdiff3(a, b, c) ((a) != (b) and (b) != (c) and (c) != (a))
#define isdiff4(a, b, c, d) \
((a) != (b) and (b) != (c) and (c) != (a) and (d) != (a) and (d) != (b) and \
(d) != (c))
#define isdiff5(a, b, c, d, e) \
((a) != (b) and (b) != (c) and (c) != (a) and (d) != (a) and (d) != (b) and \
(d) != (c) and (e) != (a) and (e) != (b) and (e) != (c) and (e) != (d))
#define Func3(f, a, b, c) (f)((f)((a), (b)), (c))
#define Func4(f, a, b, c, d) (f)((f)((f)((a), (b)), (c)), (d))
inline int isEven(int x) { return x % 2 == 0; }
inline int isOdd(int x) { return x % 2 == 1; }
inline ll samepair(ll x) { return x * (x - 1) / 2; }
inline void printD(double d) { printf("%15.15lf ", d); }
inline ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
} // 最大公約数 なお一方が0なら答えは他方になるので番兵は0で良い
// また、負の数もOK -4%3=-1となるため
inline ll lcm(ll a, ll b) {
return a * b / gcd(a, b);
} // MODやオーバーフローには注意!
// inline ll ceil(double a){return (ll)a+1;}
// ans = accumulate(A, A+N, 0, [](int a, int b) {return gcd(a,b);});
// auto count = std::count_if(v.begin(), v.end(), [](int x) { return x == 1 || x
// == 3; } );
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};
// 番兵 累積和 しゃくとり法 木構造 DP
// キュー 乱択アルゴリズム 嘘解法 ハッシュ next_permulation
// 課題:DP 木構造 Xor
// 多い失敗:小数点以下表示しきれてない オーバーフロー そもそも嘘解法
// Nが10^6 → O(N)かO(N log N)
// Nが10^5 → O(N log N)かO(N log2 N)
// Nが3000 → O(N^2)
// Nが300 → O(N^3)(シンプルな処理)
// Nが100 → O(N^3)
// Nが50 → O(N^4)
// Nが20 → O(2^N)かO(N * 2^N)
ll probA() {
ll ans;
ans = 0;
ll N;
N = 0;
cin >> N;
ll one = N % 10;
if (one == 3) {
OutputAndReturn0("bon");
} else if (one == 0 or one == 1 or one == 6 or one == 8) {
OutputAndReturn0("pon");
} else
OutputAndReturn0("hon")
OutputAndReturn0(ans);
return 0;
}
ll probB() {
string ans;
ll K;
string S;
cin >> K >> S;
cout << S.substr(0, K);
if (K < S.length())
cout << "...";
br;
// OutputAndReturn0(ans);
return 0;
}
ll probC() {
double ans;
ans = 0;
double hourM, miniM, H, M;
cin >> hourM >> miniM >> H >> M;
const double pi = 3.14159265358979323846;
double hx, hy, mx, my;
mx = miniM * cos(2 * pi * M / 60);
my = miniM * sin(2 * pi * M / 60);
double nowmin = 60 * H + M;
double totalmin = 60 * 12;
hx = hourM * cos(2 * pi * nowmin / totalmin);
hy = hourM * sin(2 * pi * nowmin / totalmin);
ans = sqrt(pow((hx - mx), 2) + pow((hy - my), 2));
printf("%15.15lf \n", ans);
// OutputAndReturn0(ans);
return 0;
}
ll probD() {
ll ans;
ans = 0;
ll N;
N = 0;
cin >> N;
ll A[N], B[N];
inarrayW(A, B, 0, N);
double ratio[N];
const ll Ais0 = pow(10, 18) + 100;
const ll Bis0 = pow(10, 18) + 150;
const ll ABis0 = pow(10, 18) + 200;
FOR(i, 0, N) {
if (A[i] == 0) {
if (B[i] == 0) {
ratio[i] = ABis0;
} else {
ratio[i] = Ais0;
}
} else if (B[i] == 0) {
ratio[i] = Bis0;
} else
ratio[i] = A[i] / B[i];
}
OutputAndReturn0(ans);
return 0;
}
ll probE() {
ll ans;
ans = 0;
ll N, M;
cin >> N >> M;
vector<vector<ll>> Graph(N + 1);
for (ll i = 0; i < M; ++i) {
ll a, b;
cin >> a >> b;
Graph[b].push_back(a); // 逆向きに辺を張る
Graph[a].push_back(b);
}
cout << "Yes" << endl;
deque<ll> dq;
dq.push_back(1);
ll arrived[N + 1];
FOR(i, 0, N + 1) { arrived[i] = -1; }
arrived[0] = 0;
arrived[1] = 0;
while (!dq.empty()) {
ll now;
now = dq.front();
dq.pop_front();
for (auto &e : Graph[now]) {
if (arrived[e] == -1) {
arrived[e] = now;
dq.push_back(e);
}
}
}
FOR(i, 2, N + 1) { cout << arrived[i] << endl; }
// OutputAndReturn0(ans);
return 0;
}
ll probF() {
ll ans;
ans = 0;
ll N;
N = 0;
cin >> N;
OutputAndReturn0(ans);
return 0;
}
signed main() {
// cin.tie(0);
// //cinとcoutの結び付き解除(cout時にcinの内容を吐き出さなくなる)
// ios::sync_with_stdio(false);
// //coutとprintfの結び付き解除(coutとprintfを同時に使うな!)
probE();
// cout<<(ll)pow(10,18)+10 ;
return 0;
}
| replace | 214 | 215 | 214 | 215 | 0 | |
p02678 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#define faster \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;
vector<int> g[MAXN];
int main() {
faster int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].push_back(b);
g[b].push_back(a);
}
vector<int> p(n, -1);
vector<bool> was(n, false);
queue<int> q;
q.push(0);
while (!q.empty()) {
int v = q.front();
q.pop();
was[v] = true;
for (int to : g[v]) {
if (!was[to]) {
q.push(to);
if (p[to] < 0)
p[to] = v;
}
}
}
for (int i = 1; i < n; i++) {
if (p[i] < 0) {
cout << "No\n";
return 0;
}
}
cout << "Yes\n";
for (int i = 1; i < n; i++) {
cout << p[i] + 1 << "\n";
}
return 0;
}
| #include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#define faster \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;
vector<int> g[MAXN];
int main() {
faster int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].push_back(b);
g[b].push_back(a);
}
vector<int> p(n, -1);
vector<bool> was(n, false);
queue<int> q;
q.push(0);
while (!q.empty()) {
int v = q.front();
q.pop();
if (was[v])
continue;
was[v] = true;
for (int to : g[v]) {
if (!was[to]) {
q.push(to);
if (p[to] < 0)
p[to] = v;
}
}
}
for (int i = 1; i < n; i++) {
if (p[i] < 0) {
cout << "No\n";
return 0;
}
}
cout << "Yes\n";
for (int i = 1; i < n; i++) {
cout << p[i] + 1 << "\n";
}
return 0;
}
| insert | 33 | 33 | 33 | 35 | TLE | |
p02678 | C++ | Runtime Error | #pragma GCC optimize(3)
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>*/
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define INFI 2147483647
#define INFL 9223372036854775807
#define INFU 18446744073709551615
#define maxn 200005
using namespace std;
// using namespace __gnu_pbds;
const double PI = acos(-1.0);
const double eps = 1e-6;
struct Edge {
int to, nxt;
} edge[maxn];
bool vis[maxn];
int cnt, head[maxn], ans[maxn];
void addedge(int u, int v) {
edge[cnt].to = v;
edge[cnt].nxt = head[u];
head[u] = cnt++;
return;
}
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
void bfs() {
queue<int> q;
q.push(1);
vis[1] = 1;
while (!q.empty()) {
int u = q.front();
q.pop();
for (int k = head[u]; k != -1; k = edge[k].nxt) {
int v = edge[k].to;
if (!vis[v]) {
q.push(v);
ans[v] = u;
vis[v] = 1;
}
}
}
return;
}
int main() {
// ios_base::sync_with_stdio(false);
// cin.tie(0);
// cout.tie(0);
int n = read(), m = read();
memset(head, -1, sizeof(head));
for (int i = 1; i <= m; i++) {
int u = read(), v = read();
addedge(u, v);
addedge(v, u);
}
bfs();
for (int i = 2; i <= n; i++) {
if (ans[i] == 0) {
printf("No\n");
return 0;
}
}
printf("Yes\n");
for (int i = 2; i <= n; i++)
printf("%d\n", ans[i]);
return 0;
}
| #pragma GCC optimize(3)
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>*/
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define INFI 2147483647
#define INFL 9223372036854775807
#define INFU 18446744073709551615
#define maxn 400005
using namespace std;
// using namespace __gnu_pbds;
const double PI = acos(-1.0);
const double eps = 1e-6;
struct Edge {
int to, nxt;
} edge[maxn];
bool vis[maxn];
int cnt, head[maxn], ans[maxn];
void addedge(int u, int v) {
edge[cnt].to = v;
edge[cnt].nxt = head[u];
head[u] = cnt++;
return;
}
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
void bfs() {
queue<int> q;
q.push(1);
vis[1] = 1;
while (!q.empty()) {
int u = q.front();
q.pop();
for (int k = head[u]; k != -1; k = edge[k].nxt) {
int v = edge[k].to;
if (!vis[v]) {
q.push(v);
ans[v] = u;
vis[v] = 1;
}
}
}
return;
}
int main() {
// ios_base::sync_with_stdio(false);
// cin.tie(0);
// cout.tie(0);
int n = read(), m = read();
memset(head, -1, sizeof(head));
for (int i = 1; i <= m; i++) {
int u = read(), v = read();
addedge(u, v);
addedge(v, u);
}
bfs();
for (int i = 2; i <= n; i++) {
if (ans[i] == 0) {
printf("No\n");
return 0;
}
}
printf("Yes\n");
for (int i = 2; i <= n; i++)
printf("%d\n", ans[i]);
return 0;
}
| replace | 26 | 27 | 26 | 27 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
vector<int> to[10005];
void bfs(int n) {
queue<int> q;
vector<int> dist(n, -1);
vector<int> pre(n, -1);
q.push(0);
dist[0] = 0;
while (!q.empty()) {
int v = q.front();
q.pop();
for (int u : to[v]) {
if (dist[u] != -1)
continue;
dist[u] = dist[v] + 1;
pre[u] = v;
q.push(u);
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; ++i) {
cout << pre[i] + 1 << endl;
}
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; ++i) {
int a, b;
cin >> a >> b;
--a;
--b;
to[a].push_back(b);
to[b].push_back(a);
}
bfs(n);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
vector<int> to[100005];
void bfs(int n) {
queue<int> q;
vector<int> dist(n, -1);
vector<int> pre(n, -1);
q.push(0);
dist[0] = 0;
while (!q.empty()) {
int v = q.front();
q.pop();
for (int u : to[v]) {
if (dist[u] != -1)
continue;
dist[u] = dist[v] + 1;
pre[u] = v;
q.push(u);
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; ++i) {
cout << pre[i] + 1 << endl;
}
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; ++i) {
int a, b;
cin >> a >> b;
--a;
--b;
to[a].push_back(b);
to[b].push_back(a);
}
bfs(n);
return 0;
} | replace | 2 | 3 | 2 | 3 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;
vector<int> G[10010];
int main() {
int n, m;
cin >> n >> m;
rep(i, m) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].push_back(b);
G[b].push_back(a);
}
vector<int> dist(n, -1);
vector<int> pre(n, -1);
queue<int> que;
dist[0] = 0;
que.push(0);
while (!que.empty()) {
int v = que.front();
que.pop();
for (int nv : G[v]) {
if (dist[nv] != -1)
continue;
dist[nv] = dist[v] + 1;
pre[nv] = v;
que.push(nv);
}
}
cout << "Yes" << endl;
rep(i, n) {
if (i == 0)
continue;
int ans = pre[i];
ans++;
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;
vector<int> G[100100];
int main() {
int n, m;
cin >> n >> m;
rep(i, m) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].push_back(b);
G[b].push_back(a);
}
vector<int> dist(n, -1);
vector<int> pre(n, -1);
queue<int> que;
dist[0] = 0;
que.push(0);
while (!que.empty()) {
int v = que.front();
que.pop();
for (int nv : G[v]) {
if (dist[nv] != -1)
continue;
dist[nv] = dist[v] + 1;
pre[nv] = v;
que.push(nv);
}
}
cout << "Yes" << endl;
rep(i, n) {
if (i == 0)
continue;
int ans = pre[i];
ans++;
cout << ans << endl;
}
return 0;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p02678 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<set<int>> path(n);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
path.at(a - 1).insert(b - 1);
path.at(b - 1).insert(a - 1);
}
queue<int> q;
vector<int> depth(n, -1);
vector<int> done(n, 0);
vector<int> parent(n, 0);
q.push(0);
done.at(0) = 1;
depth.at(0) = 0;
while (!q.empty()) {
int front = q.front();
done.at(front) = 1;
for (int i = 0; i < n; i++) {
if (path.at(front).count(i) && done.at(i) == 0) {
q.push(i);
done.at(i) = 1;
depth.at(i) = depth.at(front) + 1;
parent.at(i) = front;
}
}
q.pop();
}
for (int i = 0; i < n; i++) {
if (depth.at(i) == -1) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
cout << parent.at(i) + 1 << endl;
// cout << depth.at(i) << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<set<int>> path(n);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
path.at(a - 1).insert(b - 1);
path.at(b - 1).insert(a - 1);
}
queue<int> q;
vector<int> depth(n, -1);
vector<int> done(n, 0);
vector<int> parent(n, 0);
q.push(0);
done.at(0) = 1;
depth.at(0) = 0;
while (!q.empty()) {
int front = q.front();
done.at(front) = 1;
for (auto value : path.at(front)) {
if (done.at(value) == 0) {
q.push(value);
done.at(value) = 1;
depth.at(value) = depth.at(front) + 1;
parent.at(value) = front;
}
}
q.pop();
}
for (int i = 0; i < n; i++) {
if (depth.at(i) == -1) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
cout << parent.at(i) + 1 << endl;
// cout << depth.at(i) << endl;
}
}
| replace | 22 | 28 | 22 | 28 | TLE | |
p02678 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
vector<int> a[200010];
int dis[200010];
int main() {
int n, m;
while (cin >> n >> m) {
ll ans = 0;
for (int i = 1; i <= n; ++i) {
dis[i] = n + 10;
}
int x, y;
for (int i = 0; i < m; ++i) {
scanf("%d%d", &x, &y);
a[x].push_back(y);
a[y].push_back(x);
}
queue<pair<int, int>> q;
q.push(mk(0, 1));
pair<int, int> tmp;
while (!q.empty()) {
tmp = q.front();
q.pop();
if (dis[tmp.sc] < tmp.fs) {
continue;
}
dis[tmp.sc] = tmp.fs;
for (auto it : a[tmp.sc]) {
q.push(mk(tmp.fs + 1, it));
}
}
// for(int i=1; i<=n; ++i){
// b[dis[i]].push_back(i);
// }
printf("Yes\n");
for (int i = 1; i <= n; ++i) {
for (auto it : a[i]) {
if (dis[it] < dis[i]) {
printf("%d\n", it);
break;
}
}
}
}
return 0;
}
| #include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
vector<int> a[200010];
int dis[200010];
int main() {
int n, m;
while (cin >> n >> m) {
ll ans = 0;
for (int i = 1; i <= n; ++i) {
dis[i] = n + 10;
}
int x, y;
for (int i = 0; i < m; ++i) {
scanf("%d%d", &x, &y);
a[x].push_back(y);
a[y].push_back(x);
}
queue<pair<int, int>> q;
q.push(mk(0, 1));
pair<int, int> tmp;
while (!q.empty()) {
tmp = q.front();
q.pop();
if (dis[tmp.sc] <= tmp.fs) {
continue;
}
dis[tmp.sc] = tmp.fs;
for (auto it : a[tmp.sc]) {
q.push(mk(tmp.fs + 1, it));
}
}
// for(int i=1; i<=n; ++i){
// b[dis[i]].push_back(i);
// }
printf("Yes\n");
for (int i = 1; i <= n; ++i) {
for (auto it : a[i]) {
if (dis[it] < dis[i]) {
printf("%d\n", it);
break;
}
}
}
}
return 0;
}
| replace | 28 | 29 | 28 | 29 | TLE | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(), x.end()
#define rep(i, j, n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
#define mod 200003
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
//(a+b-1)/b
// priority_queue<ll, vector<ll>, greater<ll>> q;
using pl = pair<ll, ll>;
using vvb = vector<vector<bool>>;
using vb = vector<bool>;
ll f(ll a, ll b, ll p) {
if (b == 0)
return 1;
if (b % 2 == 0) {
ll t = f(a, b / 2, p);
return t * t % p;
}
return a * (f(a, b - 1, p)) % p;
}
//__builtin_popcount()
signed main() {
ll n, m;
cin >> n >> m;
vl g[n];
rep(i, 0, m) {
ll a, b;
cin >> a >> b;
--a;
--b;
g[a].push_back(b);
g[b].push_back(a);
}
vl ans{n + 10};
queue<ll> q;
q.push(0);
vector<bool> seen(n);
seen[0] = 1;
while (!q.empty()) {
ll k = q.front();
q.pop();
for (auto c : g[k]) {
if (seen[c])
continue;
seen[c] = 1;
ans[c] = k;
q.push(c);
}
}
cout << "Yes" << endl;
rep(i, 1, n) cout << ans[i] + 1 << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(), x.end()
#define rep(i, j, n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
#define mod 200003
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
//(a+b-1)/b
// priority_queue<ll, vector<ll>, greater<ll>> q;
using pl = pair<ll, ll>;
using vvb = vector<vector<bool>>;
using vb = vector<bool>;
ll f(ll a, ll b, ll p) {
if (b == 0)
return 1;
if (b % 2 == 0) {
ll t = f(a, b / 2, p);
return t * t % p;
}
return a * (f(a, b - 1, p)) % p;
}
//__builtin_popcount()
signed main() {
ll n, m;
cin >> n >> m;
vl g[n];
rep(i, 0, m) {
ll a, b;
cin >> a >> b;
--a;
--b;
g[a].push_back(b);
g[b].push_back(a);
}
vl ans(n + 10);
queue<ll> q;
q.push(0);
vector<bool> seen(n);
seen[0] = 1;
while (!q.empty()) {
ll k = q.front();
q.pop();
for (auto c : g[k]) {
if (seen[c])
continue;
seen[c] = 1;
ans[c] = k;
q.push(c);
}
}
cout << "Yes" << endl;
rep(i, 1, n) cout << ans[i] + 1 << endl;
return 0;
} | replace | 54 | 55 | 54 | 55 | -6 | free(): invalid pointer
|
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int mod = 1e9 + 7;
// const int mod = 998244353;
const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
void YesNo(bool j) {
cout << (j ? "Yes" : "No") << endl;
return;
}
void yesno(bool j) {
cout << (j ? "yes" : "no") << endl;
return;
}
template <class Head> void pt(Head &&head) {
cout << head << endl;
return;
}
vector<int> to[20005];
int main() {
int n, m;
cin >> n >> m;
rep(i, m) {
int u, v;
cin >> u >> v;
to[v].push_back(u);
to[u].push_back(v);
}
vector<int> c(n + 1, inf);
queue<int> q;
vector<int> ans(n + 1, -1);
c[1] = 1;
q.push(1);
while (!q.empty()) {
int a = q.front();
q.pop();
for (int i : to[a]) {
if (c[i] != inf)
continue;
c[i] = c[a] + 1;
ans[i] = a;
q.push(i);
}
}
/* bool ok=true;
for(int i=1 ;i<n+1;i++) {
if(c[i]==inf) ok=false;
}
if(!ok) {
pt("No");
}
else {
pt("Yes");
for(int i=2; i<=n; i++) {
pt(ans[i]);
}
}*/
pt("Yes");
for (int i = 2; i <= n; i++) {
pt(ans[i]);
}
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int mod = 1e9 + 7;
// const int mod = 998244353;
const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
void YesNo(bool j) {
cout << (j ? "Yes" : "No") << endl;
return;
}
void yesno(bool j) {
cout << (j ? "yes" : "no") << endl;
return;
}
template <class Head> void pt(Head &&head) {
cout << head << endl;
return;
}
vector<int> to[200005];
int main() {
int n, m;
cin >> n >> m;
rep(i, m) {
int u, v;
cin >> u >> v;
to[v].push_back(u);
to[u].push_back(v);
}
vector<int> c(n + 1, inf);
queue<int> q;
vector<int> ans(n + 1, -1);
c[1] = 1;
q.push(1);
while (!q.empty()) {
int a = q.front();
q.pop();
for (int i : to[a]) {
if (c[i] != inf)
continue;
c[i] = c[a] + 1;
ans[i] = a;
q.push(i);
}
}
/* bool ok=true;
for(int i=1 ;i<n+1;i++) {
if(c[i]==inf) ok=false;
}
if(!ok) {
pt("No");
}
else {
pt("Yes");
for(int i=2; i<=n; i++) {
pt(ans[i]);
}
}*/
pt("Yes");
for (int i = 2; i <= n; i++) {
pt(ans[i]);
}
return 0;
}
| replace | 22 | 23 | 22 | 23 | 0 | |
p02678 | C++ | Runtime Error | #include <iostream>
#include <queue>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<vector<int>> dp(n);
REP(i, n) {
int a, b;
cin >> a >> b;
a--, b--;
dp[a].push_back(b);
dp[b].push_back(a);
}
vector<int> dist(n, -1);
queue<int> q;
vector<int> pre(n, -1);
dist[0] = 0;
q.push(0);
while (!q.empty()) {
int v = q.front();
q.pop();
for (auto i : dp[v]) {
if (dist[i] != -1)
continue;
dist[i] = dist[v] + 1;
q.push(i);
pre[i] = v;
}
}
cout << "Yes" << '\n';
REP(i, n) {
if (i == 0)
continue;
cout << pre[i] + 1 << '\n';
}
return 0;
} | #include <iostream>
#include <queue>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<vector<int>> dp(n);
REP(i, m) {
int a, b;
cin >> a >> b;
a--, b--;
dp[a].push_back(b);
dp[b].push_back(a);
}
vector<int> dist(n, -1);
queue<int> q;
vector<int> pre(n, -1);
dist[0] = 0;
q.push(0);
while (!q.empty()) {
int v = q.front();
q.pop();
for (auto i : dp[v]) {
if (dist[i] != -1)
continue;
dist[i] = dist[v] + 1;
q.push(i);
pre[i] = v;
}
}
cout << "Yes" << '\n';
REP(i, n) {
if (i == 0)
continue;
cout << pre[i] + 1 << '\n';
}
return 0;
}
| replace | 14 | 15 | 14 | 15 | 0 | |
p02678 | C++ | Runtime Error | #include <iostream>
#include <queue>
#include <stdio.h>
#include <vector>
typedef long long ll;
#define debug(x) cerr << #x << ": " << x << "\n";
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<vector<int>> G(M);
rep(i, M) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].push_back(b);
G[b].push_back(a);
}
vector<int> ans(N, -1);
queue<int> q;
q.push(0);
while (!q.empty()) {
int s = q.front();
q.pop();
rep(i, G[s].size()) {
if (ans[G[s][i]] == -1) {
ans[G[s][i]] = s;
q.push(G[s][i]);
}
}
}
bool ok = true;
rep(i, N - 1) if (ans[i + 1] == -1) ok = false;
if (ok) {
cout << "Yes" << endl;
rep(i, N - 1) cout << ans[i + 1] + 1 << endl;
} else
cout << "No" << endl;
} | #include <iostream>
#include <queue>
#include <stdio.h>
#include <vector>
typedef long long ll;
#define debug(x) cerr << #x << ": " << x << "\n";
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<vector<int>> G(N);
rep(i, M) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].push_back(b);
G[b].push_back(a);
}
vector<int> ans(N, -1);
queue<int> q;
q.push(0);
while (!q.empty()) {
int s = q.front();
q.pop();
rep(i, G[s].size()) {
if (ans[G[s][i]] == -1) {
ans[G[s][i]] = s;
q.push(G[s][i]);
}
}
}
bool ok = true;
rep(i, N - 1) if (ans[i + 1] == -1) ok = false;
if (ok) {
cout << "Yes" << endl;
rep(i, N - 1) cout << ans[i + 1] + 1 << endl;
} else
cout << "No" << endl;
} | replace | 16 | 17 | 16 | 17 | 0 | |
p02678 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
// cin.tie(0);
// ios::sync_with_stdio(false);
int N, M;
scanf("%d %d", &N, &M);
vector<vector<pair<int, int>>> w(N + 1,
vector<pair<int, int>>()); //(部屋,道番号)
vector<pair<int, int>> result(N + 1, make_pair(N + 100, -1)); //(距離, 道)
int a, b;
for (int i = 1; i < M + 1; i++) {
scanf("%d %d", &a, &b);
w[a].insert(w[a].end(), make_pair(b, i));
w[b].insert(w[b].end(), make_pair(a, i));
}
queue<int> que;
que.push(1);
result[1].first = 0;
result[1].second = 0;
while (!que.empty()) {
int n = que.front();
// std::cout << n << "\n";
que.pop(); // 先頭要素を削除
for (int i = 0; i < w[n].size(); i++) {
pair<int, int> now = w[n][i];
// cout << "now is w[" << n << "][" << i << "]=" << now.first << " " <<
// now.second << "\n";
if (result[now.first].first <= result[n].first) {
continue;
}
result[now.first].first = result[n].first + 1;
result[now.first].second = n;
que.push(now.first);
// cout << "hoge";
}
}
cout << "Yes\n";
for (int i = 2; i <= N; i++) {
cout << result[i].second << "\n";
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
// cin.tie(0);
// ios::sync_with_stdio(false);
int N, M;
scanf("%d %d", &N, &M);
vector<vector<pair<int, int>>> w(N + 1,
vector<pair<int, int>>()); //(部屋,道番号)
vector<pair<int, int>> result(N + 1, make_pair(N + 100, -1)); //(距離, 道)
int a, b;
for (int i = 1; i < M + 1; i++) {
scanf("%d %d", &a, &b);
w[a].insert(w[a].end(), make_pair(b, i));
w[b].insert(w[b].end(), make_pair(a, i));
}
queue<int> que;
que.push(1);
result[1].first = 0;
result[1].second = 0;
while (!que.empty()) {
int n = que.front();
// std::cout << n << "\n";
que.pop(); // 先頭要素を削除
for (int i = 0; i < w[n].size(); i++) {
pair<int, int> now = w[n][i];
// cout << "now is w[" << n << "][" << i << "]=" << now.first << " " <<
// now.second << "\n";
if (result[now.first].first <= result[n].first + 1) {
continue;
}
result[now.first].first = result[n].first + 1;
result[now.first].second = n;
que.push(now.first);
// cout << "hoge";
}
}
cout << "Yes\n";
for (int i = 2; i <= N; i++) {
cout << result[i].second << "\n";
}
return 0;
} | replace | 34 | 35 | 34 | 35 | TLE | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<vector<int>> path(M + 1);
for (int i = 1; i <= M; i++) {
int a, b;
cin >> a >> b;
path[a].push_back(b);
path[b].push_back(a);
}
vector<int> dist(N + 1, INT_MAX);
vector<int> prev(N + 1, INT_MAX);
dist[1] = 0;
queue<int> que;
que.push(1);
while (!que.empty()) {
int n = que.front();
que.pop();
for (size_t i = 0; i < path[n].size(); i++) {
if (dist[path[n][i]] != INT_MAX) {
continue;
}
dist[path[n][i]] = dist[n] + 1;
prev[path[n][i]] = n;
que.push(path[n][i]);
}
}
cout << "Yes" << endl;
for (int i = 2; i <= N; i++) {
cout << prev[i] << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<vector<int>> path(N + 1);
for (int i = 1; i <= M; i++) {
int a, b;
cin >> a >> b;
path[a].push_back(b);
path[b].push_back(a);
}
vector<int> dist(N + 1, INT_MAX);
vector<int> prev(N + 1, INT_MAX);
dist[1] = 0;
queue<int> que;
que.push(1);
while (!que.empty()) {
int n = que.front();
que.pop();
for (size_t i = 0; i < path[n].size(); i++) {
if (dist[path[n][i]] != INT_MAX) {
continue;
}
dist[path[n][i]] = dist[n] + 1;
prev[path[n][i]] = n;
que.push(path[n][i]);
}
}
cout << "Yes" << endl;
for (int i = 2; i <= N; i++) {
cout << prev[i] << endl;
}
return 0;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p02678 | C++ | Runtime Error | #pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for (int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
constexpr ll mod = 1e9 + 7;
constexpr int inf = INT32_MAX / 2;
constexpr ll INF = LLONG_MAX / 2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */
/* --------------------テンプレート------------------ */
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
/* ----------------------end----------------------- */
/* --------------------ライブラリ-------------------- */
ll fact(int i) { // 階乗
if (i == 0)
return 1;
return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) { // 最大公約数
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { // 最小公倍数
return a * b / gcd(a, b);
}
int keta(ll n) { // 桁数を求める
if (n == 0)
return 1;
int count = 0;
while (n != 0) {
n /= 10;
count++;
}
return count;
}
ll ketasum(ll n) { // 各桁の和
ll sum = 0;
while (n != 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
bool isprime(int n) { // 素数判定
if (n == 1)
return false;
if (n == 2)
return true;
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0)
return false;
}
return true;
}
/* ----------------------end----------------------- */
#pragma endregion
int n, m;
int ans[114514];
signed main() {
cin >> n >> m;
vvi v(m);
rep(i, m) {
int a, b;
cin >> a >> b;
a--;
b--;
v[a].pb(b);
v[b].pb(a);
}
queue<int> que;
que.push(0);
ans[0] = inf;
while (!que.empty()) {
int p = que.front();
// cout << "p:" << p+1 << endl;
que.pop();
for (auto i : v[p]) {
if (ans[i] != 0)
continue;
// cout << i+1 << "\n";
ans[i] = p + 1;
que.push(i);
}
}
rep1(i, n - 1) {
if (ans[i] == 0) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
rep1(i, n - 1) cout << ans[i] << endl;
return 0;
} | #pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for (int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
constexpr ll mod = 1e9 + 7;
constexpr int inf = INT32_MAX / 2;
constexpr ll INF = LLONG_MAX / 2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */
/* --------------------テンプレート------------------ */
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
/* ----------------------end----------------------- */
/* --------------------ライブラリ-------------------- */
ll fact(int i) { // 階乗
if (i == 0)
return 1;
return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) { // 最大公約数
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { // 最小公倍数
return a * b / gcd(a, b);
}
int keta(ll n) { // 桁数を求める
if (n == 0)
return 1;
int count = 0;
while (n != 0) {
n /= 10;
count++;
}
return count;
}
ll ketasum(ll n) { // 各桁の和
ll sum = 0;
while (n != 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
bool isprime(int n) { // 素数判定
if (n == 1)
return false;
if (n == 2)
return true;
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0)
return false;
}
return true;
}
/* ----------------------end----------------------- */
#pragma endregion
int n, m;
int ans[114514];
signed main() {
cin >> n >> m;
vvi v(214514);
rep(i, m) {
int a, b;
cin >> a >> b;
a--;
b--;
v[a].pb(b);
v[b].pb(a);
}
queue<int> que;
que.push(0);
ans[0] = inf;
while (!que.empty()) {
int p = que.front();
// cout << "p:" << p+1 << endl;
que.pop();
for (auto i : v[p]) {
if (ans[i] != 0)
continue;
// cout << i+1 << "\n";
ans[i] = p + 1;
que.push(i);
}
}
rep1(i, n - 1) {
if (ans[i] == 0) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
rep1(i, n - 1) cout << ans[i] << endl;
return 0;
} | replace | 95 | 96 | 95 | 96 | 0 | |
p02678 | C++ | Time Limit Exceeded | // include
// ------------------------------------------------
#include <algorithm>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
// func
// ------------------------------------------------
int CalcSumOfDigit(int n); // 各桁の和を計算する。
int getDigit(int n); // 数字の桁数を取得する。
string upper(string str); // 英字を大文字に変換する。
string lower(string str); // 英字を小文字に変換する。
// class
// ------------------------------------------------
class Combi {
public:
Combi();
long long Combination(long long n, long long k);
private:
vector<vector<long long>> memo;
long long n_num;
long long k_num;
void Resize(long long n, long long k);
};
// define
// ------------------------------------------------
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define repe(i, n) for (int(i) = 0; (i) <= (n); (i)++)
#define vsort(v) sort((v).begin(), (v).end())
#define rvsort(v) sort(rall((v)))
#define vi vector<int>
#define GCD(a, b) __gcd((a), (b))
#define LCM(a, b) (a) / GCD((a), (b)) * (b)
#define kiriage(a, b) ((a) + (b)-1) / (b)
const int INF = 1e9;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<long> vll;
// code
// ------------------------------------------------
int main() {
ll n, m;
cin >> n >> m;
vector<vector<ll>> Graph(n);
vll a(n, -1);
rep(i, m) {
ll a, b;
cin >> a >> b;
a--;
b--;
Graph[a].push_back(b);
Graph[b].push_back(a);
}
queue<ll> q;
ll now = 0;
ll before = 0;
vll seen(n);
q.push(now);
while (!q.empty()) {
now = q.front();
q.pop();
seen[now] = 1;
for (auto itr = Graph[now].begin(); itr != Graph[now].end(); ++itr) {
ll next = *itr;
if (a[next] == -1) {
a[next] = now;
}
if (seen[next] != 1) {
q.push(next);
}
}
before = now;
}
bool ans = true;
for (ll i = 1; i < n; ++i) {
if (a[i] == -1) {
ans = false;
break;
}
}
if (ans)
cout << "Yes" << endl;
else
cout << "No" << endl;
for (ll i = 1; i < n; ++i) {
cout << a[i] + 1 << endl;
}
return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(int n) {
int i = 1;
while (1) {
n = n / 10;
if (n == 1)
break;
i++;
}
return i;
}
int CalcSumOfDigit(int n) {
int s = 0;
while (n) {
s += n % 10;
n = n / 10;
}
return s;
}
string upper(string str) {
for (auto itr = str.begin(); itr != str.end(); itr++) {
if (97 <= *itr && *itr <= 122) {
*itr = *itr - 32;
}
}
return str;
}
string lower(string str) {
for (auto itr = str.begin(); itr != str.end(); itr++) {
if (65 <= *itr && *itr <= 90) {
*itr = *itr + 32;
}
}
return str;
}
Combi::Combi() {
n_num = -1;
k_num = -1;
};
ll Combi::Combination(ll n, ll k) {
Resize(n, k);
ll ret;
if (memo[n][k] != 0) {
ret = memo[n][k];
} else if (n == k || k == 0) {
memo[n][k] = 1;
ret = 1;
} else {
ret = Combination(n - 1, k - 1) + Combination(n - 1, k);
memo[n][k] = ret;
}
return ret;
}
void Combi::Resize(ll n, ll k) {
if (n_num <= n || k_num <= k) {
n_num = (n + 1) * 2;
k_num = (k + 1) * 2;
memo.resize(n_num);
for (auto itr = memo.begin(); itr != memo.end(); ++itr) {
itr->resize(k_num);
}
}
} | // include
// ------------------------------------------------
#include <algorithm>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
// func
// ------------------------------------------------
int CalcSumOfDigit(int n); // 各桁の和を計算する。
int getDigit(int n); // 数字の桁数を取得する。
string upper(string str); // 英字を大文字に変換する。
string lower(string str); // 英字を小文字に変換する。
// class
// ------------------------------------------------
class Combi {
public:
Combi();
long long Combination(long long n, long long k);
private:
vector<vector<long long>> memo;
long long n_num;
long long k_num;
void Resize(long long n, long long k);
};
// define
// ------------------------------------------------
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define repe(i, n) for (int(i) = 0; (i) <= (n); (i)++)
#define vsort(v) sort((v).begin(), (v).end())
#define rvsort(v) sort(rall((v)))
#define vi vector<int>
#define GCD(a, b) __gcd((a), (b))
#define LCM(a, b) (a) / GCD((a), (b)) * (b)
#define kiriage(a, b) ((a) + (b)-1) / (b)
const int INF = 1e9;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<long> vll;
// code
// ------------------------------------------------
int main() {
ll n, m;
cin >> n >> m;
vector<vector<ll>> Graph(n);
vll a(n, -1);
rep(i, m) {
ll a, b;
cin >> a >> b;
a--;
b--;
Graph[a].push_back(b);
Graph[b].push_back(a);
}
queue<ll> q;
ll now = 0;
ll before = 0;
vll seen(n);
q.push(now);
while (!q.empty()) {
now = q.front();
q.pop();
if (seen[now] == 1) {
continue;
}
seen[now] = 1;
for (auto itr = Graph[now].begin(); itr != Graph[now].end(); ++itr) {
ll next = *itr;
if (a[next] == -1) {
a[next] = now;
}
if (seen[next] != 1) {
q.push(next);
}
}
before = now;
}
bool ans = true;
for (ll i = 1; i < n; ++i) {
if (a[i] == -1) {
ans = false;
break;
}
}
if (ans)
cout << "Yes" << endl;
else
cout << "No" << endl;
for (ll i = 1; i < n; ++i) {
cout << a[i] + 1 << endl;
}
return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(int n) {
int i = 1;
while (1) {
n = n / 10;
if (n == 1)
break;
i++;
}
return i;
}
int CalcSumOfDigit(int n) {
int s = 0;
while (n) {
s += n % 10;
n = n / 10;
}
return s;
}
string upper(string str) {
for (auto itr = str.begin(); itr != str.end(); itr++) {
if (97 <= *itr && *itr <= 122) {
*itr = *itr - 32;
}
}
return str;
}
string lower(string str) {
for (auto itr = str.begin(); itr != str.end(); itr++) {
if (65 <= *itr && *itr <= 90) {
*itr = *itr + 32;
}
}
return str;
}
Combi::Combi() {
n_num = -1;
k_num = -1;
};
ll Combi::Combination(ll n, ll k) {
Resize(n, k);
ll ret;
if (memo[n][k] != 0) {
ret = memo[n][k];
} else if (n == k || k == 0) {
memo[n][k] = 1;
ret = 1;
} else {
ret = Combination(n - 1, k - 1) + Combination(n - 1, k);
memo[n][k] = ret;
}
return ret;
}
void Combi::Resize(ll n, ll k) {
if (n_num <= n || k_num <= k) {
n_num = (n + 1) * 2;
k_num = (k + 1) * 2;
memo.resize(n_num);
for (auto itr = memo.begin(); itr != memo.end(); ++itr) {
itr->resize(k_num);
}
}
} | insert | 77 | 77 | 77 | 81 | TLE | |
p02678 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define int long long
int mod = 1e9 + 7;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie();
cout.tie();
int n, m;
cin >> n >> m;
vector<vector<int>> g(n);
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].push_back(b);
g[b].push_back(a);
}
queue<int> q;
vector<int> used(n, -1);
q.push(0);
used[0] = 0;
while (!q.empty()) {
int a = q.front();
q.pop();
for (int i = 0; i < g[a].size(); i++) {
int to = g[a][i];
if (used[to] == -1) {
used[to] = a;
q.push(to);
}
}
}
for (int i = 1; i < n; i++) {
if (used[i] == -1) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
cout << used[i] + 1 << endl;
}
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define int long long
int mod = 1e9 + 7;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie();
cout.tie();
int n, m;
cin >> n >> m;
vector<vector<int>> g(n);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].push_back(b);
g[b].push_back(a);
}
queue<int> q;
vector<int> used(n, -1);
q.push(0);
used[0] = 0;
while (!q.empty()) {
int a = q.front();
q.pop();
for (int i = 0; i < g[a].size(); i++) {
int to = g[a][i];
if (used[to] == -1) {
used[to] = a;
q.push(to);
}
}
}
for (int i = 1; i < n; i++) {
if (used[i] == -1) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
cout << used[i] + 1 << endl;
}
}
| replace | 22 | 23 | 22 | 23 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> r(m);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
r[a - 1].push_back(b - 1);
r[b - 1].push_back(a - 1);
}
vector<int> d(n, -1);
queue<int> que;
d[0] = 0;
que.push(0);
while (!que.empty()) {
int v = que.front();
que.pop();
for (int nv : r[v]) {
if (d[nv] != -1)
continue;
d[nv] = v;
que.push(nv);
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
cout << d[i] + 1 << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> r(n);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
r[a - 1].push_back(b - 1);
r[b - 1].push_back(a - 1);
}
vector<int> d(n, -1);
queue<int> que;
d[0] = 0;
que.push(0);
while (!que.empty()) {
int v = que.front();
que.pop();
for (int nv : r[v]) {
if (d[nv] != -1)
continue;
d[nv] = v;
que.push(nv);
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
cout << d[i] + 1 << endl;
}
return 0;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p02678 | C++ | Runtime Error |
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stdio.h>
using namespace std;
#define N 10001
#define INFTY 100000000
int n, m;
vector<int> num[N];
bool color[N];
int d[N];
void bfs(int s) {
queue<int> q; // 標準ライブラリのqueue 入るものは最後尾 出すものは先頭
q.push(s);
for (int i = 0; i < n; i++) {
d[i] = INFTY;
}
d[s] = 0;
int u;
while (!q.empty()) { // qが空になるまで続ける
u = q.front(); // uはqの先頭
q.pop(); // qの先頭を取り出
if (color[u] == false)
continue;
color[u] = false;
for (int i = 0; i < num[u].size(); i++) {
d[num[u][i]] = min(d[u] + 1, d[num[u][i]]);
q.push(num[u][i]); // qの最後尾にvを追加
// color[num[u][i]]=false;
}
}
}
int main() {
cin >> n >> m;
for (int i = 0; i <= n; i++) {
color[i] = true;
d[i] = 100000000;
}
for (int i = 0; i < m; i++) {
int p, q;
cin >> p >> q;
num[p].push_back(q);
num[q].push_back(p);
}
d[1] = 0;
bfs(1);
// cout<<d[num[6][1]]<<d[6]<<endl;
// for (int i=1; i<=n; i++)cout<<d[i]<<endl;
cout << "Yes" << endl;
for (int i = 2; i <= n; i++) {
for (int j = 0; j < num[i].size(); j++) {
if (d[num[i][j]] == d[i] - 1) {
cout << num[i][j] << endl;
break;
}
}
}
} |
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stdio.h>
using namespace std;
#define N 200001
#define INFTY 100000000
int n, m;
vector<int> num[N];
bool color[N];
int d[N];
void bfs(int s) {
queue<int> q; // 標準ライブラリのqueue 入るものは最後尾 出すものは先頭
q.push(s);
for (int i = 0; i < n; i++) {
d[i] = INFTY;
}
d[s] = 0;
int u;
while (!q.empty()) { // qが空になるまで続ける
u = q.front(); // uはqの先頭
q.pop(); // qの先頭を取り出
if (color[u] == false)
continue;
color[u] = false;
for (int i = 0; i < num[u].size(); i++) {
d[num[u][i]] = min(d[u] + 1, d[num[u][i]]);
q.push(num[u][i]); // qの最後尾にvを追加
// color[num[u][i]]=false;
}
}
}
int main() {
cin >> n >> m;
for (int i = 0; i <= n; i++) {
color[i] = true;
d[i] = 100000000;
}
for (int i = 0; i < m; i++) {
int p, q;
cin >> p >> q;
num[p].push_back(q);
num[q].push_back(p);
}
d[1] = 0;
bfs(1);
// cout<<d[num[6][1]]<<d[6]<<endl;
// for (int i=1; i<=n; i++)cout<<d[i]<<endl;
cout << "Yes" << endl;
for (int i = 2; i <= n; i++) {
for (int j = 0; j < num[i].size(); j++) {
if (d[num[i][j]] == d[i] - 1) {
cout << num[i][j] << endl;
break;
}
}
}
} | replace | 6 | 7 | 6 | 7 | 0 | |
p02678 | C++ | Runtime Error | #include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using ull = unsigned long long;
int gcd(int x, int y);
const int INF = 1001001001;
// mint�p�̕ϐ� (10��9��)
const int mod = 1000000007;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> miti(m, vector<int>(0));
rep(i, m) {
int a, b;
cin >> a >> b;
miti[a - 1].emplace_back(b - 1);
miti[b - 1].emplace_back(a - 1);
}
vector<int> dist(n, INF);
queue<int> room;
vector<int> pre(n, -1);
room.push(0);
while (!room.empty()) {
int num = room.front();
room.pop();
for (int r : miti[num]) {
if (dist[r] != INF)
continue;
dist[r] = dist[num] + 1;
pre[r] = num;
room.push(r);
}
}
cout << "Yes" << endl;
rep(i, n) {
if (i == 0)
continue;
cout << pre[i] + 1 << endl;
}
return 0;
}
/*���C�u�����ő����*/
// ���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
int num[3];
num[0] = (x > y) ? x : y;
num[1] = (x <= y) ? x : y;
num[2] = num[0] % num[1];
while (num[2]) {
num[0] = num[1];
num[1] = num[2];
num[2] = num[0] % num[1];
}
return num[1];
}
| #include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using ull = unsigned long long;
int gcd(int x, int y);
const int INF = 1001001001;
// mint�p�̕ϐ� (10��9��)
const int mod = 1000000007;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> miti(n, vector<int>(0));
rep(i, m) {
int a, b;
cin >> a >> b;
miti[a - 1].emplace_back(b - 1);
miti[b - 1].emplace_back(a - 1);
}
vector<int> dist(n, INF);
queue<int> room;
vector<int> pre(n, -1);
room.push(0);
while (!room.empty()) {
int num = room.front();
room.pop();
for (int r : miti[num]) {
if (dist[r] != INF)
continue;
dist[r] = dist[num] + 1;
pre[r] = num;
room.push(r);
}
}
cout << "Yes" << endl;
rep(i, n) {
if (i == 0)
continue;
cout << pre[i] + 1 << endl;
}
return 0;
}
/*���C�u�����ő����*/
// ���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
int num[3];
num[0] = (x > y) ? x : y;
num[1] = (x <= y) ? x : y;
num[2] = num[0] % num[1];
while (num[2]) {
num[0] = num[1];
num[1] = num[2];
num[2] = num[0] % num[1];
}
return num[1];
}
| replace | 56 | 57 | 56 | 57 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
#define eps 1e-3
#define pi acos(-1.0)
#define inf 0x3f
#define INF 0x3f3f3f3f
#define pb push_back
#define debug1 cout << "&&";
#define debug2 cout << "**";
#define ms(a, x) memset(a, x, sizeof(a))
#define for0(i, n) for (int i = 0; i < n; ++i)
#define for1(i, n) for (int i = 1; i <= n; ++i)
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
typedef pair<long long, long long> pll;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
const int M = 1e6 + 10;
/*=================================================================================*/
int n, m, head[N], ver[N << 1], nex[N << 1], tot;
int vis[N], ans[N], sum;
void add(int a, int b) {
ver[++tot] = b;
nex[tot] = head[a];
head[a] = tot;
}
int main() {
cin >> n >> m;
for1(i, m) {
int x, y;
scanf("%d%d", &x, &y);
add(x, y);
add(y, x);
}
queue<int> q;
q.push(1);
while (!q.empty()) {
int x = q.front();
q.pop();
for (int i = head[x]; i; i = nex[i]) {
int y = ver[i];
if (!vis[y]) {
ans[y] = x;
sum++, vis[y] = 1;
q.push(y);
}
}
}
if (sum != n)
puts("No");
else {
puts("Yes");
for (int i = 2; i <= n; ++i)
printf("%d\n", ans[i]);
}
return 0;
} | #include <bits/stdc++.h>
#define eps 1e-3
#define pi acos(-1.0)
#define inf 0x3f
#define INF 0x3f3f3f3f
#define pb push_back
#define debug1 cout << "&&";
#define debug2 cout << "**";
#define ms(a, x) memset(a, x, sizeof(a))
#define for0(i, n) for (int i = 0; i < n; ++i)
#define for1(i, n) for (int i = 1; i <= n; ++i)
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
typedef pair<long long, long long> pll;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
const int M = 1e6 + 10;
/*=================================================================================*/
int n, m, head[N], ver[M], nex[M], tot;
int vis[N], ans[N], sum;
void add(int a, int b) {
ver[++tot] = b;
nex[tot] = head[a];
head[a] = tot;
}
int main() {
cin >> n >> m;
for1(i, m) {
int x, y;
scanf("%d%d", &x, &y);
add(x, y);
add(y, x);
}
queue<int> q;
q.push(1);
while (!q.empty()) {
int x = q.front();
q.pop();
for (int i = head[x]; i; i = nex[i]) {
int y = ver[i];
if (!vis[y]) {
ans[y] = x;
sum++, vis[y] = 1;
q.push(y);
}
}
}
if (sum != n)
puts("No");
else {
puts("Yes");
for (int i = 2; i <= n; ++i)
printf("%d\n", ans[i]);
}
return 0;
} | replace | 23 | 24 | 23 | 24 | 0 | |
p02678 | C++ | Time Limit Exceeded | #pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for (int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
template <class T> T gcd(T a, T b) { return ((b == 0) ? a : gcd(b, a % b)); }
vi g[100005];
int vis[100005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
// freopen("input.in", "r", stdin);
// freopen("output.out", "w", stdout);
int n, m;
cin >> n >> m;
rep(i, m) {
int a, b;
cin >> a >> b;
a--, b--;
g[a].pb(b);
g[b].pb(a);
}
queue<int> q;
q.push(0);
vis[0] = 1;
vi ans(n, 0);
while (!q.empty()) {
queue<int> q1;
while (!q.empty()) {
int cur = q.front();
q.pop();
for (int u : g[cur]) {
if (!vis[u]) {
q1.push(u);
vis[cur] = 1;
if (!ans[u])
ans[u] = cur + 1;
}
}
}
q = q1;
}
cout << "Yes" << endl;
repn(i, 1, n) cout << ans[i] << endl;
return 0;
}
/*
Things to look out for:
- Integer overflows
- Array bounds
- Special cases
Be careful!
*/
| #pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for (int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
template <class T> T gcd(T a, T b) { return ((b == 0) ? a : gcd(b, a % b)); }
vi g[100005];
int vis[100005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
// freopen("input.in", "r", stdin);
// freopen("output.out", "w", stdout);
int n, m;
cin >> n >> m;
rep(i, m) {
int a, b;
cin >> a >> b;
a--, b--;
g[a].pb(b);
g[b].pb(a);
}
queue<int> q;
q.push(0);
vis[0] = 1;
vi ans(n, 0);
while (!q.empty()) {
queue<int> q1;
while (!q.empty()) {
int cur = q.front();
q.pop();
for (int u : g[cur]) {
if (!vis[u]) {
q1.push(u);
vis[u] = 1;
if (!ans[u])
ans[u] = cur + 1;
}
}
}
q = q1;
}
cout << "Yes" << endl;
repn(i, 1, n) cout << ans[i] << endl;
return 0;
}
/*
Things to look out for:
- Integer overflows
- Array bounds
- Special cases
Be careful!
*/
| replace | 52 | 53 | 52 | 53 | TLE | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
vector<int> v[10001] = {};
vector<int> vs(10001, -1);
void bfs() {
int s = 1;
vs[s] = 0;
queue<int> q;
q.push(s);
while (!q.empty()) {
int t = q.front();
q.pop();
int num = (int)v[t].size();
for (int i = 0; i < num; i++) {
if (vs[v[t][i]] == -1) {
q.push(v[t][i]);
vs[v[t][i]] = t;
}
}
}
return;
}
int main() {
int N, M;
cin >> N >> M;
for (int i = 0; i < M; i++) {
int A, B;
cin >> A >> B;
v[A].push_back(B);
v[B].push_back(A);
}
bfs();
for (int i = 2; i <= N; i++) {
if (vs[i] == -1) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
for (int i = 2; i <= N; i++) {
cout << vs[i] << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
vector<int> v[100001] = {};
vector<int> vs(100001, -1);
void bfs() {
int s = 1;
vs[s] = 0;
queue<int> q;
q.push(s);
while (!q.empty()) {
int t = q.front();
q.pop();
int num = (int)v[t].size();
for (int i = 0; i < num; i++) {
if (vs[v[t][i]] == -1) {
q.push(v[t][i]);
vs[v[t][i]] = t;
}
}
}
return;
}
int main() {
int N, M;
cin >> N >> M;
for (int i = 0; i < M; i++) {
int A, B;
cin >> A >> B;
v[A].push_back(B);
v[B].push_back(A);
}
bfs();
for (int i = 2; i <= N; i++) {
if (vs[i] == -1) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
for (int i = 2; i <= N; i++) {
cout << vs[i] << endl;
}
return 0;
}
| replace | 3 | 5 | 3 | 5 | 0 | |
p02678 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long
// #define MULTI_TEST
int n, m;
vector<int> p;
vector<vector<int>> to;
vector<int> ans;
vector<int> a;
void path(int par, int r, int d) {
if (p[r])
return;
p[r] = 1;
if (a[r] >= d) {
a[r] = d;
ans[r] = par;
}
for (int i : to[r]) {
path(r, i, d + 1);
}
p[r] = 0;
}
void solve() {
p.clear();
ans.clear();
to.clear();
a.clear();
cin >> n >> m;
p.assign(n + 1, 0);
to.assign(n + 1, vector<int>());
ans.assign(n + 1, -1);
a.assign(n + 1, INT_MAX);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
to[a].push_back(b);
to[b].push_back(a);
}
path(0, 1, 0);
int poss = 1;
for (int i = 2; i <= n; i++) {
if (ans[i] == -1) {
poss = 0;
break;
}
}
if (poss) {
cout << "Yes\n";
for (int i = 2; i <= n; i++) {
cout << ans[i] << "\n";
}
} else {
cout << "No\n";
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
#ifdef MULTI_TEST
int t;
cin >> t;
while (t--) {
solve();
// cout << "\n";
}
#else
solve();
// cout << "\n";
#endif
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
// #define MULTI_TEST
int n, m;
vector<int> p;
vector<vector<int>> to;
vector<int> ans;
vector<int> a;
void path(int par, int r, int d) {
if (p[r])
return;
p[r] = 1;
if (a[r] >= d) {
a[r] = d;
ans[r] = par;
}
for (int i : to[r]) {
path(r, i, d + 1);
}
p[r] = 0;
}
void solve() {
p.clear();
ans.clear();
to.clear();
a.clear();
cin >> n >> m;
p.assign(n + 1, 0);
to.assign(n + 1, vector<int>());
ans.assign(n + 1, -1);
a.assign(n + 1, INT_MAX);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
to[a].push_back(b);
to[b].push_back(a);
}
/*path(0, 1, 0);
int poss = 1;
for(int i=2; i<=n; i++) {
if(ans[i] == -1) {
poss = 0;
break;
}
}*/
queue<pair<int, int>> q;
q.push(make_pair(0, 1));
while (q.size()) {
int i = q.front().second;
int par = q.front().first;
q.pop();
if (p[i])
continue;
p[i] = 1;
ans[i] = par;
for (int t : to[i]) {
q.push(make_pair(i, t));
}
}
int poss = 1;
for (int i = 2; i <= n; i++) {
if (ans[i] == -1) {
poss = 0;
break;
}
}
if (poss) {
cout << "Yes\n";
for (int i = 2; i <= n; i++) {
cout << ans[i] << "\n";
}
} else {
cout << "No\n";
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
#ifdef MULTI_TEST
int t;
cin >> t;
while (t--) {
solve();
// cout << "\n";
}
#else
solve();
// cout << "\n";
#endif
return 0;
}
| replace | 45 | 46 | 45 | 72 | TLE | |
p02678 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;
int main() {
int N, M;
cin >> N >> M;
vector<int> G[N];
int a[M], b[M];
for (int i = 0; i < M; i++) {
cin >> a[i] >> b[i];
a[i]--;
b[i]--;
G[a[i]].push_back(b[i]);
G[b[i]].push_back(a[i]);
}
priority_queue<P> q;
q.push(P(0, 0));
int dp[N];
fill(dp, dp + N, 1000000005);
dp[0] = 0;
while (!q.empty()) {
int now = q.top().second;
int d = q.top().first;
q.pop();
if (dp[now] != d)
continue;
for (auto next : G[now]) {
if (dp[next] > dp[now] + 1) {
dp[next] = dp[now] + 1;
q.push(P(dp[now] + 1, next));
}
}
}
bool fl = true;
for (int i = 0; i < N; i++) {
if (dp[i] == 1000000005)
fl = false;
}
if (!fl) {
cout << "No" << endl;
return 0;
}
cout << "Yes" << endl;
int ans[N];
for (int i = 0; i < M; i++) {
if (dp[b[i]] == dp[a[i]] - 1)
ans[a[i]] = b[i];
if (dp[a[i]] == dp[b[i]] - 1)
ans[b[i]] = a[i];
}
for (int i = 1; i < N; i++) {
cout << ans[i] + 1 << endl;
}
return 0;
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;
int main() {
int N, M;
cin >> N >> M;
vector<int> G[N];
int a[M], b[M];
for (int i = 0; i < M; i++) {
cin >> a[i] >> b[i];
a[i]--;
b[i]--;
G[a[i]].push_back(b[i]);
G[b[i]].push_back(a[i]);
}
priority_queue<P, vector<P>, greater<P>> q;
q.push(P(0, 0));
int dp[N];
fill(dp, dp + N, 1000000005);
dp[0] = 0;
while (!q.empty()) {
int now = q.top().second;
int d = q.top().first;
q.pop();
if (dp[now] != d)
continue;
for (auto next : G[now]) {
if (dp[next] > dp[now] + 1) {
dp[next] = dp[now] + 1;
q.push(P(dp[now] + 1, next));
}
}
}
bool fl = true;
for (int i = 0; i < N; i++) {
if (dp[i] == 1000000005)
fl = false;
}
if (!fl) {
cout << "No" << endl;
return 0;
}
cout << "Yes" << endl;
int ans[N];
for (int i = 0; i < M; i++) {
if (dp[b[i]] == dp[a[i]] - 1)
ans[a[i]] = b[i];
if (dp[a[i]] == dp[b[i]] - 1)
ans[b[i]] = a[i];
}
for (int i = 1; i < N; i++) {
cout << ans[i] + 1 << endl;
}
return 0;
}
| replace | 27 | 28 | 27 | 28 | TLE | |
p02678 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
int main() {
// cout << fixed << setprecision(10);
int N, M;
map<int, bool> visited;
cin >> N >> M;
vector<int> previousMark(N);
vector<vector<int>> rooms(N + 1);
for (int i = 1; i <= N; i++) {
rooms[i] = vector<int>();
}
int A, B;
for (int i = 0; i < M; i++) {
cin >> A >> B;
rooms[A].push_back(B);
rooms[B].push_back(A);
}
vector<int> queue;
queue.push_back(1);
while (queue.size() > 0) {
vector<int> nextQueue;
for (int i = 0; i < queue.size(); i++) {
int currentRoom = queue[i];
vector<int> nextRooms = rooms[currentRoom];
for (int j = 0; j < nextRooms.size(); j++) {
if (visited[nextRooms[j]] == false) {
visited[nextRooms[j]] = true;
nextQueue.push_back(nextRooms[j]);
previousMark[nextRooms[j] - 2] = currentRoom;
}
}
}
queue = nextQueue;
}
cout << "Yes" << endl;
for (int i = 0; i < N - 1; i++) {
cout << previousMark[i] << endl;
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
int main() {
// cout << fixed << setprecision(10);
int N, M;
map<int, bool> visited;
visited[1] = true;
cin >> N >> M;
vector<int> previousMark(N);
vector<vector<int>> rooms(N + 1);
for (int i = 1; i <= N; i++) {
rooms[i] = vector<int>();
}
int A, B;
for (int i = 0; i < M; i++) {
cin >> A >> B;
rooms[A].push_back(B);
rooms[B].push_back(A);
}
vector<int> queue;
queue.push_back(1);
while (queue.size() > 0) {
vector<int> nextQueue;
for (int i = 0; i < queue.size(); i++) {
int currentRoom = queue[i];
vector<int> nextRooms = rooms[currentRoom];
for (int j = 0; j < nextRooms.size(); j++) {
if (visited[nextRooms[j]] == false) {
visited[nextRooms[j]] = true;
nextQueue.push_back(nextRooms[j]);
previousMark[nextRooms[j] - 2] = currentRoom;
}
}
}
queue = nextQueue;
}
cout << "Yes" << endl;
for (int i = 0; i < N - 1; i++) {
cout << previousMark[i] << endl;
}
return 0;
} | insert | 29 | 29 | 29 | 30 | -6 | double free or corruption (out)
|
p02678 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#define ll long long int
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int mx4[] = {0, 1, 0, -1};
int my4[] = {1, 0, -1, 0};
int INF = 2e6;
ll MOD = 1e9 + 7;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> g(m);
rep(i, m) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].pb(b);
g[b].pb(a);
}
queue<int> que;
que.push(0);
vector<bool> vis(n, false);
vis[0] = true;
vector<int> dist(n);
vector<int> ans(n);
while (que.size()) {
int p = que.front();
que.pop();
for (auto i : g[p]) {
if (!vis[i]) {
vis[i] = true;
dist[i] = dist[p] + 1;
que.push(i);
ans[i] = p + 1;
}
}
}
for (int i = 1; i < n; i++) {
if (dist[i] == 0) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
cout << ans[i] << endl;
}
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#define ll long long int
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int mx4[] = {0, 1, 0, -1};
int my4[] = {1, 0, -1, 0};
int INF = 2e6;
ll MOD = 1e9 + 7;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> g(n);
rep(i, m) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].pb(b);
g[b].pb(a);
}
queue<int> que;
que.push(0);
vector<bool> vis(n, false);
vis[0] = true;
vector<int> dist(n);
vector<int> ans(n);
while (que.size()) {
int p = que.front();
que.pop();
for (auto i : g[p]) {
if (!vis[i]) {
vis[i] = true;
dist[i] = dist[p] + 1;
que.push(i);
ans[i] = p + 1;
}
}
}
for (int i = 1; i < n; i++) {
if (dist[i] == 0) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
cout << ans[i] << endl;
}
} | replace | 28 | 29 | 28 | 29 | 0 | |
p02678 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
int nextr[100010];
vector<int> rt[10010];
int record[100010];
int main() {
int N, M;
cin >> N >> M;
/*
for (int i =1;i<N+1;i++){
for(int j=1;j<N+1;j++){
route[i][j]=0;
}
}*/
for (int i = 1; i < N + 1; i++)
nextr[i] = record[i] = 0;
int A[M], B[M];
for (int i = 0; i < M; i++) {
cin >> A[i] >> B[i];
// route[A[i]][B[i]]= route[B[i]][A[i]]=1;
rt[A[i]].push_back(B[i]);
rt[B[i]].push_back(A[i]);
}
queue<int> q;
q.push(1);
record[1] = 1;
while (!q.empty()) {
int cur = q.front();
q.pop();
for (const auto &e : rt[cur]) {
if (record[e] == 0) {
nextr[e] = cur;
record[e] = 1; // このタイミングで訪問済みにする
q.push(e);
}
}
/* for(int i=1;i<N+1;i++){
if(route[cur][i]==1 && record[i]==0){
nextr[i]=cur;
record[i]=1;//このタイミングで訪問済みにする
q.push(i);
}
}
*/
}
cout << "Yes" << endl;
for (int i = 2; i < N + 1; i++) {
cout << nextr[i] << endl;
}
return 0;
}
| #include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
int nextr[100010];
vector<int> rt[100100];
int record[100010];
int main() {
int N, M;
cin >> N >> M;
/*
for (int i =1;i<N+1;i++){
for(int j=1;j<N+1;j++){
route[i][j]=0;
}
}*/
for (int i = 1; i < N + 1; i++)
nextr[i] = record[i] = 0;
int A[M], B[M];
for (int i = 0; i < M; i++) {
cin >> A[i] >> B[i];
// route[A[i]][B[i]]= route[B[i]][A[i]]=1;
rt[A[i]].push_back(B[i]);
rt[B[i]].push_back(A[i]);
}
queue<int> q;
q.push(1);
record[1] = 1;
while (!q.empty()) {
int cur = q.front();
q.pop();
for (const auto &e : rt[cur]) {
if (record[e] == 0) {
nextr[e] = cur;
record[e] = 1; // このタイミングで訪問済みにする
q.push(e);
}
}
/* for(int i=1;i<N+1;i++){
if(route[cur][i]==1 && record[i]==0){
nextr[i]=cur;
record[i]=1;//このタイミングで訪問済みにする
q.push(i);
}
}
*/
}
cout << "Yes" << endl;
for (int i = 2; i < N + 1; i++) {
cout << nextr[i] << endl;
}
return 0;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define INF 1e+9
#define MAX_V 20002
struct edge {
int to;
};
int V;
vector<edge> G[MAX_V];
int d[MAX_V];
int mark[MAX_V];
void dijkstra(int s) {
priority_queue<P, vector<P>, greater<P>> que;
fill(d, d + V, INF);
d[s] = 0;
que.push(P(0, s));
while (!que.empty()) {
P p = que.top();
que.pop();
int v = p.second;
if (d[v] < p.first)
continue;
rep(i, G[v].size()) {
edge e = G[v][i];
if (d[e.to] > d[v] + 1) {
d[e.to] = d[v] + 1;
mark[e.to] = v;
que.push(P(d[e.to], e.to));
}
}
}
}
int main() {
cin >> V;
int E;
cin >> E;
rep(i, E) {
int a, b;
cin >> a >> b;
a--;
b--;
edge ea = {a};
edge eb = {b};
G[a].push_back(eb);
G[b].push_back(ea);
}
dijkstra(0);
rep(i, V) {
if (d[i] == INF) {
cout << "No" << endl;
exit(0);
}
}
cout << "Yes" << endl;
for (int i = 1; i < V; i++) {
cout << mark[i] + 1 << endl;
}
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define INF 1e+9
#define MAX_V 200002
struct edge {
int to;
};
int V;
vector<edge> G[MAX_V];
int d[MAX_V];
int mark[MAX_V];
void dijkstra(int s) {
priority_queue<P, vector<P>, greater<P>> que;
fill(d, d + V, INF);
d[s] = 0;
que.push(P(0, s));
while (!que.empty()) {
P p = que.top();
que.pop();
int v = p.second;
if (d[v] < p.first)
continue;
rep(i, G[v].size()) {
edge e = G[v][i];
if (d[e.to] > d[v] + 1) {
d[e.to] = d[v] + 1;
mark[e.to] = v;
que.push(P(d[e.to], e.to));
}
}
}
}
int main() {
cin >> V;
int E;
cin >> E;
rep(i, E) {
int a, b;
cin >> a >> b;
a--;
b--;
edge ea = {a};
edge eb = {b};
G[a].push_back(eb);
G[b].push_back(ea);
}
dijkstra(0);
rep(i, V) {
if (d[i] == INF) {
cout << "No" << endl;
exit(0);
}
}
cout << "Yes" << endl;
for (int i = 1; i < V; i++) {
cout << mark[i] + 1 << endl;
}
} | replace | 6 | 7 | 6 | 7 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using namespace std;
int main() {
int n, m, a, b;
cin >> n >> m;
vector<vector<int>> v(m);
rep(i, m) {
cin >> a >> b;
a--, b--;
v[a].push_back(b);
v[b].push_back(a);
}
queue<int> que;
que.push(0);
vector<bool> fin(n);
vector<int> flag(n);
while (!que.empty()) {
int now = que.front();
que.pop();
rep(i, v[now].size()) {
int nxt = v[now][i];
if (!fin[nxt]) {
flag[nxt] = now;
fin[nxt] = true;
que.push(nxt);
}
}
}
cout << "Yes" << endl;
rep(i, n - 1) cout << flag[i + 1] + 1 << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using namespace std;
int main() {
int n, m, a, b;
cin >> n >> m;
vector<vector<int>> v(n);
rep(i, m) {
cin >> a >> b;
a--, b--;
v[a].push_back(b);
v[b].push_back(a);
}
queue<int> que;
que.push(0);
vector<bool> fin(n);
vector<int> flag(n);
while (!que.empty()) {
int now = que.front();
que.pop();
rep(i, v[now].size()) {
int nxt = v[now][i];
if (!fin[nxt]) {
flag[nxt] = now;
fin[nxt] = true;
que.push(nxt);
}
}
}
cout << "Yes" << endl;
rep(i, n - 1) cout << flag[i + 1] + 1 << endl;
} | replace | 9 | 10 | 9 | 10 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const string YES = "Yes";
const string NO = "No";
void solve(long long N, long long M, std::vector<long long> A,
std::vector<long long> B) {
vector<vector<long long>> lis(N + 1);
vector<long long> path(N + 1, LLONG_MAX);
for (long long i = 0; i < N; i++) {
lis[A[i]].push_back(B[i]);
lis[B[i]].push_back(A[i]);
}
queue<long long> q;
q.push(1);
path[0] = 0;
path[1] = 0;
while (!q.empty()) {
long long edge = q.front();
// cout << edge << ": ";
for (auto i : lis[edge]) {
// cout << i << " ";
if (path[i] == LLONG_MAX) {
path[i] = edge;
q.push(i);
}
}
// cout << endl;
q.pop();
}
if (find(path.begin(), path.end(), LLONG_MAX) == path.end()) {
cout << YES << endl;
for (long long i = 2; i <= N; i++) {
cout << path[i] << endl;
}
} else {
cout << NO << endl;
}
}
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
long long N;
scanf("%lld", &N);
long long M;
scanf("%lld", &M);
std::vector<long long> A(M);
std::vector<long long> B(M);
for (int i = 0; i < M; i++) {
scanf("%lld", &A[i]);
scanf("%lld", &B[i]);
}
solve(N, M, std::move(A), std::move(B));
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const string YES = "Yes";
const string NO = "No";
void solve(long long N, long long M, std::vector<long long> A,
std::vector<long long> B) {
vector<vector<long long>> lis(N + 1);
vector<long long> path(N + 1, LLONG_MAX);
for (long long i = 0; i < M; i++) {
lis[A[i]].push_back(B[i]);
lis[B[i]].push_back(A[i]);
}
queue<long long> q;
q.push(1);
path[0] = 0;
path[1] = 0;
while (!q.empty()) {
long long edge = q.front();
// cout << edge << ": ";
for (auto i : lis[edge]) {
// cout << i << " ";
if (path[i] == LLONG_MAX) {
path[i] = edge;
q.push(i);
}
}
// cout << endl;
q.pop();
}
if (find(path.begin(), path.end(), LLONG_MAX) == path.end()) {
cout << YES << endl;
for (long long i = 2; i <= N; i++) {
cout << path[i] << endl;
}
} else {
cout << NO << endl;
}
}
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
long long N;
scanf("%lld", &N);
long long M;
scanf("%lld", &M);
std::vector<long long> A(M);
std::vector<long long> B(M);
for (int i = 0; i < M; i++) {
scanf("%lld", &A[i]);
scanf("%lld", &B[i]);
}
solve(N, M, std::move(A), std::move(B));
return 0;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p02678 | C++ | Time Limit Exceeded | // #define _GLIBCXX_DEBUG
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using pss = pair<string, string>;
using pcc = pair<char, char>;
using pbb = pair<bool, bool>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using ti3 = tuple<int, int, int>;
using tl3 = tuple<ll, ll, ll>;
using td3 = tuple<double, double, double>;
using ts3 = tuple<string, string, string>;
using tc3 = tuple<char, char, char>;
using tb3 = tuple<bool, bool, bool>;
using ti4 = tuple<int, int, int, int>;
using tl4 = tuple<ll, ll, ll, ll>;
using td4 = tuple<double, double, double, double>;
using ts4 = tuple<string, string, string, string>;
using tc4 = tuple<char, char, char, char>;
using tb4 = tuple<bool, bool, bool, bool>;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<double>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvd = vector<vd>;
using vvs = vector<vs>;
using vvc = vector<vc>;
using vvb = vector<vb>;
using vvvi = vector<vvi>;
using vvvl = vector<vvl>;
using vvvd = vector<vvd>;
using vvvs = vector<vvs>;
using vvvc = vector<vvc>;
using vvvb = vector<vvb>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vpdd = vector<pdd>;
using vpss = vector<pss>;
using vpcc = vector<pcc>;
using vpbb = vector<pbb>;
using vpil = vector<pil>;
using vpli = vector<pli>;
using vti3 = vector<ti3>;
using vtl3 = vector<tl3>;
using vtd3 = vector<td3>;
using vts3 = vector<ts3>;
using vtc3 = vector<tc3>;
using vtb3 = vector<tb3>;
using vti4 = vector<ti4>;
using vtl4 = vector<tl4>;
using vtd4 = vector<td4>;
using vts4 = vector<ts4>;
using vtc4 = vector<tc4>;
using vtb4 = vector<tb4>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using msi = map<string, int>;
using mci = map<char, int>;
using mil = map<int, ll>;
using mli = map<ll, int>;
using si = set<int>;
using sl = set<ll>;
using sd = set<double>;
using ss = set<string>;
using sc = set<char>;
using sb = set<bool>;
using spii = set<pii>;
using spll = set<pll>;
using spdd = set<pdd>;
using spss = set<pss>;
using spcc = set<pcc>;
using spbb = set<pbb>;
using spil = set<pil>;
using spli = set<pli>;
using sti3 = set<ti3>;
using stl3 = set<tl3>;
using std3 = set<td3>;
using sts3 = set<ts3>;
using stc3 = set<tc3>;
using stb3 = set<tb3>;
#define rep0(TMS) for (int CNT = 0; CNT < (int)(TMS); CNT++)
#define rep(CNT, GOAL) for (int CNT = 0; CNT < (int)(GOAL); CNT++)
#define rep2(CNT, START, GOAL) \
for (int CNT = (int)(START); CNT < (int)(GOAL); CNT++)
#define rep3(CNT, START, GOAL) \
for (int CNT = (int)(START); CNT > (int)(GOAL); CNT--)
#define all(CONT) begin(CONT), end(CONT)
#define fr1(CONT) next(begin(CONT)), end(CONT)
#define itrep(ITR, CONT) for (auto ITR = begin(CONT); ITR != end(CONT); ITR++)
#define itrep1(ITR, CONT) \
for (auto ITR = next(begin(CONT)); ITR != end(CONT); ITR++)
#define maxel(CONT) *max_element(all(CONT))
#define minel(CONT) *min_element(all(CONT))
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> T sum(const vector<T> &VEC) {
return accumulate(all(VEC), 0.0);
}
template <typename T> vector<T> acm(const vector<T> &VEC) {
vector<T> RES(VEC.size() + 1);
rep(CNT, VEC.size()) RES[CNT + 1] = RES[CNT] + VEC[CNT];
return RES;
}
template <typename T> void fil(vector<T> &VEC, const int NUM, const T &VAL) {
VEC.assign(NUM, VAL);
}
template <typename T> void fil(vector<T> &VEC, const int NUM) {
VEC.assign(NUM, 0.0);
}
template <typename T>
void fil(vector<vector<T>> &VV, const int RNUM, const int CNUM, const T &VAL) {
fil(VV, RNUM, vector<T>());
rep(CNT, RNUM) fil(VV[CNT], CNUM, VAL);
}
template <typename T>
void fil(vector<vector<T>> &VV, const int RNUM, const int CNUM) {
fil(VV, RNUM, vector<T>());
rep(CNT, RNUM) fil(VV[CNT], CNUM);
}
template <typename T> void fil(vector<vector<T>> &VV, const int RNUM) {
fil(VV, RNUM, vector<T>());
}
void prec(const int &DIG) {
cerr << fixed << setprecision(DIG);
cout << fixed << setprecision(DIG);
}
template <typename T> void COUT(const T &ELEM) { cout << ELEM; }
template <typename T> void pout(const T &ELEM) {
COUT(ELEM);
cout << " ";
}
template <typename T, typename... Ts>
void pout(const T &FIRST, const Ts &...REST) {
pout(FIRST);
pout(REST...);
}
template <typename T> void print(T ELEM) {
COUT(ELEM);
cout << "\n";
}
template <typename T, typename... Ts>
void print(const T &FIRST, const Ts &...REST) {
print(FIRST);
print(REST...);
}
void CERR() { cerr << "\n"; }
template <typename T> void CERR(const T &ELEM) { cerr << ELEM; }
template <typename T, typename... Ts>
void CERR(const T &FIRST, const Ts &...REST) {
CERR(FIRST);
cerr << ", ";
CERR(REST...);
}
template <typename T1, typename T2> void CERR(const pair<T1, T2> &PAIR) {
cerr << "(";
CERR(PAIR.first);
cerr << ", ";
CERR(PAIR.second);
cerr << ")";
}
template <typename T1, typename T2, typename T3>
void CERR(const tuple<T1, T2, T3> &TUP3) {
cerr << "(";
CERR(get<0>(TUP3));
cerr << ", ";
CERR(get<1>(TUP3));
cerr << ", ";
CERR(get<2>(TUP3));
cerr << ")";
}
template <typename T1, typename T2, typename T3, typename T4>
void CERR(const tuple<T1, T2, T3, T4> &TUP4) {
cerr << "(";
CERR(get<0>(TUP4));
cerr << ", ";
CERR(get<1>(TUP4));
cerr << ", ";
CERR(get<2>(TUP4));
cerr << ", ";
CERR(get<3>(TUP4));
cerr << ")";
}
template <typename T> void CERR(const vector<T> &VEC) {
cerr << "{ ";
itrep(ITR, VEC) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
template <typename T> void CERR1(const vector<T> &VEC) {
cerr << "{ ";
itrep1(ITR, VEC) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
template <typename T> void CERR(const set<T> &SET) {
cerr << "{ ";
itrep(ITR, SET) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
template <typename T1, typename T2> void CERR(const map<T1, T2> &MAP) {
cerr << "{ ";
itrep(ITR, MAP) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
#define db(OBJ) \
cerr << #OBJ << ": "; \
CERR(OBJ); \
cerr << ", "
#define dbl(OBJ) \
cerr << #OBJ << ": "; \
CERR(OBJ); \
cerr << "\n"
#define db1(OBJ) \
cerr << #OBJ << ": "; \
CERR1(OBJ); \
cerr << "\n"
#define dbs(...) \
cerr << "(" << #__VA_ARGS__ << "): ("; \
CERR(__VA_ARGS__); \
cerr << ")\n"
#define dbvv(VV) \
cerr << #VV << ": {\n"; \
rep(CNT, VV.size()) { \
cerr << #VV << "[" << CNT << "]: "; \
CERR(VV[CNT]); \
cerr << ",\n"; \
} \
cerr << "}\n"
#define db01(VV) \
cerr << #VV << ": {\n"; \
rep(CNT, VV.size()) { \
cerr << #VV << "[" << CNT << "]: "; \
CERR1(VV[CNT]); \
cerr << ",\n"; \
} \
cerr << "}\n"
#define db10(VV) \
cerr << #VV << ": {\n"; \
rep2(CNT, 1, VV.size()) { \
cerr << #VV << "[" << CNT << "]: "; \
CERR(VV[CNT]); \
cerr << ",\n"; \
} \
cerr << "}\n"
#define db11(VV) \
cerr << #VV << ": {\n"; \
rep2(CNT, 1, VV.size()) { \
cerr << #VV << "[" << CNT << "]: "; \
CERR1(VV[CNT]); \
cerr << ",\n"; \
} \
cerr << "}\n"
#define YN(FLG) cout << (FLG ? "YES" : "NO") << "\n"
#define Yn(FLG) cout << (FLG ? "Yes" : "No") << "\n"
#define yn(FLG) cout << (FLG ? "yes" : "no") << "\n"
#define pcase(NUM) \
cout << "Case #" << NUM << ":" \
<< " "
#define pcasel(NUM) \
cout << "Case #" << NUM << ":" \
<< "\n"
// const ll INF = 1'000'000'000'000'000'007;
const int INF = 1'000'000'007;
const ll MOD = 1'000'000'007; // 998'2447'353;
void bfs(int s, vvi &g, vi &dis, vi &prev) {
queue<int> q;
dis[s] = 0;
q.push(s);
while (!q.empty()) {
int u = q.front();
q.pop();
for (int v : g[u]) {
if (dis[v] != -1)
continue;
prev[v] = u;
q.push(v);
dis[v] = dis[u] + 1;
}
}
}
int main() {
// 1-ind
int N, M;
cin >> N >> M;
vvi g(N + 1, vi(N + 1));
rep0(M) {
int A, B;
cin >> A >> B; // 1-ind
g[A].push_back(B);
g[B].push_back(A);
}
vi dis(N + 1, -1);
vi prev(N + 1);
bfs(1, g, dis, prev);
// dbvv(dis); dbvv(prev);
cout << "Yes" << endl;
rep2(i, 2, N + 1) cout << prev[i] << endl;
} | // #define _GLIBCXX_DEBUG
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using pss = pair<string, string>;
using pcc = pair<char, char>;
using pbb = pair<bool, bool>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using ti3 = tuple<int, int, int>;
using tl3 = tuple<ll, ll, ll>;
using td3 = tuple<double, double, double>;
using ts3 = tuple<string, string, string>;
using tc3 = tuple<char, char, char>;
using tb3 = tuple<bool, bool, bool>;
using ti4 = tuple<int, int, int, int>;
using tl4 = tuple<ll, ll, ll, ll>;
using td4 = tuple<double, double, double, double>;
using ts4 = tuple<string, string, string, string>;
using tc4 = tuple<char, char, char, char>;
using tb4 = tuple<bool, bool, bool, bool>;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<double>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvd = vector<vd>;
using vvs = vector<vs>;
using vvc = vector<vc>;
using vvb = vector<vb>;
using vvvi = vector<vvi>;
using vvvl = vector<vvl>;
using vvvd = vector<vvd>;
using vvvs = vector<vvs>;
using vvvc = vector<vvc>;
using vvvb = vector<vvb>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vpdd = vector<pdd>;
using vpss = vector<pss>;
using vpcc = vector<pcc>;
using vpbb = vector<pbb>;
using vpil = vector<pil>;
using vpli = vector<pli>;
using vti3 = vector<ti3>;
using vtl3 = vector<tl3>;
using vtd3 = vector<td3>;
using vts3 = vector<ts3>;
using vtc3 = vector<tc3>;
using vtb3 = vector<tb3>;
using vti4 = vector<ti4>;
using vtl4 = vector<tl4>;
using vtd4 = vector<td4>;
using vts4 = vector<ts4>;
using vtc4 = vector<tc4>;
using vtb4 = vector<tb4>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using msi = map<string, int>;
using mci = map<char, int>;
using mil = map<int, ll>;
using mli = map<ll, int>;
using si = set<int>;
using sl = set<ll>;
using sd = set<double>;
using ss = set<string>;
using sc = set<char>;
using sb = set<bool>;
using spii = set<pii>;
using spll = set<pll>;
using spdd = set<pdd>;
using spss = set<pss>;
using spcc = set<pcc>;
using spbb = set<pbb>;
using spil = set<pil>;
using spli = set<pli>;
using sti3 = set<ti3>;
using stl3 = set<tl3>;
using std3 = set<td3>;
using sts3 = set<ts3>;
using stc3 = set<tc3>;
using stb3 = set<tb3>;
#define rep0(TMS) for (int CNT = 0; CNT < (int)(TMS); CNT++)
#define rep(CNT, GOAL) for (int CNT = 0; CNT < (int)(GOAL); CNT++)
#define rep2(CNT, START, GOAL) \
for (int CNT = (int)(START); CNT < (int)(GOAL); CNT++)
#define rep3(CNT, START, GOAL) \
for (int CNT = (int)(START); CNT > (int)(GOAL); CNT--)
#define all(CONT) begin(CONT), end(CONT)
#define fr1(CONT) next(begin(CONT)), end(CONT)
#define itrep(ITR, CONT) for (auto ITR = begin(CONT); ITR != end(CONT); ITR++)
#define itrep1(ITR, CONT) \
for (auto ITR = next(begin(CONT)); ITR != end(CONT); ITR++)
#define maxel(CONT) *max_element(all(CONT))
#define minel(CONT) *min_element(all(CONT))
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> T sum(const vector<T> &VEC) {
return accumulate(all(VEC), 0.0);
}
template <typename T> vector<T> acm(const vector<T> &VEC) {
vector<T> RES(VEC.size() + 1);
rep(CNT, VEC.size()) RES[CNT + 1] = RES[CNT] + VEC[CNT];
return RES;
}
template <typename T> void fil(vector<T> &VEC, const int NUM, const T &VAL) {
VEC.assign(NUM, VAL);
}
template <typename T> void fil(vector<T> &VEC, const int NUM) {
VEC.assign(NUM, 0.0);
}
template <typename T>
void fil(vector<vector<T>> &VV, const int RNUM, const int CNUM, const T &VAL) {
fil(VV, RNUM, vector<T>());
rep(CNT, RNUM) fil(VV[CNT], CNUM, VAL);
}
template <typename T>
void fil(vector<vector<T>> &VV, const int RNUM, const int CNUM) {
fil(VV, RNUM, vector<T>());
rep(CNT, RNUM) fil(VV[CNT], CNUM);
}
template <typename T> void fil(vector<vector<T>> &VV, const int RNUM) {
fil(VV, RNUM, vector<T>());
}
void prec(const int &DIG) {
cerr << fixed << setprecision(DIG);
cout << fixed << setprecision(DIG);
}
template <typename T> void COUT(const T &ELEM) { cout << ELEM; }
template <typename T> void pout(const T &ELEM) {
COUT(ELEM);
cout << " ";
}
template <typename T, typename... Ts>
void pout(const T &FIRST, const Ts &...REST) {
pout(FIRST);
pout(REST...);
}
template <typename T> void print(T ELEM) {
COUT(ELEM);
cout << "\n";
}
template <typename T, typename... Ts>
void print(const T &FIRST, const Ts &...REST) {
print(FIRST);
print(REST...);
}
void CERR() { cerr << "\n"; }
template <typename T> void CERR(const T &ELEM) { cerr << ELEM; }
template <typename T, typename... Ts>
void CERR(const T &FIRST, const Ts &...REST) {
CERR(FIRST);
cerr << ", ";
CERR(REST...);
}
template <typename T1, typename T2> void CERR(const pair<T1, T2> &PAIR) {
cerr << "(";
CERR(PAIR.first);
cerr << ", ";
CERR(PAIR.second);
cerr << ")";
}
template <typename T1, typename T2, typename T3>
void CERR(const tuple<T1, T2, T3> &TUP3) {
cerr << "(";
CERR(get<0>(TUP3));
cerr << ", ";
CERR(get<1>(TUP3));
cerr << ", ";
CERR(get<2>(TUP3));
cerr << ")";
}
template <typename T1, typename T2, typename T3, typename T4>
void CERR(const tuple<T1, T2, T3, T4> &TUP4) {
cerr << "(";
CERR(get<0>(TUP4));
cerr << ", ";
CERR(get<1>(TUP4));
cerr << ", ";
CERR(get<2>(TUP4));
cerr << ", ";
CERR(get<3>(TUP4));
cerr << ")";
}
template <typename T> void CERR(const vector<T> &VEC) {
cerr << "{ ";
itrep(ITR, VEC) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
template <typename T> void CERR1(const vector<T> &VEC) {
cerr << "{ ";
itrep1(ITR, VEC) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
template <typename T> void CERR(const set<T> &SET) {
cerr << "{ ";
itrep(ITR, SET) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
template <typename T1, typename T2> void CERR(const map<T1, T2> &MAP) {
cerr << "{ ";
itrep(ITR, MAP) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
#define db(OBJ) \
cerr << #OBJ << ": "; \
CERR(OBJ); \
cerr << ", "
#define dbl(OBJ) \
cerr << #OBJ << ": "; \
CERR(OBJ); \
cerr << "\n"
#define db1(OBJ) \
cerr << #OBJ << ": "; \
CERR1(OBJ); \
cerr << "\n"
#define dbs(...) \
cerr << "(" << #__VA_ARGS__ << "): ("; \
CERR(__VA_ARGS__); \
cerr << ")\n"
#define dbvv(VV) \
cerr << #VV << ": {\n"; \
rep(CNT, VV.size()) { \
cerr << #VV << "[" << CNT << "]: "; \
CERR(VV[CNT]); \
cerr << ",\n"; \
} \
cerr << "}\n"
#define db01(VV) \
cerr << #VV << ": {\n"; \
rep(CNT, VV.size()) { \
cerr << #VV << "[" << CNT << "]: "; \
CERR1(VV[CNT]); \
cerr << ",\n"; \
} \
cerr << "}\n"
#define db10(VV) \
cerr << #VV << ": {\n"; \
rep2(CNT, 1, VV.size()) { \
cerr << #VV << "[" << CNT << "]: "; \
CERR(VV[CNT]); \
cerr << ",\n"; \
} \
cerr << "}\n"
#define db11(VV) \
cerr << #VV << ": {\n"; \
rep2(CNT, 1, VV.size()) { \
cerr << #VV << "[" << CNT << "]: "; \
CERR1(VV[CNT]); \
cerr << ",\n"; \
} \
cerr << "}\n"
#define YN(FLG) cout << (FLG ? "YES" : "NO") << "\n"
#define Yn(FLG) cout << (FLG ? "Yes" : "No") << "\n"
#define yn(FLG) cout << (FLG ? "yes" : "no") << "\n"
#define pcase(NUM) \
cout << "Case #" << NUM << ":" \
<< " "
#define pcasel(NUM) \
cout << "Case #" << NUM << ":" \
<< "\n"
// const ll INF = 1'000'000'000'000'000'007;
const int INF = 1'000'000'007;
const ll MOD = 1'000'000'007; // 998'2447'353;
void bfs(int s, vvi &g, vi &dis, vi &prev) {
queue<int> q;
dis[s] = 0;
q.push(s);
while (!q.empty()) {
int u = q.front();
q.pop();
for (int v : g[u]) {
if (dis[v] != -1)
continue;
prev[v] = u;
q.push(v);
dis[v] = dis[u] + 1;
}
}
}
int main() {
// 1-ind
int N, M;
cin >> N >> M;
vvi g(N + 1, vi());
rep0(M) {
int A, B;
cin >> A >> B; // 1-ind
g[A].push_back(B);
g[B].push_back(A);
}
vi dis(N + 1, -1);
vi prev(N + 1);
bfs(1, g, dis, prev);
// dbvv(dis); dbvv(prev);
cout << "Yes" << endl;
rep2(i, 2, N + 1) cout << prev[i] << endl;
} | replace | 317 | 318 | 317 | 318 | TLE | |
p02678 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
#define INF 1000000007 // 1000000000000000003
#define MOD 1000000007
#define MAX 2000005
#define ll long long
// printf("%.10f", );
// cout << fixed << setprecision(10) << heikin << endl;
// vector<vector<int>> data(3, vector<int>(4, -1));
// left + 1 < top
using namespace std;
using P = pair<int, int>;
using Pc = pair<double, int>;
using T = tuple<int, int, int>;
using edge = struct {
int to;
long long dist;
};
const double PI = 3.141592653589793;
long long fact[MAX], inv[MAX];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
//////////////////////////////////
vector<vector<int>> bingo(3, vector<int>(3));
vector<vector<int>> tree(100005);
int color[100005];
map<P, int> colorMap;
int m = 0;
struct Connection {
vector<int> connect;
int parent = INF;
int dep = INF;
Connection() {}
};
bool compare_by_second(pair<int, int> a, pair<int, int> b) {
if (a.second != b.second) {
return a.second < b.second;
} else {
return a.first < b.first;
}
}
struct UnionFind {
vector<int> uf;
UnionFind(int size) : uf(size, -1){};
int root(int target) {
if (uf[target] < 0)
return target;
else
return uf[target] = root(uf[target]);
}
void merge(int a, int b) {
a = root(a);
b = root(b);
if (a == b)
return;
if (uf[b] < uf[a])
swap(a, b);
uf[a] += uf[b];
uf[b] = a;
}
};
ll CalcPow(ll num, ll power) {
if (power == 0)
return 1;
if (power % 2 == 0) {
ll half = CalcPow(num, power / 2);
return (half * half) % MOD;
} else
return (num * CalcPow(num, power - 1)) % MOD;
}
ll combination(ll all, ll select) {
if (all < select)
return 0;
if (all < 0 || select < 0)
return 0;
return fact[all] * (inv[select] * inv[all - select] % MOD) % MOD;
}
void initCombination(int max) {
fact[0] = fact[1] = 1;
for (int i = 2; i <= max; ++i) {
fact[i] = fact[i - 1] * i % MOD;
}
inv[max] = CalcPow(fact[max], MOD - 2);
for (int i = max - 1; 0 <= i; --i) {
inv[i] = (inv[i + 1] * (i + 1)) % MOD;
}
}
ll getGcd(ll a, ll b) {
if (a < b) {
ll temp = b;
b = a;
a = temp;
}
ll r;
while ((r = a % b) != 0) {
a = b;
b = r;
}
return b;
}
/*int getNum(ll target) {
int bottom = 0;
int top = 151;
while (1 < top - bottom) {
int middle = (top + bottom) / 2;
if (target < line[middle])top = middle;
else bottom = middle;
}
return bottom;
}*/
Connection connection[100005];
int co = 0;
void dfs(int depth, int next, int parent) {
++depth;
for (int c : connection[next].connect) {
if (c == parent)
continue;
if (depth < connection[c].dep) {
if (connection[c].dep == INF)
co++;
connection[c].dep = depth;
connection[c].parent = next;
} else if (connection[c].parent == next) {
continue;
}
dfs(depth, c, next);
}
}
int main() {
int N, M;
cin >> N >> M;
map<int, int> parent;
for (int i = 0; i < M; ++i) {
int a, b;
cin >> a >> b;
--a;
--b;
connection[a].connect.emplace_back(b);
connection[b].connect.emplace_back(a);
}
connection[0].dep = -1;
connection[0].parent = -1;
dfs(-1, 0, -1);
if (co == N - 1) {
cout << "Yes" << endl;
for (int i = 1; i < N; ++i) {
cout << connection[i].parent + 1 << endl;
}
} else {
cout << "No" << endl;
}
}
| #include <algorithm>
#include <array>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
#define INF 1000000007 // 1000000000000000003
#define MOD 1000000007
#define MAX 2000005
#define ll long long
// printf("%.10f", );
// cout << fixed << setprecision(10) << heikin << endl;
// vector<vector<int>> data(3, vector<int>(4, -1));
// left + 1 < top
using namespace std;
using P = pair<int, int>;
using Pc = pair<double, int>;
using T = tuple<int, int, int>;
using edge = struct {
int to;
long long dist;
};
const double PI = 3.141592653589793;
long long fact[MAX], inv[MAX];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
//////////////////////////////////
vector<vector<int>> bingo(3, vector<int>(3));
vector<vector<int>> tree(100005);
int color[100005];
map<P, int> colorMap;
int m = 0;
struct Connection {
vector<int> connect;
int parent = INF;
int dep = INF;
Connection() {}
};
bool compare_by_second(pair<int, int> a, pair<int, int> b) {
if (a.second != b.second) {
return a.second < b.second;
} else {
return a.first < b.first;
}
}
struct UnionFind {
vector<int> uf;
UnionFind(int size) : uf(size, -1){};
int root(int target) {
if (uf[target] < 0)
return target;
else
return uf[target] = root(uf[target]);
}
void merge(int a, int b) {
a = root(a);
b = root(b);
if (a == b)
return;
if (uf[b] < uf[a])
swap(a, b);
uf[a] += uf[b];
uf[b] = a;
}
};
ll CalcPow(ll num, ll power) {
if (power == 0)
return 1;
if (power % 2 == 0) {
ll half = CalcPow(num, power / 2);
return (half * half) % MOD;
} else
return (num * CalcPow(num, power - 1)) % MOD;
}
ll combination(ll all, ll select) {
if (all < select)
return 0;
if (all < 0 || select < 0)
return 0;
return fact[all] * (inv[select] * inv[all - select] % MOD) % MOD;
}
void initCombination(int max) {
fact[0] = fact[1] = 1;
for (int i = 2; i <= max; ++i) {
fact[i] = fact[i - 1] * i % MOD;
}
inv[max] = CalcPow(fact[max], MOD - 2);
for (int i = max - 1; 0 <= i; --i) {
inv[i] = (inv[i + 1] * (i + 1)) % MOD;
}
}
ll getGcd(ll a, ll b) {
if (a < b) {
ll temp = b;
b = a;
a = temp;
}
ll r;
while ((r = a % b) != 0) {
a = b;
b = r;
}
return b;
}
/*int getNum(ll target) {
int bottom = 0;
int top = 151;
while (1 < top - bottom) {
int middle = (top + bottom) / 2;
if (target < line[middle])top = middle;
else bottom = middle;
}
return bottom;
}*/
Connection connection[100005];
int co = 0;
void dfs(int depth, int next, int parent) {
++depth;
for (int c : connection[next].connect) {
if (c == parent)
continue;
if (depth < connection[c].dep) {
if (connection[c].dep == INF)
co++;
connection[c].dep = depth;
connection[c].parent = next;
} else if (connection[c].parent == next) {
continue;
}
dfs(depth, c, next);
}
}
int main() {
int N, M;
cin >> N >> M;
map<int, int> parent;
for (int i = 0; i < M; ++i) {
int a, b;
cin >> a >> b;
--a;
--b;
connection[a].connect.emplace_back(b);
connection[b].connect.emplace_back(a);
}
connection[0].dep = -1;
connection[0].parent = -1;
queue<int> que;
que.push(0);
int depth = -1;
while (!que.empty()) {
depth++;
int current = que.front();
que.pop();
for (int c : connection[current].connect) {
if (connection[c].dep < depth)
continue;
if (connection[c].dep == INF)
co++;
connection[c].dep = depth;
connection[c].parent = current;
que.push(c);
}
}
if (co == N - 1) {
cout << "Yes" << endl;
for (int i = 1; i < N; ++i) {
cout << connection[i].parent + 1 << endl;
}
} else {
cout << "No" << endl;
}
}
| replace | 179 | 180 | 179 | 197 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
const long long MOD = (long long)1e9 + 7;
int main() {
int n, m, ans = 0;
cin >> n >> m;
vector<vector<int>> e(m);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
e[a].emplace_back(b);
e[b].emplace_back(a);
}
vector<int> nx(n, -1);
queue<int> q;
q.push(0);
while (!q.empty()) {
int t = q.front();
q.pop();
for (auto &&i : e[t]) {
if (nx[i] != -1) {
continue;
}
nx[i] = t;
q.push(i);
}
}
bool f = true;
for (int i = 1; i < n; i++) {
if (nx[i] == -1) {
f = false;
break;
}
}
if (f) {
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
cout << nx[i] + 1 << endl;
}
} else {
cout << "No" << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
const long long MOD = (long long)1e9 + 7;
int main() {
int n, m, ans = 0;
cin >> n >> m;
vector<vector<int>> e(n);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
e[a].emplace_back(b);
e[b].emplace_back(a);
}
vector<int> nx(n, -1);
queue<int> q;
q.push(0);
while (!q.empty()) {
int t = q.front();
q.pop();
for (auto &&i : e[t]) {
if (nx[i] != -1) {
continue;
}
nx[i] = t;
q.push(i);
}
}
bool f = true;
for (int i = 1; i < n; i++) {
if (nx[i] == -1) {
f = false;
break;
}
}
if (f) {
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
cout << nx[i] + 1 << endl;
}
} else {
cout << "No" << endl;
}
return 0;
}
| replace | 12 | 13 | 12 | 13 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
#define quickie \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rep1(i, a, b) for (int i = a; i <= b; i++)
#define repp(i, a, b) for (int i = b - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define vi vector<int>
#define MI(x) power(x, mod - 2)
#define test \
int t; \
cin >> t;
#define mod 1000000007LL
#define pi 3.141592653589
// #define mod 998244353
using namespace std;
int power(int x, int y);
int gcd(int a, int b);
/*___________________________TEMPLATE END______________________________*/
vi v[10001];
bool vis[10001];
int dis[10001];
void bfs(int src) {
queue<int> q;
q.push(src);
vis[src] = true;
dis[src] = 0;
while (!q.empty()) {
int curr = q.front();
q.pop();
for (int i = 0; i < v[curr].size(); i++) {
if (!vis[v[curr][i]]) {
q.push(v[curr][i]);
dis[v[curr][i]] = dis[curr] + 1;
vis[v[curr][i]] = true;
}
}
}
}
signed main() {
quickie int n, m;
cin >> n >> m;
rep(i, 0, m) {
int a, b;
cin >> a >> b;
v[a].pb(b);
v[b].pb(a);
}
bfs(1);
rep(i, 2, n + 1) {
if (dis[i] == 0) {
cout << "No\n";
return 0;
}
}
cout << "Yes\n";
rep(i, 2, n + 1) {
for (auto it : v[i]) {
if (dis[it] == dis[i] - 1) {
cout << it << "\n";
break;
}
}
}
}
int power(int x, int y) {
int res = 1;
x %= mod;
while (y > 0) {
if (y & 1)
res = (res * x) % mod;
y = y >> 1;
x = (x * x) % mod;
}
return res % mod;
}
int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
} | #include <bits/stdc++.h>
#define int long long
#define quickie \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rep1(i, a, b) for (int i = a; i <= b; i++)
#define repp(i, a, b) for (int i = b - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define vi vector<int>
#define MI(x) power(x, mod - 2)
#define test \
int t; \
cin >> t;
#define mod 1000000007LL
#define pi 3.141592653589
// #define mod 998244353
using namespace std;
int power(int x, int y);
int gcd(int a, int b);
/*___________________________TEMPLATE END______________________________*/
vi v[1000001];
bool vis[1000001];
int dis[1000001];
void bfs(int src) {
queue<int> q;
q.push(src);
vis[src] = true;
dis[src] = 0;
while (!q.empty()) {
int curr = q.front();
q.pop();
for (int i = 0; i < v[curr].size(); i++) {
if (!vis[v[curr][i]]) {
q.push(v[curr][i]);
dis[v[curr][i]] = dis[curr] + 1;
vis[v[curr][i]] = true;
}
}
}
}
signed main() {
quickie int n, m;
cin >> n >> m;
rep(i, 0, m) {
int a, b;
cin >> a >> b;
v[a].pb(b);
v[b].pb(a);
}
bfs(1);
rep(i, 2, n + 1) {
if (dis[i] == 0) {
cout << "No\n";
return 0;
}
}
cout << "Yes\n";
rep(i, 2, n + 1) {
for (auto it : v[i]) {
if (dis[it] == dis[i] - 1) {
cout << it << "\n";
break;
}
}
}
}
int power(int x, int y) {
int res = 1;
x %= mod;
while (y > 0) {
if (y & 1)
res = (res * x) % mod;
y = y >> 1;
x = (x * x) % mod;
}
return res % mod;
}
int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
} | replace | 30 | 33 | 30 | 33 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5;
int t;
int n, m;
int par[N];
bool vis[N];
vector<vector<int>> v;
void fail() {
cout << "No";
exit(0);
}
void solve() {
cin >> n >> m;
v.resize(n + 5);
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
queue<int> q;
q.push(1);
vis[1] = true;
while (q.size()) {
int node = q.front();
q.pop();
for (int to : v[node]) {
if (vis[to])
continue;
else {
q.push(to);
vis[to] = true;
par[to] = node;
}
}
}
for (int i = 1; i <= n; i++) {
if (!vis[i])
fail();
}
cout << "Yes" << endl;
for (int i = 2; i <= n; i++) {
cout << par[i] << endl;
}
}
int main() {
t = 1;
while (t--) {
solve();
}
} | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int t;
int n, m;
int par[N];
bool vis[N];
vector<vector<int>> v;
void fail() {
cout << "No";
exit(0);
}
void solve() {
cin >> n >> m;
v.resize(n + 5);
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
queue<int> q;
q.push(1);
vis[1] = true;
while (q.size()) {
int node = q.front();
q.pop();
for (int to : v[node]) {
if (vis[to])
continue;
else {
q.push(to);
vis[to] = true;
par[to] = node;
}
}
}
for (int i = 1; i <= n; i++) {
if (!vis[i])
fail();
}
cout << "Yes" << endl;
for (int i = 2; i <= n; i++) {
cout << par[i] << endl;
}
}
int main() {
t = 1;
while (t--) {
solve();
}
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
typedef long long ll;
constexpr auto INFI = 2147483647;
const ll INFL = 9223372036854775807;
int main() {
int n, m;
cin >> n >> m;
vector<int> parent(n, -1);
vector<vector<int>> route(m);
int a, b;
rep(i, m) {
cin >> a >> b;
a--;
b--;
route[a].emplace_back(b);
route[b].emplace_back(a);
}
queue<int> que;
que.push(0);
parent[0] = INFI;
while (!que.empty()) {
int now = que.front();
que.pop();
if (route[now].empty())
continue;
int size_route = (int)route[now].size();
rep(i, size_route) {
int next = route[now][i];
if (parent[next] == -1) {
parent[next] = now;
que.push(next);
}
}
}
rep(i, n) {
if (parent[i] == -1) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
cout << parent[i] + 1 << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
typedef long long ll;
constexpr auto INFI = 2147483647;
const ll INFL = 9223372036854775807;
int main() {
int n, m;
cin >> n >> m;
vector<int> parent(n, -1);
vector<vector<int>> route(n);
int a, b;
rep(i, m) {
cin >> a >> b;
a--;
b--;
route[a].emplace_back(b);
route[b].emplace_back(a);
}
queue<int> que;
que.push(0);
parent[0] = INFI;
while (!que.empty()) {
int now = que.front();
que.pop();
if (route[now].empty())
continue;
int size_route = (int)route[now].size();
rep(i, size_route) {
int next = route[now][i];
if (parent[next] == -1) {
parent[next] = now;
que.push(next);
}
}
}
rep(i, n) {
if (parent[i] == -1) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
cout << parent[i] + 1 << endl;
}
return 0;
} | replace | 13 | 14 | 13 | 14 | 0 | |
p02678 | C++ | Runtime Error | #define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef map<int, string> mis;
typedef pair<int, ii> edge;
#define sc(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define mem(arr, val) memset(arr, val, sizeof arr)
#define sz(v) (int)v.size()
#define rsz(v) v.resize
#define clr(v) v.clear()
#define rev(v) reverse(all(v))
#define lop(i, end) for (int i = 0; i < end; i++)
#define rlop(i, start) for (int i = start - 1; i >= 0; i--)
#define loop(i, start, end) for (int i = start; i < end; i++)
#define rloop(i, start, end) for (int i = start - 1; i >= end; i--)
#define PB push_back
#define pb pop_back
#define mP make_pair
#define f first
#define s second
const ll OO = (ll)(4e18) + 9;
const int MOD = (int)(1e9) + 7;
const int oo = 2147483647;
const double EPS = 1e-8;
const double PI = acos(-1.0);
// enum dir { d, r, u, l , dr, ur, dl, ul };
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
string abc = "abcdefghijklmnopqrstuvwxyz";
string vowels = "aeiouy"; // and sometimes "aeiouy"
template <typename X, typename Y> bool ckmin(X &a, Y b) {
return a > b ? a = b, true : false;
}
template <typename X, typename Y> bool ckmax(X &a, Y b) {
return a < b ? a = b, true : false;
}
int dcmp(ld d1, ld d2) {
return fabs(d1 - d2) <= EPS ? 0 : d1 > d2 ? 1 : -1;
} // Compare Double Numbers
ll gcd(ll x, ll y) { return !y ? x : gcd(y, x % y); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
// convert index from 2D array to 1D array. (Zero-indexed)
int conv_2_1(int r, int c, int nCol) { return (nCol * r) + c + 1; }
// convert index from 1D array to 2D array. (Zero-indexed)
ii conv_1_2(int n, int nCol) {
int r = n / nCol, c = n % nCol;
return ii(r, c);
}
void inter(string s) {
cout << s << endl;
fflush(stdout);
}
ll power(ll base, ll exp) {
ll ans = 1;
base %= MOD;
while (exp > 0) {
if (exp & 1)
ans = (ans * base) % MOD;
exp >>= 1;
base = (base * base) % MOD;
}
return ans;
}
ll modInverse(ll a) { return power(a, MOD - 2); }
ll fact[2000010];
void init() {
fact[0] = 1;
for (int i = 1; i < 2000010; ++i)
fact[i] = (fact[i - 1] * 1LL * i) % MOD;
}
ll nCr(ll n, ll r) {
return (fact[n] * modInverse(fact[r] * 1LL * fact[n - r])) % MOD;
}
const int N = 1e5 + 10;
vector<int> adj[N];
int dis[N]; // dis[v] : holds the shortest distance between the source and node
// "v".
void bfs(int src) {
queue<int> q;
q.push(src);
memset(dis, -1, sizeof(dis));
dis[src] = 0;
while (!q.empty()) {
int u = q.front();
q.pop();
for (int v : adj[u]) {
if (dis[v] == -1) {
dis[v] = dis[u] + 1;
q.push(v);
}
}
}
}
int main() {
#ifndef ONLINE_JUDGE
#else
// freopen("pyramid.in", "r", stdin);
#endif
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, u, v;
cin >> n >> m;
lop(i, m) sc(u), sc(v), adj[u].PB(v), adj[v].PB(u);
bfs(1);
for (int i = 2; i <= n; i++)
if (dis[i] == -1)
return puts("No");
cout << "Yes\n";
loop(i, 2, n + 1) {
for (int u : adj[i]) {
if (dis[i] == dis[u] + 1) {
cout << u << endl;
break;
}
}
}
return 0;
}
| #define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef map<int, string> mis;
typedef pair<int, ii> edge;
#define sc(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define mem(arr, val) memset(arr, val, sizeof arr)
#define sz(v) (int)v.size()
#define rsz(v) v.resize
#define clr(v) v.clear()
#define rev(v) reverse(all(v))
#define lop(i, end) for (int i = 0; i < end; i++)
#define rlop(i, start) for (int i = start - 1; i >= 0; i--)
#define loop(i, start, end) for (int i = start; i < end; i++)
#define rloop(i, start, end) for (int i = start - 1; i >= end; i--)
#define PB push_back
#define pb pop_back
#define mP make_pair
#define f first
#define s second
const ll OO = (ll)(4e18) + 9;
const int MOD = (int)(1e9) + 7;
const int oo = 2147483647;
const double EPS = 1e-8;
const double PI = acos(-1.0);
// enum dir { d, r, u, l , dr, ur, dl, ul };
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
string abc = "abcdefghijklmnopqrstuvwxyz";
string vowels = "aeiouy"; // and sometimes "aeiouy"
template <typename X, typename Y> bool ckmin(X &a, Y b) {
return a > b ? a = b, true : false;
}
template <typename X, typename Y> bool ckmax(X &a, Y b) {
return a < b ? a = b, true : false;
}
int dcmp(ld d1, ld d2) {
return fabs(d1 - d2) <= EPS ? 0 : d1 > d2 ? 1 : -1;
} // Compare Double Numbers
ll gcd(ll x, ll y) { return !y ? x : gcd(y, x % y); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
// convert index from 2D array to 1D array. (Zero-indexed)
int conv_2_1(int r, int c, int nCol) { return (nCol * r) + c + 1; }
// convert index from 1D array to 2D array. (Zero-indexed)
ii conv_1_2(int n, int nCol) {
int r = n / nCol, c = n % nCol;
return ii(r, c);
}
void inter(string s) {
cout << s << endl;
fflush(stdout);
}
ll power(ll base, ll exp) {
ll ans = 1;
base %= MOD;
while (exp > 0) {
if (exp & 1)
ans = (ans * base) % MOD;
exp >>= 1;
base = (base * base) % MOD;
}
return ans;
}
ll modInverse(ll a) { return power(a, MOD - 2); }
ll fact[2000010];
void init() {
fact[0] = 1;
for (int i = 1; i < 2000010; ++i)
fact[i] = (fact[i - 1] * 1LL * i) % MOD;
}
ll nCr(ll n, ll r) {
return (fact[n] * modInverse(fact[r] * 1LL * fact[n - r])) % MOD;
}
const int N = 1e5 + 10;
vector<int> adj[N];
int dis[N]; // dis[v] : holds the shortest distance between the source and node
// "v".
void bfs(int src) {
queue<int> q;
q.push(src);
memset(dis, -1, sizeof(dis));
dis[src] = 0;
while (!q.empty()) {
int u = q.front();
q.pop();
for (int v : adj[u]) {
if (dis[v] == -1) {
dis[v] = dis[u] + 1;
q.push(v);
}
}
}
}
int main() {
#ifndef ONLINE_JUDGE
#else
// freopen("pyramid.in", "r", stdin);
#endif
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, u, v;
cin >> n >> m;
lop(i, m) cin >> u >> v, adj[u].PB(v), adj[v].PB(u);
bfs(1);
for (int i = 2; i <= n; i++)
if (dis[i] == -1)
return puts("No");
cout << "Yes\n";
loop(i, 2, n + 1) {
for (int u : adj[i]) {
if (dis[i] == dis[u] + 1) {
cout << u << endl;
break;
}
}
}
return 0;
}
| replace | 142 | 143 | 142 | 143 | -11 | |
p02678 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define ll long long
int main(void) {
int n, m;
cin >> n >> m;
vector<int> a(m), b(m);
for (int i = 0; i < m; ++i) {
int tmpa, tmpb;
cin >> tmpa >> tmpb;
a[i] = tmpa - 1;
b[i] = tmpb - 1;
}
vector<int> dist(n, 1000000000);
vector<vector<int>> coef(n);
for (int i = 0; i < m; ++i) {
coef[a[i]].push_back(b[i]);
coef[b[i]].push_back(a[i]);
}
// for(int i = 0;i < n;++i){
// cout << coef[i].size() << endl;
// }
queue<int> next;
next.push(0);
dist[0] = 0;
vector<int> ans(n);
for (int i = next.front(); next.size() > 0; i = next.front()) {
// cout << i << endl;
for (int j = 0; j < coef[i].size(); ++j) {
if (dist[coef[i][j]] > dist[i] + 1) {
dist[coef[i][j]] = dist[i] + 1;
// cout << "next push : " << coef[i][j] << endl;
next.push(coef[i][j]);
ans[j] = i;
}
}
next.pop();
// cout << "next is : " << next.front() << endl;
}
int flag = 1;
for (int i = 1; i < n; ++i) {
if (dist[i] == 1000000000) {
flag = 0;
}
}
if (flag) {
cout << "Yes" << endl;
for (int i = 1; i < n; ++i) {
cout << ans[i] + 1 << endl;
}
} else {
cout << "No" << endl;
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define ll long long
int main(void) {
int n, m;
cin >> n >> m;
vector<int> a(m), b(m);
for (int i = 0; i < m; ++i) {
int tmpa, tmpb;
cin >> tmpa >> tmpb;
a[i] = tmpa - 1;
b[i] = tmpb - 1;
}
vector<int> dist(n, 1000000000);
vector<vector<int>> coef(n);
for (int i = 0; i < m; ++i) {
coef[a[i]].push_back(b[i]);
coef[b[i]].push_back(a[i]);
}
// for(int i = 0;i < n;++i){
// cout << coef[i].size() << endl;
// }
queue<int> next;
next.push(0);
dist[0] = 0;
vector<int> ans(n);
for (int i = next.front(); next.size() > 0; i = next.front()) {
// cout << i << endl;
for (int j = 0; j < coef[i].size(); ++j) {
if (dist[coef[i][j]] > dist[i] + 1) {
dist[coef[i][j]] = dist[i] + 1;
// cout << "next push : " << coef[i][j] << endl;
next.push(coef[i][j]);
ans[coef[i][j]] = i;
}
}
next.pop();
// cout << "next is : " << next.front() << endl;
}
int flag = 1;
for (int i = 1; i < n; ++i) {
if (dist[i] == 1000000000) {
flag = 0;
}
}
if (flag) {
cout << "Yes" << endl;
for (int i = 1; i < n; ++i) {
cout << ans[i] + 1 << endl;
}
} else {
cout << "No" << endl;
}
return 0;
} | replace | 49 | 50 | 49 | 50 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (int i = int(x); i < (int)(n); i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
using ll = long long;
using P = pair<int, int>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;
ll const mod = 998244353;
const ll MAX = 300000;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvp = vector<vector<P>>;
int main() {
int n, m;
cin >> n >> m;
vvi ab(m);
rep(i, m) {
int a, b;
cin >> a >> b;
a--, b--;
ab[a].push_back(b);
ab[b].push_back(a);
}
vi ans(n);
vi used(n);
queue<int> q;
q.push(0);
while (q.size()) {
int now = q.front();
q.pop();
used[now] = 1;
for (int x : ab[now]) {
if (used[x] == 1)
continue;
used[x] = 1;
ans[x] = now + 1;
q.push(x);
}
// cout<<"aaa";
}
cout << "Yes" << endl;
arep(i, 1, n) { cout << ans[i] << endl; }
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (int i = int(x); i < (int)(n); i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
using ll = long long;
using P = pair<int, int>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;
ll const mod = 998244353;
const ll MAX = 300000;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvp = vector<vector<P>>;
int main() {
int n, m;
cin >> n >> m;
vvi ab(n);
rep(i, m) {
int a, b;
cin >> a >> b;
a--, b--;
ab[a].push_back(b);
ab[b].push_back(a);
}
vi ans(n);
vi used(n);
queue<int> q;
q.push(0);
while (q.size()) {
int now = q.front();
q.pop();
used[now] = 1;
for (int x : ab[now]) {
if (used[x] == 1)
continue;
used[x] = 1;
ans[x] = now + 1;
q.push(x);
}
// cout<<"aaa";
}
cout << "Yes" << endl;
arep(i, 1, n) { cout << ans[i] << endl; }
return 0;
} | replace | 22 | 23 | 22 | 23 | 0 | |
p02678 | Python | Runtime Error | from collections import deque
n, m = map(int, input().split())
INF = 100000000
to = [[] for _ in range(10005)]
for i in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
to[a].append(b)
to[b].append(a)
print("Yes")
q = deque([])
dist = [INF] * n
pre = [-1] * n
dist[0] = 0
q.append(0)
while len(q) > 0:
v = q.popleft()
for i in to[v]:
if dist[i] != INF:
continue
dist[i] = dist[v] + 1
pre[i] = v
q.append(i)
for i in range(1, n):
ans = pre[i]
ans += 1
print(ans)
| from collections import deque
n, m = map(int, input().split())
INF = 100000000
to = [[] for _ in range(100005)]
for i in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
to[a].append(b)
to[b].append(a)
print("Yes")
q = deque([])
dist = [INF] * n
pre = [-1] * n
dist[0] = 0
q.append(0)
while len(q) > 0:
v = q.popleft()
for i in to[v]:
if dist[i] != INF:
continue
dist[i] = dist[v] + 1
pre[i] = v
q.append(i)
for i in range(1, n):
ans = pre[i]
ans += 1
print(ans)
| replace | 5 | 6 | 5 | 6 | 0 | |
p02678 | Python | Time Limit Exceeded | from dataclasses import dataclass
from collections import deque
@dataclass
class Query:
now: int
prev: int
cost: int
N, M = map(int, input().split())
E = [[] for _ in range(N + 1)]
for e in range(M):
a, b = map(int, input().split())
E[a].append(b)
E[b].append(a)
res = [-1 for _ in range(N + 1)]
cost = [float("inf") for _ in range(N + 1)]
cost[1] = 0
queue = deque()
for next in E[1]:
queue.append(Query(next, 1, 1))
while len(queue):
q = queue.popleft()
if cost[q.now] > q.cost:
res[q.now] = q.prev
cost[q.now] = q.cost
for next in E[q.now]:
if cost[next] > q.cost + 1:
queue.append(Query(next, q.now, q.cost + 1))
for r in res[2:]:
if r == -1:
print("No")
exit()
print("Yes")
for r in res[2:]:
print(r)
| from dataclasses import dataclass
from collections import deque
@dataclass
class Query:
now: int
prev: int
cost: int
N, M = map(int, input().split())
E = [[] for _ in range(N + 1)]
for e in range(M):
a, b = map(int, input().split())
E[a].append(b)
E[b].append(a)
res = [-1 for _ in range(N + 1)]
cost = [float("inf") for _ in range(N + 1)]
cost[1] = 0
queue = deque()
for next in E[1]:
queue.append(Query(next, 1, 1))
while len(queue):
q = queue.popleft()
if cost[q.now] > q.cost:
res[q.now] = q.prev
cost[q.now] = q.cost
for next in E[q.now]:
if cost[next] > q.cost + 1:
queue.append(Query(next, q.now, q.cost + 1))
for r in res[2:]:
if r == -1:
print("No")
exit()
print("Yes")
for r in res[2:]:
print(r)
| replace | 34 | 37 | 34 | 37 | TLE | |
p02678 | Python | Runtime Error | import heapq
def dijkstra_heap(s):
d = [float("inf")] * n
prev = [float("inf")] * n
d[s] = 0
edgelist = [[d[s], s]]
heapq.heapify(edgelist)
while edgelist:
dis, v = heapq.heappop(edgelist)
if d[v] < dis:
continue
for e in edge[v]:
if d[e] > dis + 1:
d[e] = dis + 1
heapq.heappush(edgelist, [dis + 1, e])
prev[e] = v
return d, prev
n, w = map(int, input().split())
edge = [[] for i in range(w)]
for i in range(w):
x, y = map(int, input().split())
x -= 1
y -= 1
edge[x].append(y)
edge[y].append(x)
d, prev = dijkstra_heap(0)
if float("inf") in prev[1:]:
print("No")
else:
print("Yes")
for i in prev[1:]:
print(i + 1)
| import heapq
def dijkstra_heap(s):
d = [float("inf")] * n
prev = [float("inf")] * n
d[s] = 0
edgelist = [[d[s], s]]
heapq.heapify(edgelist)
while edgelist:
dis, v = heapq.heappop(edgelist)
if d[v] < dis:
continue
for e in edge[v]:
if d[e] > dis + 1:
d[e] = dis + 1
heapq.heappush(edgelist, [dis + 1, e])
prev[e] = v
return d, prev
n, w = map(int, input().split())
edge = [[] for i in range(n)]
for i in range(w):
x, y = map(int, input().split())
x -= 1
y -= 1
edge[x].append(y)
edge[y].append(x)
d, prev = dijkstra_heap(0)
if float("inf") in prev[1:]:
print("No")
else:
print("Yes")
for i in prev[1:]:
print(i + 1)
| replace | 25 | 26 | 25 | 26 | 0 | |
p02678 | Python | Runtime Error | from collections import deque
n, m = map(int, input().split())
to = [[] for _ in range(n + 1)]
for i in range(n):
a, b = map(int, input().split())
to[a].append(b)
to[b].append(a)
q = deque([1])
dist = [-1] * (n + 1)
# print(to)
while q:
v = q.popleft()
for u in to[v]:
if dist[u] != -1:
continue
q.append(u)
dist[u] = v
print("Yes")
# print(dist)
for i in range(2, n + 1):
print(dist[i])
| from collections import deque
n, m = map(int, input().split())
to = [[] for _ in range(n + 1)]
for i in range(m):
a, b = map(int, input().split())
to[a].append(b)
to[b].append(a)
q = deque([1])
dist = [-1] * (n + 1)
# print(to)
while q:
v = q.popleft()
for u in to[v]:
if dist[u] != -1:
continue
q.append(u)
dist[u] = v
print("Yes")
# print(dist)
for i in range(2, n + 1):
print(dist[i])
| replace | 5 | 6 | 5 | 6 | 0 | |
p02678 | Python | Time Limit Exceeded | def solve(string):
from collections import deque
n, m, *ab = map(int, string.split())
p = [[] for _ in range(n)]
for a, b in zip(*[iter(ab)] * 2):
p[a - 1].append(b - 1)
p[b - 1].append(a - 1)
s, ans, d = deque([0]), [0] * n, [0] + [n] * (n - 1)
while s:
c = s.popleft()
for t in p[c]:
if d[c] + 1 < d[t]:
d[t] = d[c] + 1
ans[t] = c + 1
if t not in s:
s.append(t)
return "Yes\n" + "\n".join(map(str, ans[1:]))
if __name__ == "__main__":
import sys
print(solve(sys.stdin.read().strip()))
| def solve(string):
from collections import deque
n, m, *ab = map(int, string.split())
p = [[] for _ in range(n)]
for a, b in zip(*[iter(ab)] * 2):
p[a - 1].append(b - 1)
p[b - 1].append(a - 1)
s, ans, d = deque([0]), [0] * n, [0] + [n] * (n - 1)
while s:
c = s.popleft()
for t in p[c]:
if d[c] + 1 < d[t]:
d[t] = d[c] + 1
ans[t] = c + 1
s.append(t)
return "Yes\n" + "\n".join(map(str, ans[1:]))
if __name__ == "__main__":
import sys
print(solve(sys.stdin.read().strip()))
| replace | 15 | 17 | 15 | 16 | TLE | |
p02678 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using lint = long long int;
struct Graph {
struct Edge {
int from;
int to;
lint cost;
};
struct Node {
Node() : par(-1), done(false), dist(INF) {}
int index;
int par;
bool done;
lint dist;
vector<Edge> edge;
};
int n;
vector<Node> nodes;
vector<Edge> edges;
const static lint INF = 1e18;
Graph(int n) : n(n) {
nodes.resize(n);
for (int i = 0; i < n; i++)
nodes[i].index = i;
}
void add_edge(int from, int to, lint cost) {
nodes[from].edge.push_back(Edge{from, to, cost});
edges.push_back(Edge{from, to, cost});
}
void dijkstra(int s) {
using Cand = tuple<lint, int, int>; // (dist, index, from)
priority_queue<Cand, vector<Cand>, greater<Cand>> que;
que.emplace(0, s, -1);
while (!que.empty()) {
lint dist;
int index, from;
tie(dist, index, from) = que.top();
que.pop();
if (dist >= nodes[index].dist)
continue;
nodes[index].dist = dist;
nodes[index].par = from;
for (auto &e : nodes[index].edge) {
que.emplace(dist + e.cost, e.to, e.from);
}
}
}
bool bellman_ford(int s) {
bool negative_cycle;
nodes[s].dist = 0;
for (int step = 1; step <= n; step++) {
bool update = false;
for (auto &e : edges) {
if (nodes[e.from].dist == INF)
continue;
lint next_cost = nodes[e.from].dist + e.cost;
if (nodes[e.to].dist > next_cost) {
nodes[e.to].dist = next_cost;
nodes[e.to].par = e.from;
update = true;
}
}
negative_cycle = (step == n && update);
}
return negative_cycle;
}
void bfs(int s) {
queue<int> que;
nodes[s].dist = 0;
que.push(s);
while (!que.empty()) {
int index = que.front();
que.pop();
for (auto &e : nodes[index].edge) {
if (nodes[e.to].dist != INF)
continue;
nodes[e.to].dist = nodes[index].dist + 1;
nodes[e.to].par = index;
que.push(e.to);
}
}
}
lint shortest_dist(int to) { return nodes[to].dist; }
vector<int> shortest_path(int to) {
vector<int> path;
int index = to;
while (index != -1) {
path.push_back(index);
index = nodes[index].par;
}
reverse(path.begin(), path.end());
return path;
}
};
int main() {
lint N, M;
cin >> N >> M;
Graph G(N);
for (int i = 0; i < M; i++) {
int a, b;
cin >> a >> b;
a--, b--;
G.add_edge(a, b, 1);
G.add_edge(b, a, 1);
}
G.bfs(0);
cout << "Yes" << endl;
for (int i = 1; i < N; i++) {
auto v = G.shortest_path(i);
cout << v[v.size() - 2] + 1 << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
using lint = long long int;
struct Graph {
struct Edge {
int from;
int to;
lint cost;
};
struct Node {
Node() : par(-1), done(false), dist(INF) {}
int index;
int par;
bool done;
lint dist;
vector<Edge> edge;
};
int n;
vector<Node> nodes;
vector<Edge> edges;
const static lint INF = 1e18;
Graph(int n) : n(n) {
nodes.resize(n);
for (int i = 0; i < n; i++)
nodes[i].index = i;
}
void add_edge(int from, int to, lint cost) {
nodes[from].edge.push_back(Edge{from, to, cost});
edges.push_back(Edge{from, to, cost});
}
void dijkstra(int s) {
using Cand = tuple<lint, int, int>; // (dist, index, from)
priority_queue<Cand, vector<Cand>, greater<Cand>> que;
que.emplace(0, s, -1);
while (!que.empty()) {
lint dist;
int index, from;
tie(dist, index, from) = que.top();
que.pop();
if (dist >= nodes[index].dist)
continue;
nodes[index].dist = dist;
nodes[index].par = from;
for (auto &e : nodes[index].edge) {
que.emplace(dist + e.cost, e.to, e.from);
}
}
}
bool bellman_ford(int s) {
bool negative_cycle;
nodes[s].dist = 0;
for (int step = 1; step <= n; step++) {
bool update = false;
for (auto &e : edges) {
if (nodes[e.from].dist == INF)
continue;
lint next_cost = nodes[e.from].dist + e.cost;
if (nodes[e.to].dist > next_cost) {
nodes[e.to].dist = next_cost;
nodes[e.to].par = e.from;
update = true;
}
}
negative_cycle = (step == n && update);
}
return negative_cycle;
}
void bfs(int s) {
queue<int> que;
nodes[s].dist = 0;
que.push(s);
while (!que.empty()) {
int index = que.front();
que.pop();
for (auto &e : nodes[index].edge) {
if (nodes[e.to].dist != INF)
continue;
nodes[e.to].dist = nodes[index].dist + 1;
nodes[e.to].par = index;
que.push(e.to);
}
}
}
lint shortest_dist(int to) { return nodes[to].dist; }
vector<int> shortest_path(int to) {
vector<int> path;
int index = to;
while (index != -1) {
path.push_back(index);
index = nodes[index].par;
}
reverse(path.begin(), path.end());
return path;
}
};
int main() {
lint N, M;
cin >> N >> M;
Graph G(N);
for (int i = 0; i < M; i++) {
int a, b;
cin >> a >> b;
a--, b--;
G.add_edge(a, b, 1);
G.add_edge(b, a, 1);
}
G.bfs(0);
cout << "Yes" << endl;
for (int i = 1; i < N; i++) {
cout << G.nodes[i].par + 1 << endl;
}
} | replace | 126 | 128 | 126 | 127 | TLE | |
p02678 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
vector<vector<int>> to;
int main() {
int n, m;
cin >> n >> m;
to = vector<vector<int>>(n);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
to[a].push_back(b);
to[b].push_back(a);
}
queue<int> que;
que.push(0);
vector<bool> done(n, false);
vector<int> ans(n, -1);
while (!que.empty()) {
int id = que.front();
que.pop();
done[id] = true;
for (int i = 0; i < to[id].size(); i++) {
int nx = to[id][i];
if (done[nx])
continue;
if (ans[nx] == -1)
ans[nx] = id;
que.push(nx);
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; i++)
cout << ans[i] + 1 << endl;
} | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
vector<vector<int>> to;
int main() {
int n, m;
cin >> n >> m;
to = vector<vector<int>>(n);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
to[a].push_back(b);
to[b].push_back(a);
}
queue<int> que;
que.push(0);
vector<bool> done(n, false);
vector<int> ans(n, -1);
while (!que.empty()) {
int id = que.front();
que.pop();
done[id] = true;
for (int i = 0; i < to[id].size(); i++) {
int nx = to[id][i];
if (done[nx])
continue;
if (ans[nx] == -1)
ans[nx] = id;
que.push(nx);
done[nx] = true;
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; i++)
cout << ans[i] + 1 << endl;
} | insert | 43 | 43 | 43 | 44 | TLE | |
p02678 | C++ | Runtime Error | /*
Jai Shree Krishna !!
Radhe Radhe !!
उद्यमेन हि सिद्ध्यन्ति कार्याणि न मनोरथैः। नहि सुप्तस्य सिंहस्य मुखे प्रविशन्ति
मृगाः।।
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
#define loop(i, n) for (int i = 0; i < n; i++)
#define read(a) \
int a; \
cin >> a;
#define readarr(a, n) \
int a[n]; \
for (int i = 0; i < n; i++) \
cin >> a[i];
#define readmat(a, n, m) \
int a[n][m]; \
for (int i = 0; i < n; i++) \
for (int j = 0; j < m; j++) \
cin >> a[i][j];
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int, int>
#define vvi vector<vector<int>>
#define sti set<int>
#define vpi vector<pair<int, int>>
#define print(a, n) \
for (int i = 0; i < n; i++) \
cout << a[i] << " "; \
cout << endl;
#define printmat(a, n, m) \
for (int i = 0; i < n; i++) { \
for (int j = 0; j < m; j++) \
cout << a[i][j] << " "; \
cout << endl; \
}
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define endl "\n"
#define mp make_pair
#define ins insert
#define rep(i, s, e) for (int i = s; i <= e; i++)
#define repd(i, s, e) for (int i = e; i >= s; i--)
#define vb vector<bool>
#define read2(n, m) \
int n, m; \
cin >> n >> m;
#define range(v) v.begin(), v.end()
#define sortd(v) sort(v.begin(), v.end(), greater<int>())
#define sorti(v) sort(v.begin(), v.end())
#define PI 3.14159265358979323846264338
const ll inf = 1e18;
const ll mod = 1e9 + 7;
vb visited(100001);
vi adj[100001];
void dfs(int v) {
visited[v] = true;
for (int u : adj[v]) {
if (!visited[u])
dfs(u);
}
}
signed main() {
fast;
read2(n, m);
rep(i, 0, m - 1) {
int x, y;
cin >> x >> y;
adj[x].pb(y);
adj[y].pb(x);
}
dfs(1);
rep(i, 1, n) {
if (!visited[i]) {
cout << "No" << endl;
return 0;
}
}
queue<int> q;
vector<bool> used(n);
vector<int> d(n), p(n);
int s = 1;
q.push(s);
used[s] = true;
p[s] = -1;
while (!q.empty()) {
int v = q.front();
q.pop();
for (int u : adj[v]) {
if (!used[u]) {
used[u] = true;
q.push(u);
// d[u] = v;
p[u] = v;
}
}
}
cout << "Yes" << endl;
rep(i, 2, n) cout << p[i] << endl;
return 0;
}
/* Pooja Yadav */ | /*
Jai Shree Krishna !!
Radhe Radhe !!
उद्यमेन हि सिद्ध्यन्ति कार्याणि न मनोरथैः। नहि सुप्तस्य सिंहस्य मुखे प्रविशन्ति
मृगाः।।
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
#define loop(i, n) for (int i = 0; i < n; i++)
#define read(a) \
int a; \
cin >> a;
#define readarr(a, n) \
int a[n]; \
for (int i = 0; i < n; i++) \
cin >> a[i];
#define readmat(a, n, m) \
int a[n][m]; \
for (int i = 0; i < n; i++) \
for (int j = 0; j < m; j++) \
cin >> a[i][j];
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int, int>
#define vvi vector<vector<int>>
#define sti set<int>
#define vpi vector<pair<int, int>>
#define print(a, n) \
for (int i = 0; i < n; i++) \
cout << a[i] << " "; \
cout << endl;
#define printmat(a, n, m) \
for (int i = 0; i < n; i++) { \
for (int j = 0; j < m; j++) \
cout << a[i][j] << " "; \
cout << endl; \
}
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define endl "\n"
#define mp make_pair
#define ins insert
#define rep(i, s, e) for (int i = s; i <= e; i++)
#define repd(i, s, e) for (int i = e; i >= s; i--)
#define vb vector<bool>
#define read2(n, m) \
int n, m; \
cin >> n >> m;
#define range(v) v.begin(), v.end()
#define sortd(v) sort(v.begin(), v.end(), greater<int>())
#define sorti(v) sort(v.begin(), v.end())
#define PI 3.14159265358979323846264338
const ll inf = 1e18;
const ll mod = 1e9 + 7;
vb visited(100001);
vi adj[100001];
void dfs(int v) {
visited[v] = true;
for (int u : adj[v]) {
if (!visited[u])
dfs(u);
}
}
signed main() {
fast;
read2(n, m);
rep(i, 0, m - 1) {
int x, y;
cin >> x >> y;
adj[x].pb(y);
adj[y].pb(x);
}
dfs(1);
rep(i, 1, n) {
if (!visited[i]) {
cout << "No" << endl;
return 0;
}
}
queue<int> q;
vector<bool> used(n + 1);
vector<int> p(n + 1);
int s = 1;
q.push(s);
used[s] = true;
p[s] = -1;
while (!q.empty()) {
int v = q.front();
q.pop();
for (int u : adj[v]) {
if (!used[u]) {
used[u] = true;
q.push(u);
// d[u] = v;
p[u] = v;
}
}
}
cout << "Yes" << endl;
rep(i, 2, n) cout << p[i] << endl;
return 0;
}
/* Pooja Yadav */ | replace | 94 | 96 | 94 | 96 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
typedef vector<vector<int>> Graph;
Graph G(100010);
vector<int> par(100010);
int room[10010] = {};
void init(int N) { // 最初は全てが根であるとして初期化
for (int i = 0; i < N; i++)
par[i] = i;
}
int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] == x)
return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) { // xとyの木を併合
int rx = root(x); // xの根をrx
int ry = root(y); // yの根をry
if (rx == ry)
return; // xとyの根が同じ(=同じ木にある)時はそのまま
if (ry < rx) {
par[rx] = ry;
} else {
par[ry] = rx;
}
}
bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
int rx = root(x);
int ry = root(y);
return rx == ry;
}
int main() {
int n, m, a, b;
cin >> n >> m;
init(n + 1);
rep(i, m) {
cin >> a >> b;
unite(a, b);
G[a].push_back(b);
G[b].push_back(a);
}
for (int i = 2; i <= n; i++) {
if (!same(1, i)) {
cout << "No";
return 0;
}
}
cout << "Yes" << endl;
queue<int> q;
q.push(1);
while (!q.empty()) {
int c = q.front();
q.pop();
rep(i, G[c].size()) {
if (room[G[c][i]] == 0) {
room[G[c][i]] = c;
q.push(G[c][i]);
}
}
}
for (int i = 2; i <= n; i++)
cout << room[i] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
typedef vector<vector<int>> Graph;
Graph G(100010);
vector<int> par(100010);
int room[100010] = {};
void init(int N) { // 最初は全てが根であるとして初期化
for (int i = 0; i < N; i++)
par[i] = i;
}
int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] == x)
return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) { // xとyの木を併合
int rx = root(x); // xの根をrx
int ry = root(y); // yの根をry
if (rx == ry)
return; // xとyの根が同じ(=同じ木にある)時はそのまま
if (ry < rx) {
par[rx] = ry;
} else {
par[ry] = rx;
}
}
bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
int rx = root(x);
int ry = root(y);
return rx == ry;
}
int main() {
int n, m, a, b;
cin >> n >> m;
init(n + 1);
rep(i, m) {
cin >> a >> b;
unite(a, b);
G[a].push_back(b);
G[b].push_back(a);
}
for (int i = 2; i <= n; i++) {
if (!same(1, i)) {
cout << "No";
return 0;
}
}
cout << "Yes" << endl;
queue<int> q;
q.push(1);
while (!q.empty()) {
int c = q.front();
q.pop();
rep(i, G[c].size()) {
if (room[G[c][i]] == 0) {
room[G[c][i]] = c;
q.push(G[c][i]);
}
}
}
for (int i = 2; i <= n; i++)
cout << room[i] << endl;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define INF 1e+9
#define MAX_V 10
struct edge {
int to;
int cost;
};
// <最短距離, 頂点の番号>
using P = pair<int, int>;
int V;
vector<edge> G[MAX_V];
int y[MAX_V];
int d[MAX_V];
void dijkstra(int s) {
priority_queue<P, vector<P>, greater<P>> que;
fill(d, d + V, INF);
d[s] = 0;
que.push(P(0, s));
while (!que.empty()) {
P p = que.top();
que.pop();
int v = p.second;
if (d[v] < p.first)
continue;
for (int i = 0; i < (int)G[v].size(); ++i) {
edge e = G[v][i];
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
y[e.to] = v;
que.push(P(d[e.to], e.to));
}
}
}
}
int main() {
cin >> V;
int E;
cin >> E;
for (int i = 0; i < E; ++i) {
int a, b;
cin >> a >> b;
edge e = {b - 1, 1};
G[a - 1].push_back(e);
e = {a - 1, 1};
G[b - 1].push_back(e);
}
dijkstra(0);
cout << "Yes" << endl;
for (int i = 1; i < V; ++i) {
if (d[i] != INF)
cout << y[i] + 1 << endl;
}
}
| #include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define INF 1e+9
#define MAX_V 100000
struct edge {
int to;
int cost;
};
// <最短距離, 頂点の番号>
using P = pair<int, int>;
int V;
vector<edge> G[MAX_V];
int y[MAX_V];
int d[MAX_V];
void dijkstra(int s) {
priority_queue<P, vector<P>, greater<P>> que;
fill(d, d + V, INF);
d[s] = 0;
que.push(P(0, s));
while (!que.empty()) {
P p = que.top();
que.pop();
int v = p.second;
if (d[v] < p.first)
continue;
for (int i = 0; i < (int)G[v].size(); ++i) {
edge e = G[v][i];
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
y[e.to] = v;
que.push(P(d[e.to], e.to));
}
}
}
}
int main() {
cin >> V;
int E;
cin >> E;
for (int i = 0; i < E; ++i) {
int a, b;
cin >> a >> b;
edge e = {b - 1, 1};
G[a - 1].push_back(e);
e = {a - 1, 1};
G[b - 1].push_back(e);
}
dijkstra(0);
cout << "Yes" << endl;
for (int i = 1; i < V; ++i) {
if (d[i] != INF)
cout << y[i] + 1 << endl;
}
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
#define FOR(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define TRAV(i, a) for (auto &i : (a))
#define SZ(x) ((int)(x).size())
#define PR std::pair
#define MP std::make_pair
#define X first
#define Y second
typedef long long ll;
typedef std::pair<int, int> PII;
typedef std::vector<int> VI;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
int n;
std::cin >> n;
int m;
std::cin >> m;
std::vector<VI> g(n);
FOR(i, n) {
int a, b;
std::cin >> a >> b;
a--;
b--;
g[a].push_back(b);
g[b].push_back(a);
}
std::queue<int> que;
que.push(0);
VI prev(n, -1);
prev[0] = 0;
while (SZ(que)) {
int cur = que.front();
que.pop();
TRAV(ch, g[cur]) {
if (prev[ch] == -1) {
prev[ch] = cur;
que.push(ch);
}
}
}
std::cout << "Yes\n";
REP(i, 1, n) std::cout << prev[i] + 1 << "\n";
return 0;
} | #include <bits/stdc++.h>
#define FOR(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define TRAV(i, a) for (auto &i : (a))
#define SZ(x) ((int)(x).size())
#define PR std::pair
#define MP std::make_pair
#define X first
#define Y second
typedef long long ll;
typedef std::pair<int, int> PII;
typedef std::vector<int> VI;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
int n;
std::cin >> n;
int m;
std::cin >> m;
std::vector<VI> g(n);
FOR(i, m) {
int a, b;
std::cin >> a >> b;
a--;
b--;
g[a].push_back(b);
g[b].push_back(a);
}
std::queue<int> que;
que.push(0);
VI prev(n, -1);
prev[0] = 0;
while (SZ(que)) {
int cur = que.front();
que.pop();
TRAV(ch, g[cur]) {
if (prev[ch] == -1) {
prev[ch] = cur;
que.push(ch);
}
}
}
std::cout << "Yes\n";
REP(i, 1, n) std::cout << prev[i] + 1 << "\n";
return 0;
} | replace | 21 | 22 | 21 | 22 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<vector<int>> G(M);
int a, b;
REP(i, M) {
cin >> a >> b;
--a;
--b;
G.at(a).push_back(b);
G.at(b).push_back(a);
}
vector<bool> visit(N, false);
queue<int> q;
unordered_map<int, int> route;
q.push(0);
while (!q.empty()) {
int v = q.front();
q.pop();
for (int nv : G.at(v)) {
if (!visit.at(nv)) {
q.push(nv);
visit.at(nv) = true;
route.insert(make_pair(nv, v));
}
}
}
if (!all_of(visit.begin(), visit.end(), [](bool f) { return f; })) {
cout << "No" << endl;
return 0;
}
cout << "Yes" << endl;
REPI(i, 1, N) {
// cout << i << ":" << route.at(i).size() << endl;
cout << route.at(i) + 1 << endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<vector<int>> G(N);
int a, b;
REP(i, M) {
cin >> a >> b;
--a;
--b;
G.at(a).push_back(b);
G.at(b).push_back(a);
}
vector<bool> visit(N, false);
queue<int> q;
unordered_map<int, int> route;
q.push(0);
while (!q.empty()) {
int v = q.front();
q.pop();
for (int nv : G.at(v)) {
if (!visit.at(nv)) {
q.push(nv);
visit.at(nv) = true;
route.insert(make_pair(nv, v));
}
}
}
if (!all_of(visit.begin(), visit.end(), [](bool f) { return f; })) {
cout << "No" << endl;
return 0;
}
cout << "Yes" << endl;
REPI(i, 1, N) {
// cout << i << ":" << route.at(i).size() << endl;
cout << route.at(i) + 1 << endl;
}
return 0;
}
| replace | 15 | 16 | 15 | 16 | 0 | |
p02678 | C++ | Time Limit Exceeded | #include <iostream>
#include <queue>
#include <vector>
using namespace std;
void search(vector<vector<int>> g, vector<int> &nxt, queue<int> &q) {
int tar = q.front();
q.pop();
for (int s : g[tar]) {
if (nxt[s] == -1) {
q.push(s);
nxt[s] = tar;
}
}
if (q.size() < 1)
return;
else
search(g, nxt, q);
}
int main(void) {
int n, m;
cin >> n >> m;
vector<vector<int>> g(n, vector<int>(0));
int n1, n2;
for (int i = 0; i < m; i++) {
cin >> n1 >> n2;
g[n1 - 1].push_back(n2 - 1);
g[n2 - 1].push_back(n1 - 1);
}
vector<int> nxt(n, -1);
nxt[0] = 0;
queue<int> q;
q.push(0);
search(g, nxt, q);
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
cout << nxt[i] + 1 << endl;
}
}
| #include <iostream>
#include <queue>
#include <vector>
using namespace std;
void search(vector<vector<int>> &g, vector<int> &nxt, queue<int> &q) {
int tar = q.front();
q.pop();
for (int s : g[tar]) {
if (nxt[s] == -1) {
q.push(s);
nxt[s] = tar;
}
}
if (q.size() < 1)
return;
else
search(g, nxt, q);
}
int main(void) {
int n, m;
cin >> n >> m;
vector<vector<int>> g(n, vector<int>(0));
int n1, n2;
for (int i = 0; i < m; i++) {
cin >> n1 >> n2;
g[n1 - 1].push_back(n2 - 1);
g[n2 - 1].push_back(n1 - 1);
}
vector<int> nxt(n, -1);
nxt[0] = 0;
queue<int> q;
q.push(0);
search(g, nxt, q);
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
cout << nxt[i] + 1 << endl;
}
}
| replace | 5 | 6 | 5 | 6 | TLE | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
using ll = long long;
int main() {
ll N, M;
cin >> N >> M;
vector<vector<ll>> G(M, vector<ll>(0));
rep(i, M) {
ll a, b;
cin >> a >> b;
--a;
--b;
G[a].push_back(b);
G[b].push_back(a);
}
queue<ll> q;
q.push(0);
vector<ll> ans(N, -1);
vector<bool> gone(N, false);
gone[0] = true;
while (!q.empty()) {
ll x = q.front();
q.pop();
if (!G[x].empty()) {
for (auto g : G[x]) {
if (gone[g])
continue;
gone[g] = true;
ans[g] = x + 1;
q.push(g);
}
}
}
bool can = true;
for (ll i = 1; i < N; i++) {
if (ans[i] == -1) {
can = false;
break;
}
}
if (can) {
cout << "Yes" << endl;
for (ll i = 1; i < N; i++) {
cout << ans[i] << endl;
}
} else
cout << "No" << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
using ll = long long;
int main() {
ll N, M;
cin >> N >> M;
vector<vector<ll>> G(N, vector<ll>(0));
rep(i, M) {
ll a, b;
cin >> a >> b;
--a;
--b;
G[a].push_back(b);
G[b].push_back(a);
}
queue<ll> q;
q.push(0);
vector<ll> ans(N, -1);
vector<bool> gone(N, false);
gone[0] = true;
while (!q.empty()) {
ll x = q.front();
q.pop();
if (!G[x].empty()) {
for (auto g : G[x]) {
if (gone[g])
continue;
gone[g] = true;
ans[g] = x + 1;
q.push(g);
}
}
}
bool can = true;
for (ll i = 1; i < N; i++) {
if (ans[i] == -1) {
can = false;
break;
}
}
if (can) {
cout << "Yes" << endl;
for (ll i = 1; i < N; i++) {
cout << ans[i] << endl;
}
} else
cout << "No" << endl;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02678 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for (long long i = 0; i < n; i++)
#define reps(i, s, e) for (long long i = s; i < e; i++)
#define repr(i, n) for (long long i = n - 1; i >= 0; i--)
#define reprs(i, s, e) for (long long i = e - 1; i >= s; i--)
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n, m;
cin >> n >> m;
ll a[m], b[m];
rep(i, m) {
cin >> a[i] >> b[i];
a[i]--;
b[i]--;
}
vector<ll> g[n];
rep(i, n) {
g[a[i]].push_back(b[i]);
g[b[i]].push_back(a[i]);
}
ll signal[n];
memset(signal, -1, sizeof(signal));
queue<ll> que;
que.push(0);
while (!que.empty()) {
ll p_now = que.front();
que.pop();
for (ll p_nxt : g[p_now]) {
if (signal[p_nxt] != -1)
continue;
signal[p_nxt] = p_now;
que.push(p_nxt);
}
}
cout << "Yes" << endl;
reps(i, 1, n) { cout << signal[i] + 1 << endl; }
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for (long long i = 0; i < n; i++)
#define reps(i, s, e) for (long long i = s; i < e; i++)
#define repr(i, n) for (long long i = n - 1; i >= 0; i--)
#define reprs(i, s, e) for (long long i = e - 1; i >= s; i--)
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n, m;
cin >> n >> m;
ll a[m], b[m];
rep(i, m) {
cin >> a[i] >> b[i];
a[i]--;
b[i]--;
}
vector<ll> g[n];
rep(i, m) {
g[a[i]].push_back(b[i]);
g[b[i]].push_back(a[i]);
}
ll signal[n];
memset(signal, -1, sizeof(signal));
queue<ll> que;
que.push(0);
while (!que.empty()) {
ll p_now = que.front();
que.pop();
for (ll p_nxt : g[p_now]) {
if (signal[p_nxt] != -1)
continue;
signal[p_nxt] = p_now;
que.push(p_nxt);
}
}
cout << "Yes" << endl;
reps(i, 1, n) { cout << signal[i] + 1 << endl; }
return 0;
} | replace | 38 | 39 | 38 | 39 | 0 | |
p02678 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
template <typename T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <typename T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
int in() {
int x;
scanf("%d", &x);
return x;
}
ll lin() {
ll x;
scanf("%lld", &x);
return x;
}
// #define INF 1LL<<60
#define INF 1e+9
#define MAX_V 10005
struct edge {
int to;
int cost;
};
// <最短距離, 頂点の番号>
using P = pair<int, int>;
int V;
vector<edge> G[MAX_V];
vector<int> par(MAX_V, -1);
int d[MAX_V];
void dijkstra(int s) {
priority_queue<P, vector<P>, greater<P>> que;
fill(d, d + V, INF);
d[s] = 0;
que.push(P(0, s));
while (!que.empty()) {
P p = que.top();
que.pop();
int v = p.second;
if (d[v] < p.first)
continue;
for (int i = 0; i < G[v].size(); ++i) {
edge e = G[v][i];
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
par[e.to] = v;
que.push(P(d[e.to], e.to));
}
}
}
}
int main() {
int N, M;
cin >> N >> M;
V = N;
for (int i = 0; i < M; ++i) {
int a, b, c;
cin >> a >> b;
c = 1;
a--;
b--;
edge e1 = {b, c}, e2 = {a, c};
G[a].push_back(e1);
G[b].push_back(e2);
}
par[0] = 0;
dijkstra(0);
bool flag = true;
REP(i, N) if (par[i] == -1) flag = false;
if (!flag) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
FOR(i, 1, N - 1) { cout << par[i] + 1 << endl; }
}
return 0;
} | #include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
template <typename T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <typename T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
int in() {
int x;
scanf("%d", &x);
return x;
}
ll lin() {
ll x;
scanf("%lld", &x);
return x;
}
// #define INF 1LL<<60
#define INF 1e+9
#define MAX_V 100005
struct edge {
int to;
int cost;
};
// <最短距離, 頂点の番号>
using P = pair<int, int>;
int V;
vector<edge> G[MAX_V];
vector<int> par(MAX_V, -1);
int d[MAX_V];
void dijkstra(int s) {
priority_queue<P, vector<P>, greater<P>> que;
fill(d, d + V, INF);
d[s] = 0;
que.push(P(0, s));
while (!que.empty()) {
P p = que.top();
que.pop();
int v = p.second;
if (d[v] < p.first)
continue;
for (int i = 0; i < G[v].size(); ++i) {
edge e = G[v][i];
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
par[e.to] = v;
que.push(P(d[e.to], e.to));
}
}
}
}
int main() {
int N, M;
cin >> N >> M;
V = N;
for (int i = 0; i < M; ++i) {
int a, b, c;
cin >> a >> b;
c = 1;
a--;
b--;
edge e1 = {b, c}, e2 = {a, c};
G[a].push_back(e1);
G[b].push_back(e2);
}
par[0] = 0;
dijkstra(0);
bool flag = true;
REP(i, N) if (par[i] == -1) flag = false;
if (!flag) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
FOR(i, 1, N - 1) { cout << par[i] + 1 << endl; }
}
return 0;
} | replace | 55 | 56 | 55 | 56 | 0 | |
p02678 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
#define pb push_back
long long int mod = (long long int)1000000007;
using namespace std;
int n;
const int full = 200006;
vector<int> adj[full];
bool vis[full];
int par[full];
int depth[full];
int ans[full];
void dfs(int i) {
queue<int> q;
q.push(1);
while (q.size() > 0) {
int x = q.front();
vis[x] = 1;
q.pop();
for (int j = 0; j < adj[x].size(); j++) {
if (vis[adj[x][j]] == 0) {
if (ans[adj[x][j]] == 0)
ans[adj[x][j]] = x;
q.push(adj[x][j]);
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int i, j, k;
int n, m;
cin >> n >> m;
for (i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
adj[a].pb(b);
adj[b].push_back(a);
}
dfs(1);
for (i = 2; i <= n; i++) {
if (ans[i] == 0) {
cout << "No";
return 0;
}
}
cout << "Yes\n";
for (i = 2; i <= n; i++) {
cout << ans[i] << "\n";
}
} | #include <bits/stdc++.h>
#define ll long long
#define pb push_back
long long int mod = (long long int)1000000007;
using namespace std;
int n;
const int full = 200006;
vector<int> adj[full];
bool vis[full];
int par[full];
int depth[full];
int ans[full];
void dfs(int i) {
queue<int> q;
q.push(1);
while (q.size() > 0) {
int x = q.front();
vis[x] = 1;
q.pop();
for (int j = 0; j < adj[x].size(); j++) {
if (vis[adj[x][j]] == 0 && ans[adj[x][j]] == 0) {
ans[adj[x][j]] = x;
q.push(adj[x][j]);
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int i, j, k;
int n, m;
cin >> n >> m;
for (i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
adj[a].pb(b);
adj[b].push_back(a);
}
dfs(1);
for (i = 2; i <= n; i++) {
if (ans[i] == 0) {
cout << "No";
return 0;
}
}
cout << "Yes\n";
for (i = 2; i <= n; i++) {
cout << ans[i] << "\n";
}
} | replace | 22 | 25 | 22 | 25 | TLE | |
p02678 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
#define ALL(c) (c).begin(), (c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
// #define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(), (c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ROF(i, a, b) for (int i = (b - 1); i >= (a); --i)
#define REP(i, n) FOR(i, 0, n)
#define PER(i, n) ROF(i, 0, n)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int LARGE_INT = 1e9 + 100;
const int INF = 2e9 + 100;
const LL INF_LL = (LL)INF * (LL)INF;
const int MOD = 1e9 + 7;
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
LL modpow(LL a, LL n) {
LL res = 1;
while (n > 0) {
if (n & 1)
res = res * a % MOD;
a = a * a % MOD;
n >>= 1;
}
return res;
}
void Main() {
int n, m;
cin >> n >> m;
VVI e(m);
REP(i, m) {
int a, b;
cin >> a >> b;
a--;
b--;
e[a].PB(b);
e[b].PB(a);
}
VI result(n, -1);
queue<int> q;
q.push(0);
result[0] = 0;
while (!q.empty()) {
int now = q.front();
q.pop();
for (auto next : e[now]) {
if (result[next] != -1) {
continue;
}
result[next] = now;
q.push(next);
}
}
REP(i, n) {
if (result[i] == -1) {
cout << "No" << endl;
return;
}
}
cout << "Yes" << endl;
FOR(i, 1, n) { cout << result[i] + 1 << endl; }
return;
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
return 0;
} | #include "bits/stdc++.h"
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
#define ALL(c) (c).begin(), (c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
// #define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(), (c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ROF(i, a, b) for (int i = (b - 1); i >= (a); --i)
#define REP(i, n) FOR(i, 0, n)
#define PER(i, n) ROF(i, 0, n)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int LARGE_INT = 1e9 + 100;
const int INF = 2e9 + 100;
const LL INF_LL = (LL)INF * (LL)INF;
const int MOD = 1e9 + 7;
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
LL modpow(LL a, LL n) {
LL res = 1;
while (n > 0) {
if (n & 1)
res = res * a % MOD;
a = a * a % MOD;
n >>= 1;
}
return res;
}
void Main() {
int n, m;
cin >> n >> m;
VVI e(n);
REP(i, m) {
int a, b;
cin >> a >> b;
a--;
b--;
e[a].PB(b);
e[b].PB(a);
}
VI result(n, -1);
queue<int> q;
q.push(0);
result[0] = 0;
while (!q.empty()) {
int now = q.front();
q.pop();
for (auto next : e[now]) {
if (result[next] != -1) {
continue;
}
result[next] = now;
q.push(next);
}
}
REP(i, n) {
if (result[i] == -1) {
cout << "No" << endl;
return;
}
}
cout << "Yes" << endl;
FOR(i, 1, n) { cout << result[i] + 1 << endl; }
return;
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
return 0;
} | replace | 61 | 62 | 61 | 62 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> room(m + 1);
vector<int> dist(n + 1, -1);
queue<int> que;
for (int i = 1; i <= m; i++) {
int a, b;
cin >> a >> b;
room[a].push_back(b);
room[b].push_back(a);
}
// 部屋1から始める
dist[1] = 0;
que.push(1);
while (!que.empty()) {
int v = que.front();
que.pop();
for (int nv : room[v]) {
if (dist[nv] != -1)
continue;
dist[nv] = dist[v] + 1;
que.push(nv);
}
}
// for(int i=1; i<dist.size(); i++) cout << "room :" << i << ", dist :" <<
// dist[i] << endl;
cout << "Yes" << endl;
for (int i = 2; i <= n; i++) {
int minDist = 10000000;
int minRoom;
for (int j = 0; j < (int)room[i].size(); j++) {
// cout << "j :" << j << ", room :" << room[i][j] << ", dist :" <<
// dist[room[i][j]] << endl;
if (dist[room[i][j]] < minDist) {
minDist = dist[room[i][j]];
minRoom = room[i][j];
}
}
cout << minRoom << endl;
}
}
| #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> room(m + 2);
vector<int> dist(n + 1, -1);
queue<int> que;
for (int i = 1; i <= m; i++) {
int a, b;
cin >> a >> b;
room[a].push_back(b);
room[b].push_back(a);
}
// 部屋1から始める
dist[1] = 0;
que.push(1);
while (!que.empty()) {
int v = que.front();
que.pop();
for (int nv : room[v]) {
if (dist[nv] != -1)
continue;
dist[nv] = dist[v] + 1;
que.push(nv);
}
}
// for(int i=1; i<dist.size(); i++) cout << "room :" << i << ", dist :" <<
// dist[i] << endl;
cout << "Yes" << endl;
for (int i = 2; i <= n; i++) {
int minDist = 10000000;
int minRoom;
for (int j = 0; j < (int)room[i].size(); j++) {
// cout << "j :" << j << ", room :" << room[i][j] << ", dist :" <<
// dist[room[i][j]] << endl;
if (dist[room[i][j]] < minDist) {
minDist = dist[room[i][j]];
minRoom = room[i][j];
}
}
cout << minRoom << endl;
}
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
/*
void showqueue(queue<int> q) {
cout << "queue: " ;
while (!q.empty()) {
cout << q.front() << " " ;
q.pop();
}
cout << endl;
return;
}
*/
int main() {
// input
int N, M;
cin >> N >> M;
vector<queue<int>> road(M);
vector<int> output(N, -1);
for (int i = 0; i < M; i++) {
int temp_A, temp_B;
cin >> temp_A >> temp_B;
temp_A--;
temp_B--;
road[temp_A].push(temp_B);
road[temp_B].push(temp_A);
}
queue<int> room_queue;
room_queue.push(0);
while (!room_queue.empty()) {
int temp_room = room_queue.front();
queue<int> temp_room_queue = road[temp_room];
while (!temp_room_queue.empty()) {
int temp_room_new = temp_room_queue.front();
if (output[temp_room_new] == -1) {
output[temp_room_new] = temp_room;
room_queue.push(temp_room_new);
// cout << temp_room_new << " " << num << endl;
}
temp_room_queue.pop();
}
room_queue.pop();
}
// output
// cout << endl;
cout << "Yes" << endl;
for (int i = 1; i < N; i++) {
cout << output[i] + 1 << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
/*
void showqueue(queue<int> q) {
cout << "queue: " ;
while (!q.empty()) {
cout << q.front() << " " ;
q.pop();
}
cout << endl;
return;
}
*/
int main() {
// input
int N, M;
cin >> N >> M;
vector<queue<int>> road(N);
vector<int> output(N, -1);
for (int i = 0; i < M; i++) {
int temp_A, temp_B;
cin >> temp_A >> temp_B;
temp_A--;
temp_B--;
road[temp_A].push(temp_B);
road[temp_B].push(temp_A);
}
queue<int> room_queue;
room_queue.push(0);
while (!room_queue.empty()) {
int temp_room = room_queue.front();
queue<int> temp_room_queue = road[temp_room];
while (!temp_room_queue.empty()) {
int temp_room_new = temp_room_queue.front();
if (output[temp_room_new] == -1) {
output[temp_room_new] = temp_room;
room_queue.push(temp_room_new);
// cout << temp_room_new << " " << num << endl;
}
temp_room_queue.pop();
}
room_queue.pop();
}
// output
// cout << endl;
cout << "Yes" << endl;
for (int i = 1; i < N; i++) {
cout << output[i] + 1 << endl;
}
return 0;
}
| replace | 19 | 20 | 19 | 20 | 0 | |
p02678 | C++ | Time Limit Exceeded | // by Balloons
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#define mpr make_pair
#define debug() puts("okkkkkkkk")
#define rep(i, a, b) for (int(i) = (a); (i) <= (b); (i)++)
using namespace std;
typedef long long LL;
const int inf = 1e9;
const int maxn = 2e5 + 5;
int n, m;
struct edges {
int to, nxt;
} ed[maxn << 1];
int head[maxn], ecnt = 0;
int dis[maxn], pre[maxn];
struct ee {
int to, dis;
bool operator<(ee b) const { return dis < b.dis; }
};
priority_queue<ee> pq;
void add(int x, int y) {
ed[++ecnt].to = y;
ed[ecnt].nxt = head[x];
head[x] = ecnt;
}
void dij() {
memset(dis, 127, sizeof dis);
pq.push((ee){1, 0});
dis[1] = 0;
while (!pq.empty()) {
ee u = pq.top();
pq.pop();
for (int i = head[u.to]; ~i; i = ed[i].nxt) {
int v = ed[i].to;
if (dis[v] > dis[u.to] + 1) {
dis[v] = dis[u.to] + 1;
pq.push((ee){v, dis[v]});
pre[v] = u.to;
}
}
}
// for(int i=1;i<=n;i++)printf("%d ",dis[i]);puts("");
}
signed main() {
memset(head, -1, sizeof head);
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
int x, y;
scanf("%d%d", &x, &y);
add(x, y);
add(y, x);
}
dij();
int imp = dis[0];
for (int i = 1; i <= n; i++)
if (dis[i] == imp)
return puts("No"), 0;
puts("Yes");
for (int i = 2; i <= n; i++)
printf("%d\n", pre[i]);
/*
有n个点,给m个两点之间得关系,问是否每个点都能到1,是输出“Yes”,并且输出每个点到1得最短路上得前一个点,否则输出“No”。
6 5
1 2
2 3
2 4
4 5
2 6
*/
return 0;
}
| // by Balloons
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#define mpr make_pair
#define debug() puts("okkkkkkkk")
#define rep(i, a, b) for (int(i) = (a); (i) <= (b); (i)++)
using namespace std;
typedef long long LL;
const int inf = 1e9;
const int maxn = 2e5 + 5;
int n, m;
struct edges {
int to, nxt;
} ed[maxn << 1];
int head[maxn], ecnt = 0;
int dis[maxn], pre[maxn];
struct ee {
int to, dis;
bool operator<(ee b) const { return dis > b.dis; }
};
priority_queue<ee> pq;
void add(int x, int y) {
ed[++ecnt].to = y;
ed[ecnt].nxt = head[x];
head[x] = ecnt;
}
void dij() {
memset(dis, 127, sizeof dis);
pq.push((ee){1, 0});
dis[1] = 0;
while (!pq.empty()) {
ee u = pq.top();
pq.pop();
for (int i = head[u.to]; ~i; i = ed[i].nxt) {
int v = ed[i].to;
if (dis[v] > dis[u.to] + 1) {
dis[v] = dis[u.to] + 1;
pq.push((ee){v, dis[v]});
pre[v] = u.to;
}
}
}
// for(int i=1;i<=n;i++)printf("%d ",dis[i]);puts("");
}
signed main() {
memset(head, -1, sizeof head);
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
int x, y;
scanf("%d%d", &x, &y);
add(x, y);
add(y, x);
}
dij();
int imp = dis[0];
for (int i = 1; i <= n; i++)
if (dis[i] == imp)
return puts("No"), 0;
puts("Yes");
for (int i = 2; i <= n; i++)
printf("%d\n", pre[i]);
/*
有n个点,给m个两点之间得关系,问是否每个点都能到1,是输出“Yes”,并且输出每个点到1得最短路上得前一个点,否则输出“No”。
6 5
1 2
2 3
2 4
4 5
2 6
*/
return 0;
}
| replace | 26 | 27 | 26 | 27 | TLE | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int INF = 1001001001;
const int MOD = 1000000007;
template <typename T> void print(const T &v);
const int V = 10000;
vector<P> G[V]; // pair<辺の距離, 行き先の頂点> (隣接リスト)
ll dist[V]; // dist[i]はsから頂点iへの最短距離が入る
bool used[V];
void dijkstra(ll s) { // s: 始点
fill_n(dist, V, INT_MAX);
fill_n(used, V, false);
priority_queue<P, vector<P>, greater<P>>
q; // 値が小さい順に取り出されるpriority_queue
q.push(P(0, s));
while (!q.empty()) {
ll d, t; // d: sからの距離 t: 行き先
tie(d, t) = q.top();
q.pop();
if (used[t])
continue; // 既に探索済か
used[t] = true;
dist[t] = d;
for (P e : G[t]) {
if (dist[e.second] <= d + e.first)
continue;
q.push(P(d + e.first, e.second));
}
}
}
int main() {
int N, M;
cin >> N >> M;
vector<int> a(M), b(M);
rep(i, M) {
cin >> a[i] >> b[i];
--a[i];
--b[i];
}
rep(i, M) {
G[a[i]].push_back(make_pair(1, b[i]));
G[b[i]].push_back(make_pair(1, a[i]));
}
dijkstra(0);
vector<int> ans(N);
for (int i = 1; i < N; i++) {
int next = dist[i] - 1; // 移動先の部屋の入り口までの距離
for (auto p : G[i]) {
if (dist[p.second] == next) {
ans[i] = p.second;
break;
}
}
}
cout << "Yes" << endl;
for (int i = 1; i < N; i++) {
cout << ans[i] + 1 << endl;
}
return 0;
}
// Use For Debug
template <typename T> void print(T const &v) {
for (int i = 0; i < v.size(); i++) {
if (i)
cout << " ";
cout << v[i];
}
cout << endl;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int INF = 1001001001;
const int MOD = 1000000007;
template <typename T> void print(const T &v);
const int V = 100100;
vector<P> G[V]; // pair<辺の距離, 行き先の頂点> (隣接リスト)
ll dist[V]; // dist[i]はsから頂点iへの最短距離が入る
bool used[V];
void dijkstra(ll s) { // s: 始点
fill_n(dist, V, INT_MAX);
fill_n(used, V, false);
priority_queue<P, vector<P>, greater<P>>
q; // 値が小さい順に取り出されるpriority_queue
q.push(P(0, s));
while (!q.empty()) {
ll d, t; // d: sからの距離 t: 行き先
tie(d, t) = q.top();
q.pop();
if (used[t])
continue; // 既に探索済か
used[t] = true;
dist[t] = d;
for (P e : G[t]) {
if (dist[e.second] <= d + e.first)
continue;
q.push(P(d + e.first, e.second));
}
}
}
int main() {
int N, M;
cin >> N >> M;
vector<int> a(M), b(M);
rep(i, M) {
cin >> a[i] >> b[i];
--a[i];
--b[i];
}
rep(i, M) {
G[a[i]].push_back(make_pair(1, b[i]));
G[b[i]].push_back(make_pair(1, a[i]));
}
dijkstra(0);
vector<int> ans(N);
for (int i = 1; i < N; i++) {
int next = dist[i] - 1; // 移動先の部屋の入り口までの距離
for (auto p : G[i]) {
if (dist[p.second] == next) {
ans[i] = p.second;
break;
}
}
}
cout << "Yes" << endl;
for (int i = 1; i < N; i++) {
cout << ans[i] + 1 << endl;
}
return 0;
}
// Use For Debug
template <typename T> void print(T const &v) {
for (int i = 0; i < v.size(); i++) {
if (i)
cout << " ";
cout << v[i];
}
cout << endl;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p02678 | C++ | Runtime Error | #include <cstdint>
#include <iostream>
#include <queue>
#include <vector>
using std::cin;
using std::cout;
using std::vector;
using ll = long long;
using ull = unsigned long long;
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
ull n, m, a, b;
std::cin >> n >> m;
vector<ull> from(n);
vector<vector<ull>> edge(m);
for (ull i = 0; i < m; i++) {
cin >> a >> b;
edge[a - 1].push_back(b - 1);
edge[b - 1].push_back(a - 1);
}
// bfs
std::queue<ull> q;
vector<bool> done(n, false);
q.push(0);
done[0] = true;
while (!q.empty()) {
ull node = q.front();
q.pop();
for (ull next_node : edge[node]) {
if (!done[next_node]) {
q.push(next_node);
from[next_node] = node;
done[next_node] = true;
}
}
}
cout << "Yes\n";
for (ull i = 1; i < n; i++) {
cout << from[i] + 1 << "\n";
}
return 0;
} | #include <cstdint>
#include <iostream>
#include <queue>
#include <vector>
using std::cin;
using std::cout;
using std::vector;
using ll = long long;
using ull = unsigned long long;
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
ull n, m, a, b;
std::cin >> n >> m;
vector<ull> from(n);
vector<vector<ull>> edge(n);
for (ull i = 0; i < m; i++) {
cin >> a >> b;
edge[a - 1].push_back(b - 1);
edge[b - 1].push_back(a - 1);
}
// bfs
std::queue<ull> q;
vector<bool> done(n, false);
q.push(0);
done[0] = true;
while (!q.empty()) {
ull node = q.front();
q.pop();
for (ull next_node : edge[node]) {
if (!done[next_node]) {
q.push(next_node);
from[next_node] = node;
done[next_node] = true;
}
}
}
cout << "Yes\n";
for (ull i = 1; i < n; i++) {
cout << from[i] + 1 << "\n";
}
return 0;
} | replace | 20 | 21 | 20 | 21 | 0 | |
p02678 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep2(i, n) for (int i = 2; i < (int)(n); i++)
#define repk(i, k, n) for (int i = k; i < (int)(n); i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
// #define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
// const int64 INF = 1LL << 58;
#define dame \
{ \
puts("-1"); \
return 0; \
}
#define YES \
{ \
cout << "YES" << endl; \
return 0; \
}
#define NO \
{ \
cout << "NO" << endl; \
return 0; \
}
#define Yes \
{ \
cout << "Yes" << endl; \
return 0; \
}
#define No \
{ \
cout << "No" << endl; \
return 0; \
}
#define OK \
{ \
cout << "OK" << endl; \
return 0; \
}
#define NG \
{ \
cout << "NG" << endl; \
return 0; \
}
#define sz(v) ((int)(v).size())
#define uniq(a) \
sort(all(a)); \
(a).resize(unique(all(a)) - a.begin());
#define dab(v) \
for (auto i : v) \
cout << i << ' '; \
cout << endl;
#define vin(v) \
for (ll i = 0; i < v.size(); ++i) \
cin >> v[i];
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> void out(T a) { cout << a << endl; }
template <class T> void die(T a) {
cout << a << endl;
exit(0);
}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
struct edge {
int to, cost;
};
typedef vector<vector<edge>> AdjList;
AdjList graph;
typedef pair<int, int> P;
const int INF = 10000000;
vector<int> dist;
vector<int> prever;
void dijkstra(int n, int s) {
dist = vector<int>(n, INF);
prever = vector<int>(n, -1);
dist[s] = 0;
priority_queue<P, vector<P>, greater<P>> que;
que.push(P(0, s));
while (!que.empty()) {
P p = que.top();
que.pop();
int v = p.second;
if (dist[v] < p.first) {
continue;
}
for (int i = 0; i < graph[v].size(); i++) {
edge e = graph[v][i];
if (dist[e.to] > dist[v] + e.cost) {
dist[e.to] = dist[v] + e.cost;
prever[e.to] = v;
que.push(P(dist[e.to], e.to));
}
}
}
}
vector<int> get_path(int t) { // 頂点tへの最短路
vector<int> path;
for (; t != -1; t = prever[t]) {
path.push_back(t);
}
// reverse(path.begin(), path.end());
return path;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// cout << fixed << setprecision(15);
int N, M;
cin >> N >> M;
graph = AdjList(N);
for (int i = 0; i < M; i++) {
int from, to;
cin >> from >> to;
from--;
to--;
graph[from].push_back((edge){to, 1});
graph[to].push_back((edge){from, 1});
}
dijkstra(N, 0);
// dab(prever);
rep1(i, prever.size()) if (prever[i] == -1) No;
out("Yes");
rep1(i, N) {
vector<int> ans = get_path(i);
if (ans.size() == 1)
No;
cout << ans[1] + 1 << endl;
;
// dab(ans);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep2(i, n) for (int i = 2; i < (int)(n); i++)
#define repk(i, k, n) for (int i = k; i < (int)(n); i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
// #define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
// const int64 INF = 1LL << 58;
#define dame \
{ \
puts("-1"); \
return 0; \
}
#define YES \
{ \
cout << "YES" << endl; \
return 0; \
}
#define NO \
{ \
cout << "NO" << endl; \
return 0; \
}
#define Yes \
{ \
cout << "Yes" << endl; \
return 0; \
}
#define No \
{ \
cout << "No" << endl; \
return 0; \
}
#define OK \
{ \
cout << "OK" << endl; \
return 0; \
}
#define NG \
{ \
cout << "NG" << endl; \
return 0; \
}
#define sz(v) ((int)(v).size())
#define uniq(a) \
sort(all(a)); \
(a).resize(unique(all(a)) - a.begin());
#define dab(v) \
for (auto i : v) \
cout << i << ' '; \
cout << endl;
#define vin(v) \
for (ll i = 0; i < v.size(); ++i) \
cin >> v[i];
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> void out(T a) { cout << a << endl; }
template <class T> void die(T a) {
cout << a << endl;
exit(0);
}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
struct edge {
int to, cost;
};
typedef vector<vector<edge>> AdjList;
AdjList graph;
typedef pair<int, int> P;
const int INF = 10000000;
vector<int> dist;
vector<int> prever;
void dijkstra(int n, int s) {
dist = vector<int>(n, INF);
prever = vector<int>(n, -1);
dist[s] = 0;
priority_queue<P, vector<P>, greater<P>> que;
que.push(P(0, s));
while (!que.empty()) {
P p = que.top();
que.pop();
int v = p.second;
if (dist[v] < p.first) {
continue;
}
for (int i = 0; i < graph[v].size(); i++) {
edge e = graph[v][i];
if (dist[e.to] > dist[v] + e.cost) {
dist[e.to] = dist[v] + e.cost;
prever[e.to] = v;
que.push(P(dist[e.to], e.to));
}
}
}
}
vector<int> get_path(int t) { // 頂点tへの最短路
vector<int> path;
for (; t != -1; t = prever[t]) {
path.push_back(t);
}
// reverse(path.begin(), path.end());
return path;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// cout << fixed << setprecision(15);
int N, M;
cin >> N >> M;
graph = AdjList(N);
for (int i = 0; i < M; i++) {
int from, to;
cin >> from >> to;
from--;
to--;
graph[from].push_back((edge){to, 1});
graph[to].push_back((edge){from, 1});
}
dijkstra(N, 0);
// dab(prever);
rep1(i, prever.size()) if (prever[i] == -1) No;
out("Yes");
rep1(i, N) {
// vector<int> ans = get_path(i);
// if(ans.size() == 1) No;
cout << prever[i] + 1 << endl;
;
// dab(ans);
}
return 0;
} | replace | 175 | 179 | 175 | 178 | TLE | |
p02678 | C++ | Runtime Error | #include "bits/stdc++.h"
const double pi = 3.141592653589793;
#define YESNO(x) x ? printf("YES") : printf("NO")
#define YesNo(x) x ? printf("Yes") : printf("No")
#define rep(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define scani(x) scanf("%d", &x)
#define scanll(x) scanf("%lld", &x)
#define printi(x) printf("%d", x)
#define printll(x) printf("%lld", x)
typedef long long ll;
using namespace std;
long long GCD(long long x, long long y) { return y ? GCD(y, x % y) : x; }
long long LCM(long long x, long long y) { return x * y / GCD(x, y); }
// give up(TLE)
int ABC168D() {
int n, m;
scani(n);
scani(m);
vector<int> graph[10001];
int ans[10001];
rep(i, 0, m) {
int a, b;
cin >> a >> b;
a--;
b--;
graph[a].push_back(b);
graph[b].push_back(a);
}
vector<bool> visit(n, false);
visit[0] = true;
queue<int> q;
q.push(0);
while (!q.empty()) {
int cur = q.front();
q.pop();
for (auto &itr : graph[cur]) {
if (!visit[itr]) {
ans[itr] = cur;
visit[itr] = true;
q.push(itr);
}
}
}
bool isOk = true;
for (auto itr : visit) {
if (!itr) {
YesNo(0);
return 0;
}
}
YesNo(1);
printf("\n");
rep(i, 1, n) { printf("%d\n", ans[i] + 1); }
return 0;
}
int main() {
ABC168D();
return 0;
} | #include "bits/stdc++.h"
const double pi = 3.141592653589793;
#define YESNO(x) x ? printf("YES") : printf("NO")
#define YesNo(x) x ? printf("Yes") : printf("No")
#define rep(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define scani(x) scanf("%d", &x)
#define scanll(x) scanf("%lld", &x)
#define printi(x) printf("%d", x)
#define printll(x) printf("%lld", x)
typedef long long ll;
using namespace std;
long long GCD(long long x, long long y) { return y ? GCD(y, x % y) : x; }
long long LCM(long long x, long long y) { return x * y / GCD(x, y); }
// give up(TLE)
int ABC168D() {
int n, m;
scani(n);
scani(m);
vector<int> graph[101010];
int ans[101010];
rep(i, 0, m) {
int a, b;
cin >> a >> b;
a--;
b--;
graph[a].push_back(b);
graph[b].push_back(a);
}
vector<bool> visit(n, false);
visit[0] = true;
queue<int> q;
q.push(0);
while (!q.empty()) {
int cur = q.front();
q.pop();
for (auto &itr : graph[cur]) {
if (!visit[itr]) {
ans[itr] = cur;
visit[itr] = true;
q.push(itr);
}
}
}
bool isOk = true;
for (auto itr : visit) {
if (!itr) {
YesNo(0);
return 0;
}
}
YesNo(1);
printf("\n");
rep(i, 1, n) { printf("%d\n", ans[i] + 1); }
return 0;
}
int main() {
ABC168D();
return 0;
} | replace | 23 | 25 | 23 | 25 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(v) (v).size()
#define all(v) (v).begin(), (v).end()
using namespace std;
template <typename T> T Max(T X, T Y) { return X > Y ? X : Y; }
template <typename T> T Min(T X, T Y) { return X < Y ? X : Y; }
template <typename T> void chmax(T &X, T Y) {
X = X > Y ? X : Y;
return;
}
template <typename T> void chmin(T &X, T Y) {
X = X < Y ? X : Y;
return;
}
const int maxn = 100005, maxm = 200005;
int n, m;
int len, to[maxm >> 1], nxt[maxm >> 1], head[maxn], dist[maxn], from[maxn];
queue<int> q;
inline void addedge(int u, int v) {
len++, nxt[len] = head[u], head[u] = len, to[len] = v;
return;
}
int main() {
memset(dist, -1, sizeof(dist));
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
int u, v;
scanf("%d%d", &u, &v);
addedge(u, v);
addedge(v, u);
}
dist[1] = 0;
q.push(1);
while (!q.empty()) {
int pos = q.front();
q.pop();
for (int i = head[pos]; i; i = nxt[i]) {
if (dist[to[i]] != -1)
continue;
dist[to[i]] = dist[pos] + 1;
from[to[i]] = pos;
q.push(to[i]);
}
}
for (int i = 1; i <= n; i++)
if (dist[i] == -1) {
printf("No\n");
return 0;
}
printf("Yes\n");
for (int pos = 2; pos <= n; pos++)
printf("%d\n", from[pos]);
return 0;
} | #include <bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(v) (v).size()
#define all(v) (v).begin(), (v).end()
using namespace std;
template <typename T> T Max(T X, T Y) { return X > Y ? X : Y; }
template <typename T> T Min(T X, T Y) { return X < Y ? X : Y; }
template <typename T> void chmax(T &X, T Y) {
X = X > Y ? X : Y;
return;
}
template <typename T> void chmin(T &X, T Y) {
X = X < Y ? X : Y;
return;
}
const int maxn = 100005, maxm = 200005;
int n, m;
int len, to[maxm << 1], nxt[maxm << 1], head[maxn], dist[maxn], from[maxn];
queue<int> q;
inline void addedge(int u, int v) {
len++, nxt[len] = head[u], head[u] = len, to[len] = v;
return;
}
int main() {
memset(dist, -1, sizeof(dist));
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
int u, v;
scanf("%d%d", &u, &v);
addedge(u, v);
addedge(v, u);
}
dist[1] = 0;
q.push(1);
while (!q.empty()) {
int pos = q.front();
q.pop();
for (int i = head[pos]; i; i = nxt[i]) {
if (dist[to[i]] != -1)
continue;
dist[to[i]] = dist[pos] + 1;
from[to[i]] = pos;
q.push(to[i]);
}
}
for (int i = 1; i <= n; i++)
if (dist[i] == -1) {
printf("No\n");
return 0;
}
printf("Yes\n");
for (int pos = 2; pos <= n; pos++)
printf("%d\n", from[pos]);
return 0;
} | replace | 21 | 22 | 21 | 22 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
int main(void) {
int N, M, a, b;
cin >> N >> M;
Graph G(N);
// N;頂点 M;辺
for (int i = 0; i < N; i++) {
cin >> a >> b;
a--;
b--;
G[a].push_back(b);
G[b].push_back(a);
}
vector<int> dist(N, -1);
vector<int> pre(N, -1);
queue<int> que;
dist[0] = 0;
que.push(0);
while (!que.empty()) {
int v = que.front();
que.pop();
for (int nv : G[v]) {
if (dist[nv] != -1)
continue; // すでに発見済みの頂点は探索しない
// 新たな白色頂点 nv について距離情報を更新してキューに追加する
dist[nv] = dist[v] + 1;
que.push(nv);
pre[nv] = v;
}
}
cout << "Yes" << endl;
for (int v = 1; v < N; ++v) {
cout << pre[v] + 1 << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
int main(void) {
int N, M, a, b;
cin >> N >> M;
Graph G(N);
// N;頂点 M;辺
for (int i = 0; i < M; i++) {
cin >> a >> b;
a--;
b--;
G[a].push_back(b);
G[b].push_back(a);
}
vector<int> dist(N, -1);
vector<int> pre(N, -1);
queue<int> que;
dist[0] = 0;
que.push(0);
while (!que.empty()) {
int v = que.front();
que.pop();
for (int nv : G[v]) {
if (dist[nv] != -1)
continue; // すでに発見済みの頂点は探索しない
// 新たな白色頂点 nv について距離情報を更新してキューに追加する
dist[nv] = dist[v] + 1;
que.push(nv);
pre[nv] = v;
}
}
cout << "Yes" << endl;
for (int v = 1; v < N; ++v) {
cout << pre[v] + 1 << endl;
}
return 0;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p02678 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<vector<int>> mymap(100001, vector<int>());
int res[100001];
queue<pair<int, int>> q;
void dfs(int from, int i) {
if (res[i] != 0)
return;
res[i] = from;
if (i == 1)
res[i] = 0;
for (auto &room : mymap[i]) {
if (res[room] != 0)
continue;
q.push(make_pair(i, room));
}
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
mymap[a].push_back(b);
mymap[b].push_back(a);
}
for (int i = 0; i < n + 1; i++)
res[i] = 0;
q.push(make_pair(0, 1));
while (q.size() != 0) {
pair<int, int> arg = q.front();
q.pop();
dfs(arg.first, arg.second);
}
cout << "Yes" << endl;
for (int i = 2; i < n + 1; i++) {
cout << res[i] << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<vector<int>> mymap(100001, vector<int>());
int res[100001];
queue<pair<int, int>> q;
void dfs(int from, int i) {
if (res[i] != 0)
return;
res[i] = from;
for (auto &room : mymap[i]) {
if (res[room] != 0)
continue;
q.push(make_pair(i, room));
}
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
mymap[a].push_back(b);
mymap[b].push_back(a);
}
for (int i = 0; i < n + 1; i++)
res[i] = 0;
q.push(make_pair(0, 1));
while (q.size() != 0) {
pair<int, int> arg = q.front();
q.pop();
dfs(arg.first, arg.second);
}
cout << "Yes" << endl;
for (int i = 2; i < n + 1; i++) {
cout << res[i] << endl;
}
} | delete | 13 | 15 | 13 | 13 | TLE | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define m1(x) memset(x, -1, sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;
int main() {
int n, m;
cin >> n >> m;
vector<int> e[11000];
int ans[11000];
rep(i, m) {
int a, b;
cin >> a >> b;
e[a].push_back(b);
e[b].push_back(a);
}
queue<int> q;
q.push(1);
while (!q.empty()) {
int c = q.front();
q.pop();
for (int d : e[c]) {
if (d == c)
continue;
if (ans[d] != 0)
continue;
ans[d] = c;
q.push(d);
}
}
cout << "Yes" << endl;
for (int i = 2; i <= n; i++) {
cout << ans[i] << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define m1(x) memset(x, -1, sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;
int main() {
int n, m;
cin >> n >> m;
vector<int> e[110000];
int ans[110000];
rep(i, m) {
int a, b;
cin >> a >> b;
e[a].push_back(b);
e[b].push_back(a);
}
queue<int> q;
q.push(1);
while (!q.empty()) {
int c = q.front();
q.pop();
for (int d : e[c]) {
if (d == c)
continue;
if (ans[d] != 0)
continue;
ans[d] = c;
q.push(d);
}
}
cout << "Yes" << endl;
for (int i = 2; i <= n; i++) {
cout << ans[i] << endl;
}
}
| replace | 14 | 16 | 14 | 16 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
if (a > b)
a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
if (a < b)
a = b;
}
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x << ": " << x << endl;
#else
#define debug(x)
#endif
struct Edge {
long long to;
long long cost;
};
using Graph = vector<vector<Edge>>;
using P = pair<long, int>;
vll dist;
vector<int> pre;
/* dijkstra(G,s,dis,prev)
入力:グラフ G, 開始点 s, 距離を格納する dis, 最短経路の前の点を記録するprev
計算量:O(|E|log|V|)
副作用:dis, prevが書き換えられる
*/
void dijkstra(const Graph &G, int s, vector<long long> &dis,
vector<int> &prev) {
int N = G.size();
dis.resize(N, INF);
prev.resize(N, -1); // 初期化
priority_queue<P, vector<P>, greater<P>> pq;
dis[s] = 0;
pq.emplace(dis[s], s);
while (!pq.empty()) {
P p = pq.top();
pq.pop();
int v = p.second;
if (dis[v] < p.first) {
continue;
}
for (auto &e : G[v]) {
if (dis[e.to] > dis[v] + e.cost) {
dis[e.to] = dis[v] + e.cost;
prev[e.to] = v; // 頂点 v を通って e.to にたどり着いた
pq.emplace(dis[e.to], e.to);
}
}
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
int N, M;
cin >> N >> M;
Graph g(N);
rep(i, N) {
ll a, b;
cin >> a >> b;
a--, b--;
Edge e1, e2;
e1.to = b, e1.cost = 1;
e2.to = a, e2.cost = 1;
g[a].push_back(e1);
g[b].push_back(e2);
}
dijkstra(g, 0, dist, pre);
rep(i, N) if (dist[i] >= INF) {
cout << "No" << endl;
return 0;
}
cout << "Yes" << endl;
for (ll i = 1; i < N; i++)
cout << pre[i] + 1 << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
if (a > b)
a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
if (a < b)
a = b;
}
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x << ": " << x << endl;
#else
#define debug(x)
#endif
struct Edge {
long long to;
long long cost;
};
using Graph = vector<vector<Edge>>;
using P = pair<long, int>;
vll dist;
vector<int> pre;
/* dijkstra(G,s,dis,prev)
入力:グラフ G, 開始点 s, 距離を格納する dis, 最短経路の前の点を記録するprev
計算量:O(|E|log|V|)
副作用:dis, prevが書き換えられる
*/
void dijkstra(const Graph &G, int s, vector<long long> &dis,
vector<int> &prev) {
int N = G.size();
dis.resize(N, INF);
prev.resize(N, -1); // 初期化
priority_queue<P, vector<P>, greater<P>> pq;
dis[s] = 0;
pq.emplace(dis[s], s);
while (!pq.empty()) {
P p = pq.top();
pq.pop();
int v = p.second;
if (dis[v] < p.first) {
continue;
}
for (auto &e : G[v]) {
if (dis[e.to] > dis[v] + e.cost) {
dis[e.to] = dis[v] + e.cost;
prev[e.to] = v; // 頂点 v を通って e.to にたどり着いた
pq.emplace(dis[e.to], e.to);
}
}
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
int N, M;
cin >> N >> M;
Graph g(N);
rep(i, M) {
ll a, b;
cin >> a >> b;
a--, b--;
Edge e1, e2;
e1.to = b, e1.cost = 1;
e2.to = a, e2.cost = 1;
g[a].push_back(e1);
g[b].push_back(e2);
}
dijkstra(g, 0, dist, pre);
rep(i, N) if (dist[i] >= INF) {
cout << "No" << endl;
return 0;
}
cout << "Yes" << endl;
for (ll i = 1; i < N; i++)
cout << pre[i] + 1 << endl;
}
| replace | 73 | 74 | 73 | 74 | 0 | |
p02678 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <string>
#include <vector>
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18 + 42
#define endl "\n"
#define out1(a) cout << #a << " " << a << endl
#define out2(a, b) cout << #a << " " << a << " " << #b << " " << b << endl
#define out3(a, b, c) \
cout << #a << " " << a << " " << #b << " " << b << " " << #c << " " << c \
<< endl
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repr(i, a, b) for (int i = a; i >= b; i--)
#define fori(it, A) for (auto it = A.begin(); it != A.end(); it++)
#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define zero(x) memset(x, 0, sizeof(x));
using namespace std;
int binpow(int a, int b) {
int res = 1;
while (b > 0) {
if (b & 1)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
void bfs(vector<vector<int>> &v, int x, vector<int> &vis, vector<int> &dist,
vector<int> &pred) {
queue<int> q;
q.push(x);
vis[x] = 1;
while (!q.empty()) {
int p = q.front();
q.pop();
rep(i, 0, v[p].size()) {
if (vis[v[p][i]] == 0) {
dist[v[p][i]] = dist[p] + 1;
pred[v[p][i]] = p;
vis[v[p][i]] = 1;
q.push(v[p][i]);
}
}
}
}
// START OF CODE ->->->->->->->
void solve() {
int n, m;
cin >> n >> m;
vector<vector<int>> v(n + 1);
rep(i, 0, m) {
int a, b;
cin >> a >> b;
v[a].pb(b);
v[b].pb(a);
}
vector<int> vis(n + 1, 0);
vector<int> dist(n + 1, mod);
dist[1] = 0;
vector<int> pred(n + 1, -1);
bfs(v, 1, vis, dist, pred);
int found = 0;
rep(i, 2, dist.size()) {
if (dist[i] == mod) {
found = 1;
break;
}
}
if (found == 1) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
rep(i, 2, dist.size()) {
int l = i;
// cout<<dist[i]<<endl;
vector<int> path;
while (pred[l] != -1) {
path.pb(pred[l]);
l = pred[l];
}
cout << path[0] << endl;
}
}
}
// END OF CODE ->->->->->->->->
signed main() {
fast;
int t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
| #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <string>
#include <vector>
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18 + 42
#define endl "\n"
#define out1(a) cout << #a << " " << a << endl
#define out2(a, b) cout << #a << " " << a << " " << #b << " " << b << endl
#define out3(a, b, c) \
cout << #a << " " << a << " " << #b << " " << b << " " << #c << " " << c \
<< endl
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repr(i, a, b) for (int i = a; i >= b; i--)
#define fori(it, A) for (auto it = A.begin(); it != A.end(); it++)
#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define zero(x) memset(x, 0, sizeof(x));
using namespace std;
int binpow(int a, int b) {
int res = 1;
while (b > 0) {
if (b & 1)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
void bfs(vector<vector<int>> &v, int x, vector<int> &vis, vector<int> &dist,
vector<int> &pred) {
queue<int> q;
q.push(x);
vis[x] = 1;
while (!q.empty()) {
int p = q.front();
q.pop();
rep(i, 0, v[p].size()) {
if (vis[v[p][i]] == 0) {
dist[v[p][i]] = dist[p] + 1;
pred[v[p][i]] = p;
vis[v[p][i]] = 1;
q.push(v[p][i]);
}
}
}
}
// START OF CODE ->->->->->->->
void solve() {
int n, m;
cin >> n >> m;
vector<vector<int>> v(n + 1);
rep(i, 0, m) {
int a, b;
cin >> a >> b;
v[a].pb(b);
v[b].pb(a);
}
vector<int> vis(n + 1, 0);
vector<int> dist(n + 1, mod);
dist[1] = 0;
vector<int> pred(n + 1, -1);
bfs(v, 1, vis, dist, pred);
int found = 0;
rep(i, 2, dist.size()) {
if (dist[i] == mod) {
found = 1;
break;
}
}
if (found == 1) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
rep(i, 2, dist.size()) {
int l = i;
// cout<<dist[i]<<endl;
vector<int> path;
while (pred[l] != -1) {
path.pb(pred[l]);
l = pred[l];
break;
}
cout << path[0] << endl;
}
}
}
// END OF CODE ->->->->->->->->
signed main() {
fast;
int t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
| insert | 106 | 106 | 106 | 107 | TLE | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
// #define int long long
using P = pair<int, int>;
#define LOG(variable) cout << #variable ":\t" << (variable) << endl
#define LOGCON(i, container) \
for (int(i) = 0; (i) < (container).size(); ++(i)) \
cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for (int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) \
for (auto itr = (obj).begin(); itr != (obj).end(); ++itr)
#define REPROBJ(itr, obj) \
for (auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
template <typename T = int> T in() {
T a;
cin >> a;
return a;
}
int torch_nums[100005];
vector<vector<int>> paths(10005);
bool visited[100005];
void bfs() {
queue<int> que;
int current = 0;
visited[0] = true;
que.push(0);
while (!que.empty()) {
current = que.front();
que.pop();
for (auto &next : paths[current]) {
if (visited[next])
continue;
que.push(next);
torch_nums[next] = current;
visited[next] = true;
}
}
}
/***** MAIN *****/
signed main() {
int n, m;
cin >> n >> m;
REP(i, m) {
int a, b;
cin >> a >> b;
--a;
--b;
paths[a].PB(b);
paths[b].PB(a);
}
bfs();
bool flag = true;
for (int i = 1; i < n; ++i) {
if (!visited[i]) {
flag = false;
break;
}
}
if (!flag) {
cout << "No" << endl;
return 0;
}
cout << "Yes" << endl;
for (int i = 1; i < n; ++i) {
cout << torch_nums[i] + 1 << endl;
}
return 0;
}
/***** MAIN *****/ | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
// #define int long long
using P = pair<int, int>;
#define LOG(variable) cout << #variable ":\t" << (variable) << endl
#define LOGCON(i, container) \
for (int(i) = 0; (i) < (container).size(); ++(i)) \
cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for (int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) \
for (auto itr = (obj).begin(); itr != (obj).end(); ++itr)
#define REPROBJ(itr, obj) \
for (auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
template <typename T = int> T in() {
T a;
cin >> a;
return a;
}
int torch_nums[100005];
vector<vector<int>> paths(200005);
bool visited[100005];
void bfs() {
queue<int> que;
int current = 0;
visited[0] = true;
que.push(0);
while (!que.empty()) {
current = que.front();
que.pop();
for (auto &next : paths[current]) {
if (visited[next])
continue;
que.push(next);
torch_nums[next] = current;
visited[next] = true;
}
}
}
/***** MAIN *****/
signed main() {
int n, m;
cin >> n >> m;
REP(i, m) {
int a, b;
cin >> a >> b;
--a;
--b;
paths[a].PB(b);
paths[b].PB(a);
}
bfs();
bool flag = true;
for (int i = 1; i < n; ++i) {
if (!visited[i]) {
flag = false;
break;
}
}
if (!flag) {
cout << "No" << endl;
return 0;
}
cout << "Yes" << endl;
for (int i = 1; i < n; ++i) {
cout << torch_nums[i] + 1 << endl;
}
return 0;
}
/***** MAIN *****/ | replace | 34 | 35 | 34 | 35 | 0 | |
p02678 | C++ | Time Limit Exceeded | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout << (bool x ? "Yes" : "No") << endl;
#define out(s) cout << s << endl;
#define pb push_back;
#define sp " ";
void vout(vector<int> v) {
for (unsigned int i = 1; i < v.size(); i++)
cout << v.at(i) + 1 << endl;
}
int main() {
int n, m;
cin >> n >> m;
vvi edge(n, vi(n));
vi ans(n, -1);
rep(i, m) {
int s, t;
cin >> s >> t;
s--;
t--;
edge.at(s).push_back(t);
edge.at(t).push_back(s);
}
queue<int> q;
q.push(0);
while (!q.empty()) {
int k = q.front();
q.pop();
for (int j : edge.at(k)) {
if (ans.at(j) == -1) {
ans.at(j) = k;
q.push(j);
}
}
}
cout << "Yes" << endl;
vout(ans);
} | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout << (bool x ? "Yes" : "No") << endl;
#define out(s) cout << s << endl;
#define pb push_back;
#define sp " ";
void vout(vector<int> v) {
for (unsigned int i = 1; i < v.size(); i++)
cout << v.at(i) + 1 << endl;
}
int main() {
int n, m;
cin >> n >> m;
vvi edge(n);
vi ans(n, -1);
rep(i, m) {
int s, t;
cin >> s >> t;
s--;
t--;
edge.at(s).push_back(t);
edge.at(t).push_back(s);
}
queue<int> q;
q.push(0);
while (!q.empty()) {
int k = q.front();
q.pop();
for (int j : edge.at(k)) {
if (ans.at(j) == -1) {
ans.at(j) = k;
q.push(j);
}
}
}
cout << "Yes" << endl;
vout(ans);
} | replace | 19 | 20 | 19 | 20 | TLE | |
p02678 | C++ | Time Limit Exceeded | #pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define REP(i, n) for (decltype(n) i = 0; i < (n); ++i)
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, M;
cin >> N >> M;
vector<vector<int>> adj(N);
REP(i, N) { adj[i].reserve(M); }
REP(i, M) {
int a, b;
cin >> a >> b;
a--;
b--;
adj[a].push_back(b);
adj[b].push_back(a);
}
deque<tuple<int, int, int>> q;
q.emplace_back(0, 0, -1);
int INF = N + 10;
vector<int> dist(N, INF);
vector<int> prev(N, -1);
int cnt = 0;
while (!q.empty()) {
auto [l, node, pnode] = q.front();
q.pop_front();
if (dist[node] < l)
continue;
dist[node] = l;
prev[node] = pnode;
++l;
for (auto &&nxt : adj[node]) {
if (dist[nxt] > l) {
q.emplace_back(l, nxt, node);
}
}
}
cout << "Yes\n";
for (int i = 1; i < N; ++i) {
cout << (prev[i] + 1) << "\n";
}
}
| #pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define REP(i, n) for (decltype(n) i = 0; i < (n); ++i)
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, M;
cin >> N >> M;
vector<vector<int>> adj(N);
REP(i, N) { adj[i].reserve(M); }
REP(i, M) {
int a, b;
cin >> a >> b;
a--;
b--;
adj[a].push_back(b);
adj[b].push_back(a);
}
deque<tuple<int, int, int>> q;
q.emplace_back(0, 0, -1);
int INF = N + 10;
vector<int> dist(N, INF);
vector<int> prev(N, -1);
int cnt = 0;
while (!q.empty()) {
auto [l, node, pnode] = q.front();
q.pop_front();
if (dist[node] <= l)
continue;
dist[node] = l;
prev[node] = pnode;
++l;
for (auto &&nxt : adj[node]) {
if (dist[nxt] > l) {
q.emplace_back(l, nxt, node);
}
}
}
cout << "Yes\n";
for (int i = 1; i < N; ++i) {
cout << (prev[i] + 1) << "\n";
}
}
| replace | 30 | 31 | 30 | 31 | TLE | |
p02678 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define inf 0x3f3f3f3f
double const pi = acos(double(-1));
const int maxn = 2e5 + 100;
using namespace std;
typedef long long ll;
struct node {
ll to;
ll next;
} edge[maxn + 5];
ll n, m, ans;
ll head[maxn + 5];
void addedge(ll u, ll v) {
edge[ans].to = v;
edge[ans].next = head[u];
head[u] = ans++;
}
void init() {
memset(head, -1, sizeof(head));
ans = 0;
}
ll cnt = 0;
ll num[maxn + 5];
int vis[maxn + 5];
void bfs(int u) {
queue<int> q;
vis[u] = 1;
q.push(u);
while (!q.empty()) {
int k = q.front();
q.pop();
// printf("%d ",k);
for (int i = head[k]; ~i; i = edge[i].next) {
int to = edge[i].to;
if (vis[to] == -1) {
q.push(to);
vis[to] = k;
cnt++;
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
init();
cin >> n >> m;
for (ll i = 0; i < m; i++) {
ll u, v;
cin >> u >> v;
addedge(u, v);
addedge(v, u);
}
memset(vis, -1, sizeof(vis));
bfs(1);
// printf("\n");
if (cnt != n - 1) {
cout << "No";
return 0;
} else
cout << "Yes" << endl;
for (int i = 2; i <= n; i++)
cout << vis[i] << endl;
cout << endl;
return 0;
} | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define inf 0x3f3f3f3f
double const pi = acos(double(-1));
const int maxn = 4e5 + 100;
using namespace std;
typedef long long ll;
struct node {
ll to;
ll next;
} edge[maxn + 5];
ll n, m, ans;
ll head[maxn + 5];
void addedge(ll u, ll v) {
edge[ans].to = v;
edge[ans].next = head[u];
head[u] = ans++;
}
void init() {
memset(head, -1, sizeof(head));
ans = 0;
}
ll cnt = 0;
ll num[maxn + 5];
int vis[maxn + 5];
void bfs(int u) {
queue<int> q;
vis[u] = 1;
q.push(u);
while (!q.empty()) {
int k = q.front();
q.pop();
// printf("%d ",k);
for (int i = head[k]; ~i; i = edge[i].next) {
int to = edge[i].to;
if (vis[to] == -1) {
q.push(to);
vis[to] = k;
cnt++;
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
init();
cin >> n >> m;
for (ll i = 0; i < m; i++) {
ll u, v;
cin >> u >> v;
addedge(u, v);
addedge(v, u);
}
memset(vis, -1, sizeof(vis));
bfs(1);
// printf("\n");
if (cnt != n - 1) {
cout << "No";
return 0;
} else
cout << "Yes" << endl;
for (int i = 2; i <= n; i++)
cout << vis[i] << endl;
cout << endl;
return 0;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ris return *this
#define tmplt template <class T
#define dbgo debug &operator<<
tmplt > struct rge {
T b, e;
};
tmplt > rge<T> range(T i, T j) { return rge<T>{i, j}; }
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
tmplt > dbgo(T x) {
cerr << boolalpha << x;
ris;
}
tmplt, class C > dbgo(pair<T, C> x) {
ris << "(" << x.first << ", " << x.second << ")";
}
tmplt > dbgo(rge<T> x) {
*this << "[";
for (auto it = x.b; it != x.e; it++) {
*this << ", " + 2 * (it == x.b) << *it;
}
ris << "]";
}
tmplt > dbgo(vector<T> x) { ris << range(x.begin(), x.end()); }
#else
tmplt > dbgo(const T &) { ris; }
#endif
};
#define nav(...) << "[ " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ] "
using ll = long long;
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ford(i, n) for (int i = n - 1; i >= 0; i--)
template <typename T> void min_self(T &a, T b) { a = min(a, b); }
template <typename T> void max_self(T &a, T b) { a = max(a, b); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> g(n);
forn(i, n) {
int u, v;
cin >> u >> v;
u--, v--;
g[u].push_back(v);
g[v].push_back(u);
}
vector<int> par(n, -1);
vector<int> q{0};
par[0] = 0;
forn(i, q.size()) {
int u = q[i];
for (int v : g[u]) {
if (par[v] == -1) {
par[v] = u;
q.push_back(v);
}
}
}
cout << "Yes\n";
for (int i = 1; i < n; i++) {
cout << par[i] + 1 << '\n';
}
}
// Don't worry, you're getting better
// Read statement carefully
// Solve on paper first!
// Make your infinity big enough
// Overflows (long long)
// Author: blondie
| #include <bits/stdc++.h>
using namespace std;
#define ris return *this
#define tmplt template <class T
#define dbgo debug &operator<<
tmplt > struct rge {
T b, e;
};
tmplt > rge<T> range(T i, T j) { return rge<T>{i, j}; }
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
tmplt > dbgo(T x) {
cerr << boolalpha << x;
ris;
}
tmplt, class C > dbgo(pair<T, C> x) {
ris << "(" << x.first << ", " << x.second << ")";
}
tmplt > dbgo(rge<T> x) {
*this << "[";
for (auto it = x.b; it != x.e; it++) {
*this << ", " + 2 * (it == x.b) << *it;
}
ris << "]";
}
tmplt > dbgo(vector<T> x) { ris << range(x.begin(), x.end()); }
#else
tmplt > dbgo(const T &) { ris; }
#endif
};
#define nav(...) << "[ " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ] "
using ll = long long;
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ford(i, n) for (int i = n - 1; i >= 0; i--)
template <typename T> void min_self(T &a, T b) { a = min(a, b); }
template <typename T> void max_self(T &a, T b) { a = max(a, b); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> g(n);
forn(i, m) {
int u, v;
cin >> u >> v;
u--, v--;
g[u].push_back(v);
g[v].push_back(u);
}
vector<int> par(n, -1);
vector<int> q{0};
par[0] = 0;
forn(i, q.size()) {
int u = q[i];
for (int v : g[u]) {
if (par[v] == -1) {
par[v] = u;
q.push_back(v);
}
}
}
cout << "Yes\n";
for (int i = 1; i < n; i++) {
cout << par[i] + 1 << '\n';
}
}
// Don't worry, you're getting better
// Read statement carefully
// Solve on paper first!
// Make your infinity big enough
// Overflows (long long)
// Author: blondie
| replace | 48 | 49 | 48 | 49 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
#define pi 3.1415
#define ll long long
#define pii pair<ll, ll>
#define debug(a) cout << a << '\n'
#define maxn 50009
#define MOD 1000000007
#define rep(i, a, b) for (ll i = a; i < (b); ++i)
using namespace std;
const ll INF = 1e15 + 9;
ll n, m;
vector<pii> adj[maxn];
ll dis[maxn];
ll pai[maxn];
void addedge(ll a, ll b, ll c) {
adj[a].push_back({b, c});
adj[b].push_back({a, c});
}
void INFINITAR() {
for (ll i = 0; i <= n; i++) {
dis[i] = INF;
}
}
void dijkstra(int x) {
INFINITAR();
dis[x] = 0;
priority_queue<pii, vector<pii>, greater<pii>> pq;
pq.push({0, x});
while (!pq.empty()) {
auto f = pq.top();
pq.pop();
if (dis[f.second] < f.first)
continue;
for (auto e : adj[f.second]) {
if (f.first + e.second < dis[e.first]) {
pai[e.first] = f.second;
dis[e.first] = f.first + e.second;
pq.push({dis[e.first], e.first});
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
memset(pai, -1, sizeof pai);
while (m--) {
ll a, b;
cin >> a >> b;
addedge(a, b, 1);
}
dijkstra(1);
bool can = true;
rep(i, 2, n + 1) {
if (pai[i] == -1)
can = false;
}
if (!can) {
cout << "No\n";
} else {
cout << "Yes\n";
rep(i, 2, n + 1) cout << pai[i] << '\n';
}
return 0;
} | #include <bits/stdc++.h>
#define pi 3.1415
#define ll long long
#define pii pair<ll, ll>
#define debug(a) cout << a << '\n'
#define maxn 200009
#define MOD 1000000007
#define rep(i, a, b) for (ll i = a; i < (b); ++i)
using namespace std;
const ll INF = 1e15 + 9;
ll n, m;
vector<pii> adj[maxn];
ll dis[maxn];
ll pai[maxn];
void addedge(ll a, ll b, ll c) {
adj[a].push_back({b, c});
adj[b].push_back({a, c});
}
void INFINITAR() {
for (ll i = 0; i <= n; i++) {
dis[i] = INF;
}
}
void dijkstra(int x) {
INFINITAR();
dis[x] = 0;
priority_queue<pii, vector<pii>, greater<pii>> pq;
pq.push({0, x});
while (!pq.empty()) {
auto f = pq.top();
pq.pop();
if (dis[f.second] < f.first)
continue;
for (auto e : adj[f.second]) {
if (f.first + e.second < dis[e.first]) {
pai[e.first] = f.second;
dis[e.first] = f.first + e.second;
pq.push({dis[e.first], e.first});
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
memset(pai, -1, sizeof pai);
while (m--) {
ll a, b;
cin >> a >> b;
addedge(a, b, 1);
}
dijkstra(1);
bool can = true;
rep(i, 2, n + 1) {
if (pai[i] == -1)
can = false;
}
if (!can) {
cout << "No\n";
} else {
cout << "Yes\n";
rep(i, 2, n + 1) cout << pai[i] << '\n';
}
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02678 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
void _cin() {}
template <class Head, class... Tail> void _cin(Head &&head, Tail &&...tail) {
cin >> head;
_cin(forward<Tail>(tail)...);
}
void _cout() { cout << "\n"; }
template <class Head, class... Tail> void _cout(Head &&head, Tail &&...tail) {
cout << head;
_cout(forward<Tail>(tail)...);
}
int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }
template <typename S, typename T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
cout << "[" << p.first << ", " << p.second << "]";
return os;
}
#define Sq(x) (x) * (x)
#define For(i, n) for (int i = 0; i < (n); i++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) \
vector<T> sxs(xs.size() + 1); \
For(i, (int)xs.size()) sxs[i + 1] = sxs[i] + xs[i]
#define Cin(T, ...) \
T __VA_ARGS__; \
_cin(__VA_ARGS__)
#define Cins(T, n, xs) \
vector<T> xs(n); \
For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) \
vector<T> xs(n), ys(n); \
For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) \
vector<T> xs(n), ys(n), zs(n); \
For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) \
Vec2(T, n, m, xs); \
For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) \
unordered_map<T, int> map; \
Rep(n) { \
Cin(T, x); \
map[x]++; \
}
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) \
{ \
for (const auto &e : xs) \
cout << e << " "; \
cout << "\n"; \
}
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Return(expr) \
{ \
Cout(expr); \
return 0; \
}
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)
// constexpr int MOD = 1e9+7;
#include <deque>
int main(void) {
Cin(int, n, m);
vc<vc<int>> to(n);
Rep(m) {
Cin(int, a, b);
a--, b--;
to[a].push_back(b);
to[b].push_back(a);
}
vc<int> ans(n, -1);
deque<pair<int, int>> q;
q.emplace_back(0, -2);
while (!q.empty()) {
const auto &[i, from] = q.front();
q.pop_front();
if (ans[i] != -1)
continue;
ans[i] = from;
for (const auto &j : to[i]) {
q.emplace_back(j, i);
}
}
Cout("Yes");
for (int i = 1; i < n; i++) {
Cout(ans[i] + 1);
}
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
void _cin() {}
template <class Head, class... Tail> void _cin(Head &&head, Tail &&...tail) {
cin >> head;
_cin(forward<Tail>(tail)...);
}
void _cout() { cout << "\n"; }
template <class Head, class... Tail> void _cout(Head &&head, Tail &&...tail) {
cout << head;
_cout(forward<Tail>(tail)...);
}
int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }
template <typename S, typename T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
cout << "[" << p.first << ", " << p.second << "]";
return os;
}
#define Sq(x) (x) * (x)
#define For(i, n) for (int i = 0; i < (n); i++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) \
vector<T> sxs(xs.size() + 1); \
For(i, (int)xs.size()) sxs[i + 1] = sxs[i] + xs[i]
#define Cin(T, ...) \
T __VA_ARGS__; \
_cin(__VA_ARGS__)
#define Cins(T, n, xs) \
vector<T> xs(n); \
For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) \
vector<T> xs(n), ys(n); \
For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) \
vector<T> xs(n), ys(n), zs(n); \
For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) \
Vec2(T, n, m, xs); \
For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) \
unordered_map<T, int> map; \
Rep(n) { \
Cin(T, x); \
map[x]++; \
}
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) \
{ \
for (const auto &e : xs) \
cout << e << " "; \
cout << "\n"; \
}
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Return(expr) \
{ \
Cout(expr); \
return 0; \
}
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)
// constexpr int MOD = 1e9+7;
#include <deque>
int main(void) {
Cin(int, n, m);
vc<vc<int>> to(n);
Rep(m) {
Cin(int, a, b);
a--, b--;
to[a].push_back(b);
to[b].push_back(a);
}
vc<int> ans(n, -1);
deque<pair<int, int>> q;
q.emplace_back(0, -2);
while (!q.empty()) {
const auto [i, from] = q.front();
q.pop_front();
if (ans[i] != -1)
continue;
ans[i] = from;
for (const auto &j : to[i]) {
q.emplace_back(j, i);
}
}
Cout("Yes");
for (int i = 1; i < n; i++) {
Cout(ans[i] + 1);
}
}
| replace | 99 | 100 | 99 | 100 | 0 | |
p02678 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (n); ++i)
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
const ll INF = 1LL << 60;
const int inf = (1 << 30) - 1;
const int mod = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, -1, -1, 1, 1};
int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};
const int nmax = 100005;
vector<vector<pair<ll, ll>>> g(nmax);
ll d[nmax];
void dijkstra(ll s) {
priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
fill(d, d + nmax, INF);
d[s] = 0;
pq.push(make_pair(0, s));
while (!pq.empty()) {
pair<ll, ll> p = pq.top();
pq.pop();
ll v = p.second;
if (d[v] < p.first) {
continue;
}
for (auto x : g[v]) {
if (d[x.first] > d[v] + x.second) {
d[x.first] = d[v] + x.second;
pq.push(make_pair(d[x.first], x.first));
}
}
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<int> a(n), b(n), c(n, inf), ans(n);
rep(i, m) {
cin >> a[i] >> b[i];
a[i]--, b[i]--;
g[a[i]].push_back({b[i], 1});
g[b[i]].push_back({a[i], 1});
}
dijkstra(0);
rep(i, m) {
if (d[a[i]] < d[b[i]]) {
if (c[b[i]] > d[a[i]]) {
c[b[i]] = d[a[i]];
ans[b[i]] = a[i];
}
} else if (d[a[i]] > d[b[i]]) {
if (c[a[i]] > d[b[i]]) {
c[a[i]] = d[b[i]];
ans[a[i]] = b[i];
}
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
cout << ans[i] + 1 << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (n); ++i)
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
const ll INF = 1LL << 60;
const int inf = (1 << 30) - 1;
const int mod = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, -1, -1, 1, 1};
int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};
const int nmax = 100005;
vector<vector<pair<ll, ll>>> g(nmax);
ll d[nmax];
void dijkstra(ll s) {
priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
fill(d, d + nmax, INF);
d[s] = 0;
pq.push(make_pair(0, s));
while (!pq.empty()) {
pair<ll, ll> p = pq.top();
pq.pop();
ll v = p.second;
if (d[v] < p.first) {
continue;
}
for (auto x : g[v]) {
if (d[x.first] > d[v] + x.second) {
d[x.first] = d[v] + x.second;
pq.push(make_pair(d[x.first], x.first));
}
}
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<int> a(m), b(m), c(n, inf), ans(n);
rep(i, m) {
cin >> a[i] >> b[i];
a[i]--, b[i]--;
g[a[i]].push_back({b[i], 1});
g[b[i]].push_back({a[i], 1});
}
dijkstra(0);
rep(i, m) {
if (d[a[i]] < d[b[i]]) {
if (c[b[i]] > d[a[i]]) {
c[b[i]] = d[a[i]];
ans[b[i]] = a[i];
}
} else if (d[a[i]] > d[b[i]]) {
if (c[a[i]] > d[b[i]]) {
c[a[i]] = d[b[i]];
ans[a[i]] = b[i];
}
}
}
cout << "Yes" << endl;
for (int i = 1; i < n; i++) {
cout << ans[i] + 1 << endl;
}
} | replace | 52 | 53 | 52 | 53 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.