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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02847 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const string S[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
int main() {
string s;
cin >> s;
int res = 0;
for (int i = 1; i <= 7; i++)
if (s == S[i])
res = i;
cout << 7 - res << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const string S[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
int main() {
string s;
cin >> s;
int res = 0;
for (int i = 0; i < 7; i++)
if (s == S[i])
res = i;
cout << 7 - res << endl;
return 0;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p02847 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// ----------------------R00TDADA------------------------------
#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada ios_base::sync_with_stdio(false)
#define int long long
signed main() {
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
rootdada;
string s;
cin >> s;
if (s == "SUN")
cout << 7 << endl;
if (s == "SAT")
cout << 1 << endl;
if (s == "MON")
cout << 6 << endl;
if (s == "TUE")
cout << 5 << endl;
if (s == "WED")
cout << 4 << endl;
if (s == "THU")
cout << 3 << endl;
if (s == "FRI")
cout << 2 << endl;
} | #include <bits/stdc++.h>
using namespace std;
// ----------------------R00TDADA------------------------------
#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada ios_base::sync_with_stdio(false)
#define int long long
signed main() {
rootdada;
string s;
cin >> s;
if (s == "SUN")
cout << 7 << endl;
if (s == "SAT")
cout << 1 << endl;
if (s == "MON")
cout << 6 << endl;
if (s == "TUE")
cout << 5 << endl;
if (s == "WED")
cout << 4 << endl;
if (s == "THU")
cout << 3 << endl;
if (s == "FRI")
cout << 2 << endl;
} | replace | 21 | 27 | 21 | 22 | 0 | |
p02847 | Python | Runtime Error | W = ["SUM", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
S = input()
print(len(W) - W.index(S))
| W = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
S = input()
print(len(W) - W.index(S))
| replace | 0 | 1 | 0 | 1 | 0 | |
p02847 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF (ll)2e9
#define MOD ((ll)1e9 + 7)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define bit(n) (1LL << (n))
#define cauto const auto &
#define println(v) cout << v << "\n";
void show(vector<ll> &arr, int w) {
REP(i, arr.size()) { cout << right << setw(w) << i; }
cout << endl;
REP(i, arr.size()) {
if (abs(INF - arr[i]) < 1e5) {
cout << right << setw(w) << (arr[i] == INF ? "INF" : "inf");
} else {
cout << right << setw(w) << arr[i];
}
}
cout << endl;
}
void show(vector<vector<ll>> &arr, int w) {
cout << right << setw(w) << "#";
REP(i, SZ(arr[0])) { cout << right << setw(w) << i; }
cout << endl;
REP(i, SZ(arr)) {
cout << right << setw(w) << i;
REP(j, SZ(arr[0])) {
if (abs(INF - arr[i][j]) < 1e5) {
cout << right << setw(w) << (arr[i][j] == INF ? "INF" : "inf");
} else {
cout << right << setw(w) << arr[i][j];
}
}
cout << endl;
}
}
void show(vector<vector<vector<ll>>> &arr, int w) {
REP(i, arr.size()) {
println("i: " + to_string(i));
show(arr[i], w);
println("");
}
}
inline vector<vector<vector<ll>>> make_vector(ll i, ll j, ll k) {
vector<vector<vector<ll>>> v(i, vector<vector<ll>>(j, vector<ll>(k, 0)));
return v;
}
inline vector<vector<ll>> make_vector(ll i, ll j) {
vector<vector<ll>> v(i, vector<ll>(j, 0));
return v;
}
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;
}
template <class InputIterator>
InputIterator
adv(InputIterator x,
typename std::iterator_traits<InputIterator>::difference_type n) {
advance(x, n);
return x;
}
class mod {
static ll fact[];
public:
template <class... A> static ll mul(A... args) {
ll res = 1;
for (ll i : std::initializer_list<ll>{args...}) {
res = (res * i) % MOD;
}
return res;
}
static ll power(ll base, ll exp) {
if (exp == 0)
return 1;
if (exp & 1) {
return mul(base, power(base, exp - 1));
} else {
ll p = power(base, exp / 2);
return mul(p, p);
}
}
static ll calc_factorial(int n) {
fact[0] = 1;
FOR(i, 1, n + 1) { fact[i] = mul(fact[i - 1], i); }
}
static ll factorial(int n) {
if (fact[n] != 0)
return fact[n];
if (n == 0)
return 1;
return fact[n] = mul(n, factorial(n - 1));
}
static ll inverse(int n) { return power(n, MOD - 2); }
static ll comb(int n, int r) {
if (r < 0 || r > n)
return 0;
return mul(factorial(n), inverse(factorial(n - r)), inverse(factorial(r)));
}
template <class... A> static ll div(ll dividend, A... args) {
ll res = dividend;
for (ll i : std::initializer_list<ll>{args...}) {
res = mul(res, inverse(i));
}
return res;
}
template <class... A> static ll add(A... args) {
ll res = 0;
for (ll i : std::initializer_list<ll>{args...}) {
res = (res + i) % MOD;
}
return res;
}
template <class... A> static ll sub(ll l, A... args) {
ll res = l;
for (ll i : std::initializer_list<ll>{args...}) {
res = (res - i + MOD) % MOD;
}
return res;
}
};
ll mod::fact[(int)2e6 + 1];
int ni() {
int i;
cin >> i;
return i;
}
ll nll() {
ll l;
cin >> l;
return l;
}
int main() {
string youbi[] = {"SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};
string today;
cin >> today;
REP(i, 8) {
if (youbi[i] == today) {
println(i + 1);
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF (ll)2e9
#define MOD ((ll)1e9 + 7)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define bit(n) (1LL << (n))
#define cauto const auto &
#define println(v) cout << v << "\n";
void show(vector<ll> &arr, int w) {
REP(i, arr.size()) { cout << right << setw(w) << i; }
cout << endl;
REP(i, arr.size()) {
if (abs(INF - arr[i]) < 1e5) {
cout << right << setw(w) << (arr[i] == INF ? "INF" : "inf");
} else {
cout << right << setw(w) << arr[i];
}
}
cout << endl;
}
void show(vector<vector<ll>> &arr, int w) {
cout << right << setw(w) << "#";
REP(i, SZ(arr[0])) { cout << right << setw(w) << i; }
cout << endl;
REP(i, SZ(arr)) {
cout << right << setw(w) << i;
REP(j, SZ(arr[0])) {
if (abs(INF - arr[i][j]) < 1e5) {
cout << right << setw(w) << (arr[i][j] == INF ? "INF" : "inf");
} else {
cout << right << setw(w) << arr[i][j];
}
}
cout << endl;
}
}
void show(vector<vector<vector<ll>>> &arr, int w) {
REP(i, arr.size()) {
println("i: " + to_string(i));
show(arr[i], w);
println("");
}
}
inline vector<vector<vector<ll>>> make_vector(ll i, ll j, ll k) {
vector<vector<vector<ll>>> v(i, vector<vector<ll>>(j, vector<ll>(k, 0)));
return v;
}
inline vector<vector<ll>> make_vector(ll i, ll j) {
vector<vector<ll>> v(i, vector<ll>(j, 0));
return v;
}
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;
}
template <class InputIterator>
InputIterator
adv(InputIterator x,
typename std::iterator_traits<InputIterator>::difference_type n) {
advance(x, n);
return x;
}
class mod {
static ll fact[];
public:
template <class... A> static ll mul(A... args) {
ll res = 1;
for (ll i : std::initializer_list<ll>{args...}) {
res = (res * i) % MOD;
}
return res;
}
static ll power(ll base, ll exp) {
if (exp == 0)
return 1;
if (exp & 1) {
return mul(base, power(base, exp - 1));
} else {
ll p = power(base, exp / 2);
return mul(p, p);
}
}
static ll calc_factorial(int n) {
fact[0] = 1;
FOR(i, 1, n + 1) { fact[i] = mul(fact[i - 1], i); }
}
static ll factorial(int n) {
if (fact[n] != 0)
return fact[n];
if (n == 0)
return 1;
return fact[n] = mul(n, factorial(n - 1));
}
static ll inverse(int n) { return power(n, MOD - 2); }
static ll comb(int n, int r) {
if (r < 0 || r > n)
return 0;
return mul(factorial(n), inverse(factorial(n - r)), inverse(factorial(r)));
}
template <class... A> static ll div(ll dividend, A... args) {
ll res = dividend;
for (ll i : std::initializer_list<ll>{args...}) {
res = mul(res, inverse(i));
}
return res;
}
template <class... A> static ll add(A... args) {
ll res = 0;
for (ll i : std::initializer_list<ll>{args...}) {
res = (res + i) % MOD;
}
return res;
}
template <class... A> static ll sub(ll l, A... args) {
ll res = l;
for (ll i : std::initializer_list<ll>{args...}) {
res = (res - i + MOD) % MOD;
}
return res;
}
};
ll mod::fact[(int)2e6 + 1];
int ni() {
int i;
cin >> i;
return i;
}
ll nll() {
ll l;
cin >> l;
return l;
}
int main() {
string youbi[] = {"SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};
string today;
cin >> today;
REP(i, 7) {
if (youbi[i] == today) {
println(i + 1);
}
}
return 0;
} | replace | 178 | 179 | 178 | 179 | 0 | |
p02847 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define debug(x) cerr << #x " = " << (x) << endl;
#define P(x) cerr << #x << endl;
#define int long long
typedef pair<int, int> pii;
const int mod = 1000000007;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed << setprecision(9);
vector<string> days = {"MON", "TUES", "WED", "THU", "FRI", "SAT", "SUN",
"MON", "TUES", "WED", "THU", "FRI", "SAT", "SUN"};
int n = days.size();
string s;
cin >> s;
int i = 0;
while (s != days[i])
++i;
int first = i;
++i;
// cout << i << '\n';
while (days[i] != "SUN")
++i;
cout << i - first << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define debug(x) cerr << #x " = " << (x) << endl;
#define P(x) cerr << #x << endl;
#define int long long
typedef pair<int, int> pii;
const int mod = 1000000007;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed << setprecision(9);
vector<string> days = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN",
"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
int n = days.size();
string s;
cin >> s;
int i = 0;
while (s != days[i])
++i;
int first = i;
++i;
// cout << i << '\n';
while (days[i] != "SUN")
++i;
cout << i - first << '\n';
return 0;
}
| replace | 14 | 16 | 14 | 16 | 0 | |
p02847 | C++ | Runtime Error | #include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
vector<string> s = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
string today;
cin >> today;
rep(i, 8) if (today == s[i]) cout << 7 - i << endl;
return 0;
} | #include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
vector<string> s = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
string today;
cin >> today;
rep(i, 7) if (today == s[i]) cout << 7 - i << endl;
return 0;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p02848 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <math.h>
using namespace std;
int i, j, k, n, m, l, count1 = 0;
void ABC140(void);
void ABC141(void);
void ABC142(void);
void ABC143(void);
void ABC144(void);
void ABC145(void);
void ABC146(void);
void ABC147(void);
void ABC148(void);
void ABC149(void);
int main(void) { ABC146(); }
void ABC146() {
string s;
cin >> n;
cin >> s;
cout << s.substr(n, s.length() - n) << s.substr(0, n) << endl;
}
| #include <bits/stdc++.h>
#include <math.h>
using namespace std;
int i, j, k, n, m, l, count1 = 0;
void ABC140(void);
void ABC141(void);
void ABC142(void);
void ABC143(void);
void ABC144(void);
void ABC145(void);
void ABC146(void);
void ABC147(void);
void ABC148(void);
void ABC149(void);
int main(void) { ABC146(); }
void ABC146() {
string s;
cin >> n;
cin >> s;
for (i = 0; i < s.length(); i++) {
s[i] += n;
if (s[i] > 'Z')
s[i] += 'A' - 'Z' - 1;
}
cout << s << endl;
} | replace | 21 | 22 | 21 | 27 | 0 | |
p02848 | C++ | Runtime Error | #include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x) {
if (x <= 1)
return false;
for (ll i = 2; sqrt(i) <= x; i++)
if (x % i == 0)
return false;
return true;
}
int main() {
int n;
cin >> n;
string s;
FOR(i, 0, n) cin >> s.at(i);
FOR(i, 0, s.size()) { s.at(i) = (s.at(i) - 'A' + n) % 26 + 'A'; }
cout << s << endl;
return 0;
}
| #include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x) {
if (x <= 1)
return false;
for (ll i = 2; sqrt(i) <= x; i++)
if (x % i == 0)
return false;
return true;
}
int main() {
int n;
cin >> n;
string s;
cin >> s;
FOR(i, 0, s.size()) { s.at(i) = (s.at(i) - 'A' + n) % 26 + 'A'; }
cout << s << endl;
return 0;
}
| replace | 31 | 32 | 31 | 32 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 0) >= this->size() (which is 0)
|
p02848 | C++ | Runtime Error | #include <iostream>
#include <string.h>
using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int main(void) {
int N;
cin >> N;
char s[32];
cin >> s;
int len = strlen(s);
for (int i = 0; i < len; i++) {
s[i] = ((s[i] - 'A' + N) % 26) + 'A';
}
cout << s << endl;
return 0;
}
| #include <iostream>
#include <string.h>
using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int main(void) {
int N;
cin >> N;
char s[10010];
cin >> s;
int len = strlen(s);
for (int i = 0; i < len; i++) {
s[i] = ((s[i] - 'A' + N) % 26) + 'A';
}
cout << s << endl;
return 0;
}
| replace | 27 | 28 | 27 | 28 | 0 | |
p02848 | C++ | Runtime Error | #include <iostream>
#include <string.h>
using namespace std;
int main() {
int N, i, len;
char S[100];
cin >> N;
cin >> S;
len = strlen(S);
for (i = 0; i < len; i++) {
S[i] += N;
if (S[i] > 'Z')
S[i] -= 26;
}
cout << S << endl;
return 0;
}
| #include <iostream>
#include <string.h>
using namespace std;
int main() {
int N, i, len;
char S[10000];
cin >> N;
cin >> S;
len = strlen(S);
for (i = 0; i < len; i++) {
S[i] += N;
if (S[i] > 'Z')
S[i] -= 26;
}
cout << S << endl;
return 0;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p02848 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define se second
#define mp make_pair
#define fi first
#define del(a, vec) \
vec.erase(std::remove(vec.begin(), vec.end(), a), vec.end());
#define search(f, l, v) binary_search(f, l, v)
#define iter(a, b) vector<int>::iterator a, b
#define lower(v, num) lower_bound(v.begin(), v.end(), num);
#define upper(v, num) upper_bound(v.begin(), v.end(), num);
#define removecopy(a) unique(a.begin(), a.end());
#define ll long long int
namespace Rahul {
bool isPrime(int n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
ll pow(ll x, ll n, ll mod) { // calculate x^n
if (n == 0)
return 1;
ll res = pow(x, n / 2, mod);
res = (res * res) % mod;
if (n % 2)
res = (res * x) % mod;
return res;
}
ll _gcd(ll a, ll b) {
if (a == 0)
return b;
else
return _gcd(b % a, a);
}
// s.erase(s.find(2)) where s={1,2,3,3,2};
}; // namespace Rahul
using namespace Rahul;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
string s;
cin >> s;
unordered_map<char, char> cn;
for (char i = 'A'; i < 'Z'; i++) {
cn[i] = i + 1;
}
cn['Z'] = 'A';
for (int i = 0; i < s.size(); i++) {
int o = n - 1;
char c = cn[s[i]];
while (o--) {
c = cn[c];
}
cout << c;
}
}
| #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define se second
#define mp make_pair
#define fi first
#define del(a, vec) \
vec.erase(std::remove(vec.begin(), vec.end(), a), vec.end());
#define search(f, l, v) binary_search(f, l, v)
#define iter(a, b) vector<int>::iterator a, b
#define lower(v, num) lower_bound(v.begin(), v.end(), num);
#define upper(v, num) upper_bound(v.begin(), v.end(), num);
#define removecopy(a) unique(a.begin(), a.end());
#define ll long long int
namespace Rahul {
bool isPrime(int n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
ll pow(ll x, ll n, ll mod) { // calculate x^n
if (n == 0)
return 1;
ll res = pow(x, n / 2, mod);
res = (res * res) % mod;
if (n % 2)
res = (res * x) % mod;
return res;
}
ll _gcd(ll a, ll b) {
if (a == 0)
return b;
else
return _gcd(b % a, a);
}
// s.erase(s.find(2)) where s={1,2,3,3,2};
}; // namespace Rahul
using namespace Rahul;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
string s;
cin >> s;
unordered_map<char, char> cn;
for (char i = 'A'; i < 'Z'; i++) {
cn[i] = i + 1;
}
cn['Z'] = 'A';
for (int i = 0; i < s.size(); i++) {
int o = n;
char c = s[i];
while (o--) {
c = cn[c];
}
cout << c;
}
}
| replace | 66 | 68 | 66 | 68 | TLE | |
p02848 | C++ | Runtime Error | #include <stdio.h>
#include <string.h>
int main() {
int n;
char s[1000];
scanf("%d\n %s", &n, s);
int len = strlen(s);
for (int i = 0; len > i; i++) {
int x = s[i] - 'A';
x = (x + n) % 26;
putchar('A' + x);
}
putchar('\n');
} | #include <stdio.h>
#include <string.h>
int main() {
int n;
char s[10000];
scanf("%d\n %s", &n, s);
int len = strlen(s);
for (int i = 0; len > i; i++) {
int x = s[i] - 'A';
x = (x + n) % 26;
putchar('A' + x);
}
putchar('\n');
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02848 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pair<ll, ll>> vpl;
typedef vector<vl> vvl;
typedef vector<vs> vvs;
#define f(i, start, end) for (i = start; i < end; i++)
#define trav(v) for (auto &x : v)
#define deb(x) cerr << #x << ":" << x << "\n"
#define nl cout << "\n"
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(0);
ll t = 1;
// cin >> t;
while (t--) {
ll n, i;
str s;
cin >> n;
cin >> s;
f(i, 0, s.size()) {
if (s[i] + n > 'Z')
s[i] = 'A' + (s[i] + n - 1) % 'Z';
else
s[i] += n;
}
cout << s;
nl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pair<ll, ll>> vpl;
typedef vector<vl> vvl;
typedef vector<vs> vvs;
#define f(i, start, end) for (i = start; i < end; i++)
#define trav(v) for (auto &x : v)
#define deb(x) cerr << #x << ":" << x << "\n"
#define nl cout << "\n"
int main() {
ios::sync_with_stdio(0);
ll t = 1;
// cin >> t;
while (t--) {
ll n, i;
str s;
cin >> n;
cin >> s;
f(i, 0, s.size()) {
if (s[i] + n > 'Z')
s[i] = 'A' + (s[i] + n - 1) % 'Z';
else
s[i] += n;
}
cout << s;
nl;
}
return 0;
} | replace | 19 | 23 | 19 | 20 | 0 | |
p02848 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int main() {
int a;
char b[1000];
scanf("%d", &a);
scanf("%s", b);
int lena = strlen(b);
for (int i = 0; i < lena; i++) {
int e = (int)(b[i]);
// printf("%d",e);
if ((e + a) > 90)
printf("%c", e + a - 90 + 64);
else
printf("%c", e + a);
}
return 0;
}
| #include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int main() {
int a;
char b[10000000];
scanf("%d", &a);
scanf("%s", b);
int lena = strlen(b);
for (int i = 0; i < lena; i++) {
int e = (int)(b[i]);
// printf("%d",e);
if ((e + a) > 90)
printf("%c", e + a - 90 + 64);
else
printf("%c", e + a);
}
return 0;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p02848 | C++ | Runtime Error | #include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#include <vector>
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define LONG_LONG_MAX 9223372036854775807LL
#define pblank putchar(' ')
#define ll LL
#define fastIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> P;
int n, m, k;
const int maxn = 1e5 + 10;
template <class T> inline T read() {
int f = 1;
T ret = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
ret = (ret << 1) + (ret << 3) + ch - '0';
ch = getchar();
}
ret *= f;
return ret;
}
template <class T> inline void write(T n) {
if (n < 0) {
putchar('-');
n = -n;
}
if (n >= 10) {
write(n / 10);
}
putchar(n % 10 + '0');
}
template <class T> inline void writeln(const T &n) {
write(n);
puts("");
}
template <typename T> void _write(const T &t) { write(t); }
template <typename T, typename... Args> void _write(const T &t, Args... args) {
write(t), pblank;
_write(args...);
}
template <typename T, typename... Args>
inline void write_line(const T &t, const Args &...data) {
_write(t, data...);
puts("");
}
int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
fastIO;
string s;
cin >> n >> s;
for (int i = 0; i < s.size(); i++)
s[i] = (s[i] - 'A' + n) % 26 + 'A';
cout << s;
return 0;
} | #include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#include <vector>
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define LONG_LONG_MAX 9223372036854775807LL
#define pblank putchar(' ')
#define ll LL
#define fastIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> P;
int n, m, k;
const int maxn = 1e5 + 10;
template <class T> inline T read() {
int f = 1;
T ret = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
ret = (ret << 1) + (ret << 3) + ch - '0';
ch = getchar();
}
ret *= f;
return ret;
}
template <class T> inline void write(T n) {
if (n < 0) {
putchar('-');
n = -n;
}
if (n >= 10) {
write(n / 10);
}
putchar(n % 10 + '0');
}
template <class T> inline void writeln(const T &n) {
write(n);
puts("");
}
template <typename T> void _write(const T &t) { write(t); }
template <typename T, typename... Args> void _write(const T &t, Args... args) {
write(t), pblank;
_write(args...);
}
template <typename T, typename... Args>
inline void write_line(const T &t, const Args &...data) {
_write(t, data...);
puts("");
}
int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
fastIO;
string s;
cin >> n >> s;
for (int i = 0; i < s.size(); i++)
s[i] = (s[i] - 'A' + n) % 26 + 'A';
cout << s;
return 0;
} | replace | 72 | 74 | 72 | 74 | 0 | |
p02848 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
using namespace std;
int mojisu(char s[]) {
int i = 0;
while (s[i]) {
i++;
}
return i;
}
int main() {
char s[26];
int n;
cin >> n;
cin >> s;
for (int i = 0; i < mojisu(s); i++) {
if (s[i] + n <= 'Z') {
s[i] = s[i] + n;
} else {
s[i] = s[i] + n - 'Z' + 'A' - 1;
}
}
cout << s << endl;
}
| #include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
using namespace std;
int mojisu(char s[]) {
int i = 0;
while (s[i]) {
i++;
}
return i;
}
int main() {
char s[10000];
int n;
cin >> n;
cin >> s;
for (int i = 0; i < mojisu(s); i++) {
if (s[i] + n <= 'Z') {
s[i] = s[i] + n;
} else {
s[i] = s[i] + n - 'Z' + 'A' - 1;
}
}
cout << s << endl;
}
| replace | 19 | 20 | 19 | 20 | 0 | |
p02848 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
char S[1000];
int N, dem;
scanf("%d%s", &N, &S);
dem = strlen(S);
for (int i = 0; i < dem; i++) {
if ((int)S[i] + N > 90)
printf("%c", S[i] + N - 26);
else
printf("%c", S[i] + N);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
char S[10001];
int N, dem;
scanf("%d%s", &N, &S);
dem = strlen(S);
for (int i = 0; i < dem; i++) {
if ((int)S[i] + N > 90)
printf("%c", S[i] + N - 26);
else
printf("%c", S[i] + N);
}
return 0;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p02848 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string S;
cin >> S;
for (int i = 0; i < S.size(); i++) {
for (int j = 0; j < 26; j++) {
if (alphabet.at(i) == S.at(j)) {
cout << alphabet.at((j + N) % 26);
}
}
}
cout << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string S;
cin >> S;
for (int i = 0; i < S.size(); i++) {
for (int j = 0; j < 26; j++) {
if (alphabet.at(j) == S.at(i)) {
cout << alphabet.at((j + N) % 26);
}
}
}
cout << endl;
}
| replace | 12 | 13 | 12 | 13 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 6) >= this->size() (which is 6)
|
p02848 | C++ | Runtime Error | #include <stdio.h>
int main() {
int n;
scanf("%d", &n);
char str[1002];
scanf("%s", str);
for (int i = 0; str[i] != '\0'; i++) {
int temp = n;
if (str[i] + n > 'Z') {
temp = temp - ('Z' - str[i]);
str[i] = 'A' + (temp - 1);
} else {
str[i] = str[i] + n;
}
}
printf("%s", str);
return 0;
} | #include <stdio.h>
int main() {
int n;
scanf("%d", &n);
char str[10002];
scanf("%s", str);
for (int i = 0; str[i] != '\0'; i++) {
int temp = n;
if (str[i] + n > 'Z') {
temp = temp - ('Z' - str[i]);
str[i] = 'A' + (temp - 1);
} else {
str[i] = str[i] + n;
}
}
printf("%s", str);
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02848 | C++ | Runtime Error | #include <stdio.h>
#include <string.h>
int main() {
int n;
char str[1005];
scanf("%d", &n);
scanf("%s", str);
int len = strlen(str);
for (int i = 0; i < len; i++) {
if (str[i] + n > 'Z') {
str[i] -= 26 - n;
} else {
str[i] += n;
}
}
printf("%s", str);
return 0;
} | #include <stdio.h>
#include <string.h>
int main() {
int n;
char str[100005];
scanf("%d", &n);
scanf("%s", str);
int len = strlen(str);
for (int i = 0; i < len; i++) {
if (str[i] + n > 'Z') {
str[i] -= 26 - n;
} else {
str[i] += n;
}
}
printf("%s", str);
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02848 | C++ | Runtime Error | #include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()
#define DEBUG_INT(var) printf("the value of " #var " is %d\n", var)
#define PRINT_ARRAY(name, i) \
printf("the value of " #name "[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)
#define pr_arr(name, a, b) \
for (int i = (a); i < (b); i++) { \
for (int j = (a); j < (b); j++) { \
if (j > (a)) \
printf(" "); \
printf("%lld", name[i][j]); \
} \
printf("\n"); \
}
#define YES puts("YES")
#define NO puts("NO")
#define Yes puts("Yes")
#define No puts("No")
using namespace std;
typedef long long ll;
int ans, N;
char S[28];
int main(void) {
scanf("%d", &N);
scanf("%s", S);
rep(i, 0, strlen(S)) {
int t = S[i] - 'A';
t = (t + N) % 26;
S[i] = t + 'A';
}
printf("%s\n", S);
return 0;
}
| #include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()
#define DEBUG_INT(var) printf("the value of " #var " is %d\n", var)
#define PRINT_ARRAY(name, i) \
printf("the value of " #name "[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)
#define pr_arr(name, a, b) \
for (int i = (a); i < (b); i++) { \
for (int j = (a); j < (b); j++) { \
if (j > (a)) \
printf(" "); \
printf("%lld", name[i][j]); \
} \
printf("\n"); \
}
#define YES puts("YES")
#define NO puts("NO")
#define Yes puts("Yes")
#define No puts("No")
using namespace std;
typedef long long ll;
int ans, N;
char S[100005];
int main(void) {
scanf("%d", &N);
scanf("%s", S);
rep(i, 0, strlen(S)) {
int t = S[i] - 'A';
t = (t + N) % 26;
S[i] = t + 'A';
}
printf("%s\n", S);
return 0;
}
| replace | 36 | 37 | 36 | 37 | 0 | |
p02848 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
string a;
for (int i = 0; i < 10000; i++) {
cin >> a[i];
a[i] = a[i] + n;
if (a[i] > 90)
a[i] -= 26;
cout << a[i];
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
string a;
cin >> a;
for (int i = 0; i < a.size(); i++) {
a[i] = a[i] + n;
if (a[i] > 90)
a[i] -= 26;
cout << a[i];
}
return 0;
} | replace | 6 | 8 | 6 | 9 | -11 | |
p02848 | C++ | Time Limit Exceeded | #include <iostream>
#include <string>
using namespace std;
int n;
string s;
int c(char ch, int a) {
if (a == 1) {
if (ch == 'Z')
return 'A';
return ch + 1;
}
return c(c(ch, 1), a - 1);
}
int main() {
cin >> n >> s;
for (int i = 0; i < s.size(); ++i) {
s[i] = c(s[i], n);
cout << s[i];
}
return 0;
} | #include <iostream>
#include <string>
using namespace std;
int n;
string s;
int c(char ch, int a) {
if (a == 1) {
if (ch == 'Z')
return 'A';
return ch + 1;
}
if (a == 0)
return ch;
return c(c(ch, 1), a - 1);
}
int main() {
cin >> n >> s;
for (int i = 0; i < s.size(); ++i) {
s[i] = c(s[i], n);
cout << s[i];
}
return 0;
}
| insert | 12 | 12 | 12 | 14 | TLE | |
p02848 | C++ | Runtime Error | #include <stdio.h>
int main() {
char s[50];
int n, c = 0, m;
scanf("%d", &n);
scanf("%s", s);
while (1) {
if (s[c] == '\0') {
break;
}
c++;
}
for (int i = 0; i < c; i++) {
m = (int)(s[i] + n);
if (m <= 90) {
printf("%c", s[i] + n);
} else {
printf("%c", 64 + (m - 90));
}
}
return 0;
}
| #include <stdio.h>
int main() {
char s[100000];
int n, c = 0, m;
scanf("%d", &n);
scanf("%s", s);
while (1) {
if (s[c] == '\0') {
break;
}
c++;
}
for (int i = 0; i < c; i++) {
m = (int)(s[i] + n);
if (m <= 90) {
printf("%c", s[i] + n);
} else {
printf("%c", 64 + (m - 90));
}
}
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02848 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
char c[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", s[1024];
int main() {
int i, n;
scanf("%d", &n);
scanf("%s", s);
for (i = 0; i < strlen(s); i++) {
printf("%c", c[(s[i] - 'A' + n) % 26]);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
char c[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", s[10010];
int main() {
int i, n;
scanf("%d", &n);
scanf("%s", s);
for (i = 0; i < strlen(s); i++) {
printf("%c", c[(s[i] - 'A' + n) % 26]);
}
return 0;
} | replace | 2 | 3 | 2 | 3 | 0 | |
p02848 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
for (int i = 0; i < s.size(); i++) {
s.at(i) += n;
if (s.at(i) > 90) {
s.at(i) = s.at(i % 90 + 65);
}
}
cout << s << endl;
return 0;
} | #include <iostream>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
for (int i = 0; i < s.size(); i++) {
s.at(i) += n;
if (s.at(i) > 90) {
s.at(i) = (char)s.at(i) % 90 + 64;
}
}
cout << s << endl;
return 0;
} | replace | 11 | 12 | 11 | 12 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 69) >= this->size() (which is 6)
|
p02848 | Python | Runtime Error | N = int(input())
S = input()
ans = ""
a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i in range(len(S)):
if a.index(S[i]) + N > 26:
ans += a[a.index(S[i]) + N - 26]
else:
ans += a[a.index(S[i]) + N]
print(ans)
| N = int(input())
S = input()
ans = ""
a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i in range(len(S)):
if a.index(S[i]) + N > 25:
ans += a[a.index(S[i]) + N - 26]
else:
ans += a[a.index(S[i]) + N]
print(ans)
| replace | 6 | 7 | 6 | 7 | IndexError: string index out of range | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02848/Python/s484935538.py", line 10, in <module>
ans += a[a.index(S[i]) + N]
IndexError: string index out of range
|
p02848 | Python | Runtime Error | def solve(n: int, s: str) -> str:
def inc(c: str, n: int) -> str:
tbl = {
0: "A",
1: "B",
2: "C",
3: "D",
4: "E",
5: "F",
6: "G",
7: "H",
8: "I",
9: "J",
10: "K",
11: "L",
12: "M",
13: "N",
14: "O",
15: "P",
16: "Q",
17: "R",
18: "S",
19: "T",
20: "U",
21: "V",
23: "W",
24: "X",
25: "Y",
26: "Z",
}
rev_tbl = {v: k for k, v in tbl.items()}
idx = (rev_tbl[c] + n) % len(tbl)
return tbl[idx]
return "".join([inc(c, n) for c in s])
n = int(input().strip())
s = input().strip()
print(solve(n, s))
| def solve(n: int, s: str) -> str:
def inc(c: str, n: int) -> str:
tbl = {
0: "A",
1: "B",
2: "C",
3: "D",
4: "E",
5: "F",
6: "G",
7: "H",
8: "I",
9: "J",
10: "K",
11: "L",
12: "M",
13: "N",
14: "O",
15: "P",
16: "Q",
17: "R",
18: "S",
19: "T",
20: "U",
21: "V",
22: "W",
23: "X",
24: "Y",
25: "Z",
}
rev_tbl = {v: k for k, v in tbl.items()}
idx = (rev_tbl[c] + n) % len(tbl)
return tbl[idx]
return "".join([inc(c, n) for c in s])
n = int(input().strip())
s = input().strip()
print(solve(n, s))
| replace | 25 | 29 | 25 | 29 | 0 | |
p02848 | Python | Runtime Error | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
from EmurateInput import input
N, S = int(input()), input()
def rot_encode(n):
from string import ascii_lowercase as lc, ascii_uppercase as uc
lookup = str.maketrans(lc + uc, lc[n:] + lc[:n] + uc[n:] + uc[:n])
return lambda s: s.translate(lookup)
print(rot_encode(N)(S))
| N, S = int(input()), input()
def rot_encode(n):
from string import ascii_lowercase as lc, ascii_uppercase as uc
lookup = str.maketrans(lc + uc, lc[n:] + lc[:n] + uc[n:] + uc[:n])
return lambda s: s.translate(lookup)
print(rot_encode(N)(S))
| delete | 0 | 5 | 0 | 0 | ModuleNotFoundError: No module named 'EmurateInput' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02848/Python/s073748704.py", line 4, in <module>
from EmurateInput import input
ModuleNotFoundError: No module named 'EmurateInput'
|
p02848 | Python | Runtime Error | def main(n: int, s: str):
ans = ""
for _s in s:
ans += ascii[(ascii.index(_s) + n) % 26]
print(ans)
if __name__ == "__main__":
n = int(input())
s = input()
main(n, s)
| from string import ascii_uppercase as ascii
def main(n: int, s: str):
ans = ""
for _s in s:
ans += ascii[(ascii.index(_s) + n) % 26]
print(ans)
if __name__ == "__main__":
n = int(input())
s = input()
main(n, s)
| insert | 0 | 0 | 0 | 3 | AttributeError: 'builtin_function_or_method' object has no attribute 'index' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02848/Python/s884988719.py", line 13, in <module>
main(n, s)
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02848/Python/s884988719.py", line 4, in main
ans += ascii[(ascii.index(_s) + n) % 26]
AttributeError: 'builtin_function_or_method' object has no attribute 'index'
|
p02848 | C++ | Runtime Error | #include <cstdio>
#include <cstring>
using namespace std;
int main() {
int n, l;
char a[26], s[1010];
scanf("%d", &n);
scanf("%s", s);
l = strlen(s);
for (int i = 0; i < 26; i++) {
a[i] = 'A' + (i + n) % 26;
}
for (int i = 0; i < l; i++) {
printf("%c", a[s[i] - 'A']);
}
printf("\n");
} | #include <cstdio>
#include <cstring>
using namespace std;
int main() {
int n, l;
char a[26], s[10010];
scanf("%d", &n);
scanf("%s", s);
l = strlen(s);
for (int i = 0; i < 26; i++) {
a[i] = 'A' + (i + n) % 26;
}
for (int i = 0; i < l; i++) {
printf("%c", a[s[i] - 'A']);
}
printf("\n");
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02848 | C++ | Runtime Error | #include <stdio.h>
#include <string.h>
int main() {
int n, a, i, x = 0;
char s[26];
scanf("%d %s", &n, s);
a = strlen(s);
for (i = 0; i < a; i++) {
x = s[i] - 'A';
x = (x + n) % 26;
printf("%c", x + 'A');
}
printf("\n");
return 0;
}
| #include <stdio.h>
#include <string.h>
int main() {
int n, a, i, x = 0;
char s[10000];
scanf("%d %s", &n, s);
a = strlen(s);
for (i = 0; i < a; i++) {
x = s[i] - 'A';
x = (x + n) % 26;
printf("%c", x + 'A');
}
printf("\n");
return 0;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p02848 | C++ | Runtime Error | #define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS(v, n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a) + (size))
#define REMOVE(v, a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v, a) (reverse((v), (v) + (a)))
#define LOWER_BOUND(v, a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v, a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No"); }
void Yes() { cout << "Yes"; }
void No() { cout << "No"; }
// max_element
signed main() {
int N;
string S;
cin >> N;
cin >> S;
char ch[100] = {};
for (int i = 0; i < S.length(); i++) {
int a = S[i] - 'A';
a = (a + N) % 26;
ch[i] = a + 'A';
}
cout << ch << endl;
}
| #define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS(v, n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a) + (size))
#define REMOVE(v, a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v, a) (reverse((v), (v) + (a)))
#define LOWER_BOUND(v, a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v, a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No"); }
void Yes() { cout << "Yes"; }
void No() { cout << "No"; }
// max_element
signed main() {
int N;
string S;
cin >> N;
cin >> S;
char ch[11000] = {};
for (int i = 0; i < S.length(); i++) {
int a = S[i] - 'A';
a = (a + N) % 26;
ch[i] = a + 'A';
}
cout << ch << endl;
}
| replace | 46 | 47 | 46 | 47 | 0 | |
p02848 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<P>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
ll n;
cin >> n;
string s;
cin >> s;
ll ss = s.size();
vector<ll> num(n);
rep(i, ss) { num[i] = (ll)(s[i] - 'A'); }
rep(i, ss) { cout << (char)('A' + ((num[i] + n) % 26)); }
cout << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<P>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
ll n;
cin >> n;
string s;
cin >> s;
ll ss = s.size();
vector<ll> num(ss);
rep(i, ss) { num[i] = (ll)(s[i] - 'A'); }
rep(i, ss) { cout << (char)('A' + ((num[i] + n) % 26)); }
cout << endl;
return 0;
} | replace | 32 | 33 | 32 | 33 | -6 | Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
|
p02848 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string MOMI = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
int N;
cin >> N;
string S;
cin >> S;
for (int i = 0; i < S.size(); i++) {
for (int j = 0; j < 27; j++) {
if (S.at(i) == MOMI.at(j)) {
S.at(i) = MOMI.at(j + N);
}
}
}
cout << S << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string MOMI = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
int N;
cin >> N;
string S;
cin >> S;
for (int i = 0; i < S.size(); i++) {
for (int j = 0; j < 27; j++) {
if (S.at(i) == MOMI.at(j)) {
S.at(i) = MOMI.at(j + N);
break;
}
}
}
cout << S << endl;
return 0;
}
| insert | 13 | 13 | 13 | 14 | 0 | |
p02848 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
char s[100001];
cin >> n >> s;
int q = strlen(s);
for (int i = 0; i < n; i++) {
for (int j = 0; j < q; i++) {
if (s[j] == 'Z') {
s[j] = 'A';
} else {
s[j]++;
}
}
}
cout << s << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
char s[100001];
cin >> n >> s;
int q = strlen(s);
for (int i = 0; i < n; i++) {
for (int j = 0; j < q; j++) {
if (s[j] == 'Z') {
s[j] = 'A';
} else {
s[j]++;
}
}
}
cout << s << endl;
} | replace | 8 | 9 | 8 | 9 | TLE | |
p02848 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, i = 0;
char s[100];
string rot;
rot = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
cin >> n >> s;
while (s[i] != '\0') {
s[i] = rot[s[i] - 'A' + n];
i++;
}
cout << s << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, i = 0;
char s[100000];
string rot;
rot = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
cin >> n >> s;
while (s[i] != '\0') {
s[i] = rot[s[i] - 'A' + n];
i++;
}
cout << s << endl;
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02848 | C++ | Runtime Error | #include <algorithm>
#include <stdio.h>
#include <string.h>
#include <vector>
typedef long long ll;
using namespace std;
char S[10];
int main() {
int c;
scanf("%d%s", &c, S);
int len = strlen(S);
for (int i = 0; i < len; i++) {
int x = (S[i] - 'A' + c) % 26;
S[i] = x + 'A';
}
printf("%s", S);
return 0;
} | #include <algorithm>
#include <stdio.h>
#include <string.h>
#include <vector>
typedef long long ll;
using namespace std;
char S[10010];
int main() {
int c;
scanf("%d%s", &c, S);
int len = strlen(S);
for (int i = 0; i < len; i++) {
int x = (S[i] - 'A' + c) % 26;
S[i] = x + 'A';
}
printf("%s", S);
return 0;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p02848 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
#define MOD 1000000007
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < s.length(); i++) {
s[i] = (s[i] - 65 + n) % 26 + 65;
}
cout << s;
} | #include <bits/stdc++.h>
#define int long long
#define MOD 1000000007
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < s.length(); i++) {
s[i] = (s[i] - 65 + n) % 26 + 65;
}
cout << s;
} | delete | 7 | 11 | 7 | 7 | 0 | |
p02848 | C++ | Runtime Error | #include <stdio.h>
#include <string.h>
int main() {
char s[101];
int N, i, j;
scanf("%d", &N);
scanf("%s", s);
j = strlen(s);
for (i = 0; i < j; i++) {
if (s[i] + N > 'Z')
s[i] = s[i] + N - 26;
else
s[i] = s[i] + N;
}
printf("%s", s);
return 0;
}
| #include <stdio.h>
#include <string.h>
int main() {
char s[15000];
int N, i, j;
scanf("%d", &N);
scanf("%s", s);
j = strlen(s);
for (i = 0; i < j; i++) {
if (s[i] + N > 'Z')
s[i] = s[i] + N - 26;
else
s[i] = s[i] + N;
}
printf("%s", s);
return 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p02848 | 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>;
int main() {
int n;
cin >> n;
string s;
rep(i, n) s[i] = s[i] + '0' + n;
cout << s << 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 p = pair<int, int>;
int main() {
int n;
cin >> n;
string s;
cin >> s;
rep(i, s.size()) { s[i] = (s[i] + 'A' + n) % 26 + 'A'; }
cout << s << endl;
return 0;
}
| replace | 10 | 12 | 10 | 12 | 0 | |
p02848 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string S;
int key = 0;
int t = 0;
cin >> N >> S;
string base;
base = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (int i = 0; i < 26; i++) {
if (S.at(t) == base.at(i)) {
key = i;
t++;
cout << base.at(key + N);
i = 0;
}
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string S;
int key = 0;
int t = 0;
cin >> N >> S;
string base;
base = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (int t = 0; t < S.size(); t++) {
for (int i = 0; i < 26; i++) {
if (S.at(t) == base.at(i)) {
key = i;
cout << base.at(key + N);
}
}
}
}
| replace | 13 | 20 | 13 | 19 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 6) >= this->size() (which is 6)
|
p02848 | C++ | Runtime Error | #include <algorithm>
#include <stack>
#include <stdio.h>
#include <string.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
char a[1000];
scanf("%s", a);
int m;
m = strlen(a);
for (int i = 0; i < m; i++) {
if (a[i] + n <= 'Z')
printf("%c", a[i] + n);
else
printf("%c", a[i] + n - 26);
}
} | #include <algorithm>
#include <stack>
#include <stdio.h>
#include <string.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
char a[100000];
scanf("%s", a);
int m;
m = strlen(a);
for (int i = 0; i < m; i++) {
if (a[i] + n <= 'Z')
printf("%c", a[i] + n);
else
printf("%c", a[i] + n - 26);
}
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02848 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
char a[30];
int n, lenc;
char c[1004];
int main() {
for (int i = 0; i < 26; i++) {
a[i] = i + 65;
}
cin >> n;
cin >> c;
lenc = strlen(c);
for (int i = 0; i < lenc; i++) {
cout << a[(c[i] - 65 + n) % 26];
}
cout << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
char a[30];
int n, lenc;
char c[10004];
int main() {
for (int i = 0; i < 26; i++) {
a[i] = i + 65;
}
cin >> n;
cin >> c;
lenc = strlen(c);
for (int i = 0; i < lenc; i++) {
cout << a[(c[i] - 65 + n) % 26];
}
cout << endl;
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02848 | C++ | Runtime Error | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(a) (a).begin(), (a).end()
typedef pair<int, int> P;
typedef long long ll;
int main() {
int n;
char s[10010];
string S;
cin >> n >> S;
rep(i, n) {
s[i] = S[i];
int x = s[i] - 'A';
x = (x + n) % 26;
char ans = 'A' + x;
cout << ans;
}
cout << endl;
return 0;
} | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(a) (a).begin(), (a).end()
typedef pair<int, int> P;
typedef long long ll;
int main() {
int n;
char s[10010];
string S;
cin >> n >> S;
rep(i, S.size()) {
s[i] = S[i];
int x = s[i] - 'A';
x = (x + n) % 26;
char ans = 'A' + x;
cout << ans;
}
cout << endl;
return 0;
} | replace | 15 | 16 | 15 | 16 | 0 | |
p02848 | C++ | Runtime Error | /*
Author: Satya R Samal, NIT Sringar
"Everything in this world is magic, except to the magician"
*/
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define faster ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
faster;
int n;
string s;
cin >> n >> s;
string ans = "";
for (int i = 0; i < s.size(); i++) {
ans += 'A' + (s[i] - 'A' + n) % 26;
}
cout << ans << endl;
}
| /*
Author: Satya R Samal, NIT Sringar
"Everything in this world is magic, except to the magician"
*/
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define faster ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
string ans = "";
for (int i = 0; i < s.size(); i++) {
ans += 'A' + (s[i] - 'A' + n) % 26;
}
cout << ans << endl;
}
| delete | 13 | 18 | 13 | 13 | 0 | |
p02848 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string S;
cin >> N >> S;
for (int i = 0; i < N; i++) {
S.at(i) = char((S.at(i) - 65 + N) % 26 + 65);
}
cout << S << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string S;
cin >> N >> S;
for (int i = 0; i < S.size(); i++) {
S.at(i) = char((S.at(i) - 65 + N) % 26 + 65);
}
cout << S << endl;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p02848 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
// 整数の入力
int n;
cin >> n;
// 文字列の入力
char s[1000];
cin >> s;
for (int i = 0; s[i] != 0x00; i++) {
s[i] += n;
if (s[i] > 0x5a)
s[i] -= 26;
}
cout << string(s) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
// 整数の入力
int n;
cin >> n;
// 文字列の入力
char s[100000];
cin >> s;
for (int i = 0; s[i] != 0x00; i++) {
s[i] += n;
if (s[i] > 0x5a)
s[i] -= 26;
}
cout << string(s) << endl;
return 0;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02848 | C++ | Runtime Error | #include <stdio.h>
int main() {
int n;
scanf("%d", &n);
char s[2000];
scanf("%s", s);
for (int i = 0; s[i] != '\0'; i++) {
int oldChar = s[i] - 'A';
int newChar = (oldChar + n) % 26;
printf("%c", newChar + 'A');
}
printf("\n");
}
| #include <stdio.h>
int main() {
int n;
scanf("%d", &n);
char s[10000];
scanf("%s", s);
for (int i = 0; s[i] != '\0'; i++) {
int oldChar = s[i] - 'A';
int newChar = (oldChar + n) % 26;
printf("%c", newChar + 'A');
}
printf("\n");
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02848 | C++ | Runtime Error | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, N) for (int i = 0; i < (int)(N); i++)
int main() {
int n;
cin >> n;
string s;
cin >> s;
rep(i, n) s[i] += n;
cout << s << endl;
}
| #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, N) for (int i = 0; i < (int)(N); i++)
int main() {
int n;
cin >> n;
string s;
cin >> s;
rep(i, s.size()) { s[i] = (s[i] - 'A' + n) % 26 + 'A'; }
cout << s << endl;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p02848 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
int main() {
int i, n, value;
char c;
char b[27];
cin >> n;
cin >> b;
for (i = 0; b[i] != '\0'; i++) {
if (n == 0)
printf("%c", b[i]);
else if (b[i] + n > 90) {
printf("%c", 64 + (b[i] + n - 90));
} else
printf("%c", b[i] + n);
}
}
| #include "bits/stdc++.h"
using namespace std;
int main() {
int i, n, value;
char c;
char b[99999];
cin >> n;
cin >> b;
for (i = 0; b[i] != '\0'; i++) {
if (n == 0)
printf("%c", b[i]);
else if (b[i] + n > 90) {
printf("%c", 64 + (b[i] + n - 90));
} else
printf("%c", b[i] + n);
}
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p02848 | C++ | Runtime Error | #include <stdio.h>
#include <string.h>
char a[110];
int n;
int len;
int main(void) {
scanf("%d", &n);
scanf("%s", a);
len = strlen(a);
for (int i = 0; i < len; i++) {
a[i] += n;
if (a[i] > 'Z')
a[i] -= 26;
printf("%c", a[i]);
}
return 0;
} | #include <stdio.h>
#include <string.h>
char a[10010];
int n;
int len;
int main(void) {
scanf("%d", &n);
scanf("%s", a);
len = strlen(a);
for (int i = 0; i < len; i++) {
a[i] += n;
if (a[i] > 'Z')
a[i] -= 26;
printf("%c", a[i]);
}
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02848 | C++ | Runtime Error | #include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n, m;
int main() {
char s[100];
int i, j, k;
cin >> n;
cin >> s;
for (i = 0; i < strlen(s); ++i) {
int x = s[i] + n;
if (x > 'Z')
x -= 26;
s[i] = x;
}
cout << s << endl;
return 0;
} | #include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n, m;
int main() {
char s[100010];
int i, j, k;
cin >> n;
cin >> s;
for (i = 0; i < strlen(s); ++i) {
int x = s[i] + n;
if (x > 'Z')
x -= 26;
s[i] = x;
}
cout << s << endl;
return 0;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p02848 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
char s[1005] = {};
cin >> n >> s;
int lung = strlen(s);
for (int i = 0; i < lung; ++i) {
s[i] = s[i] + n;
if (s[i] > 'Z')
s[i] = 'A' + s[i] - 'Z' - 1;
}
cout << s;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
char s[10001] = {};
cin >> n >> s;
int lung = strlen(s);
for (int i = 0; i < lung; ++i) {
s[i] = s[i] + n;
if (s[i] > 'Z')
s[i] = 'A' + s[i] - 'Z' - 1;
}
cout << s;
return 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02848 | C++ | Runtime Error | /*
我的心脏怦怦跳,监管者就在附近
*/
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <unistd.h>
#define random(a, b) (rand() % (b - a + 1) + a)
using namespace std;
bool prime(int x) {
int i;
if (x < 2)
return 0;
for (i = 2; i * i <= x; i++) {
if (x % i == 0) {
return 0;
}
}
return 1;
}
int a[1001];
int main() {
int x;
cin >> x;
string st;
cin >> st;
int i;
for (i = 0; i < st.size(); ++i) {
a[i] = st[i] - 65;
a[i] += x;
a[i] %= 26;
a[i] += 65;
}
for (i = 0; i < st.size(); ++i) {
cout << char(a[i]);
}
return 0;
}
| /*
我的心脏怦怦跳,监管者就在附近
*/
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <unistd.h>
#define random(a, b) (rand() % (b - a + 1) + a)
using namespace std;
bool prime(int x) {
int i;
if (x < 2)
return 0;
for (i = 2; i * i <= x; i++) {
if (x % i == 0) {
return 0;
}
}
return 1;
}
int a[10005];
int main() {
int x;
cin >> x;
string st;
cin >> st;
int i;
for (i = 0; i < st.size(); ++i) {
a[i] = st[i] - 65;
a[i] += x;
a[i] %= 26;
a[i] += 65;
}
for (i = 0; i < st.size(); ++i) {
cout << char(a[i]);
}
return 0;
}
| replace | 27 | 28 | 27 | 28 | 0 | |
p02848 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
//
int num;
string str;
vector<string> vec(26);
vec = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
cin >> num >> str;
for (int i = 0; i < str.size(); i++) {
int tmp = str.at(i) - 'A';
if (tmp < 24)
cout << vec.at(tmp + num);
else
cout << vec.at((tmp + num) - 26);
}
//
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
//
int num;
string str;
vector<string> vec(26);
vec = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
cin >> num >> str;
for (int i = 0; i < str.size(); i++) {
int tmp = str.at(i) - 'A';
if (tmp + num < 26)
cout << vec.at(tmp + num);
else
cout << vec.at((tmp + num) - 26);
}
//
}
| replace | 15 | 16 | 15 | 16 | 0 | |
p02848 | C++ | Runtime Error | #include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < sizeof(s); i++) {
s[i] = s[i] + n;
if (s[i] > 'Z') {
s[i] = 64 + (s[i] - 'Z');
}
}
cout << s << endl;
return 0;
}
| #include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
s[i] = s[i] + n;
if (s[i] > 'Z') {
s[i] = 64 + (s[i] - 'Z');
}
}
cout << s << endl;
return 0;
}
| replace | 13 | 14 | 13 | 14 | -6 | *** stack smashing detected ***: terminated
|
p02848 | C++ | Runtime Error | // #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ld long double
#define P pair<ll, ll>
#define FOR(i, n, m) for (ll i = n; i < (ll)m; i++)
#define FORr(i, m, n) for (ll i = n; i >= (ll)m; i--)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define sortAl(v) sort(v.begin(), v.end())
#define sortAlr(v) \
sort(v.begin(), v.end()); \
reverse(v.begin(), v.end())
#define cout(n) cout << fixed << setprecision(n)
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
string s;
cin >> s;
vector<char> v(50);
FOR(i, 0, 70) { v[i] = (i % 26 + 'A'); }
FOR(i, 0, s.size()) { cout << v[s[i] - 'A' + n]; }
cout << endl;
} | // #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ld long double
#define P pair<ll, ll>
#define FOR(i, n, m) for (ll i = n; i < (ll)m; i++)
#define FORr(i, m, n) for (ll i = n; i >= (ll)m; i--)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define sortAl(v) sort(v.begin(), v.end())
#define sortAlr(v) \
sort(v.begin(), v.end()); \
reverse(v.begin(), v.end())
#define cout(n) cout << fixed << setprecision(n)
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
string s;
cin >> s;
vector<char> v(70);
FOR(i, 0, 70) { v[i] = (i % 26 + 'A'); }
FOR(i, 0, s.size()) { cout << v[s[i] - 'A' + n]; }
cout << endl;
} | replace | 24 | 25 | 24 | 25 | 0 | |
p02848 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
char s[1001];
int n;
cin >> n;
cin >> s;
for (int i = 0; i < strlen(s); i++) {
int diff = s[i] - 'A';
putchar('A' + (diff + n) % 26);
}
putchar('\n');
} | #include <bits/stdc++.h>
using namespace std;
int main() {
char s[10010];
int n;
cin >> n;
cin >> s;
for (int i = 0; i < strlen(s); i++) {
int diff = s[i] - 'A';
putchar('A' + (diff + n) % 26);
}
putchar('\n');
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02848 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string S,
T = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y'};
cin >> S;
for (int i = 0; i < S.size(); i++) {
bool flag = true;
for (int j = 0; j < T.size(); j++) {
if (T.at(j) == S.at(i) && flag == true) {
S.at(i) = T.at(j + N);
flag = false;
}
}
}
cout << S << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string S,
T = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
cin >> S;
for (int i = 0; i < S.size(); i++) {
bool flag = true;
for (int j = 0; j < T.size(); j++) {
if (T.at(j) == S.at(i) && flag == true) {
S.at(i) = T.at(j + N);
flag = false;
}
}
}
cout << S << endl;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p02850 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
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;
}
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORR(i, a, b) for (ll i = (a); i <= (b); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define P pair<ll, ll>
#define sz(x) (ll) x.size()
#define ALL(x) (x).begin(), (x).end()
#define ALLR(x) (x).rbegin(), (x).rend()
#define VE vector<ll>
#define COUT(x) cout << (x) << endl
#define MA map<ll, ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll, VE, greater<ll>>
#define COUT(x) cout << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
if (a < b)
swap(a, b);
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return a / g * b;
}
bool prime(ll n) {
for (ll i = 2; i <= sqrt(n); i++) {
if (n % i == 0)
return false;
}
return n != 1;
}
const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int MAX_N = 100010;
bool used[MAX_N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
// グラフ
vector<VE> G(n);
vector<P> vp;
rep(i, n) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].push_back(b);
G[b].push_back(a);
vp.push_back(make_pair(a, b));
}
// 色の数
int k = 0;
vector<int> hennoiro(n); // その名の通り
map<P, int> I; // 出力用map
// 幅優先探索
queue<int> que;
used[0] = true;
que.emplace(0);
while (!que.empty()) {
int v = que.front();
que.pop();
chmax(k, (int)G[v].size());
int color = 1;
for (int u : G[v]) {
if (used[u])
continue;
if (color == hennoiro[v])
color++;
hennoiro[u] = I[make_pair(u, v)] = I[make_pair(v, u)] = color++;
used[u] = true;
que.emplace(u);
}
}
cout << k << endl;
for (auto p : vp)
cout << I[p] << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
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;
}
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORR(i, a, b) for (ll i = (a); i <= (b); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define P pair<ll, ll>
#define sz(x) (ll) x.size()
#define ALL(x) (x).begin(), (x).end()
#define ALLR(x) (x).rbegin(), (x).rend()
#define VE vector<ll>
#define COUT(x) cout << (x) << endl
#define MA map<ll, ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll, VE, greater<ll>>
#define COUT(x) cout << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
if (a < b)
swap(a, b);
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return a / g * b;
}
bool prime(ll n) {
for (ll i = 2; i <= sqrt(n); i++) {
if (n % i == 0)
return false;
}
return n != 1;
}
const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int MAX_N = 100010;
bool used[MAX_N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
// グラフ
vector<VE> G(n);
vector<P> vp;
rep(i, n - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].push_back(b);
G[b].push_back(a);
vp.push_back(make_pair(a, b));
}
// 色の数
int k = 0;
vector<int> hennoiro(n); // その名の通り
map<P, int> I; // 出力用map
// 幅優先探索
queue<int> que;
used[0] = true;
que.emplace(0);
while (!que.empty()) {
int v = que.front();
que.pop();
chmax(k, (int)G[v].size());
int color = 1;
for (int u : G[v]) {
if (used[u])
continue;
if (color == hennoiro[v])
color++;
hennoiro[u] = I[make_pair(u, v)] = I[make_pair(v, u)] = color++;
used[u] = true;
que.emplace(u);
}
}
cout << k << endl;
for (auto p : vp)
cout << I[p] << endl;
return 0;
}
| replace | 99 | 100 | 99 | 100 | 0 | |
p02850 | Python | Runtime Error | n = int(input())
ki = [[] for _ in range(n)]
for i in range(n - 1):
a, b = map(int, input().split())
a -= 1
b -= 1
ki[a].append([b, i])
ans = [-1] * (n - 1)
# print(ki)
def d(index, color):
cnt = 1
for t, jid in ki[index]:
if cnt == color:
cnt += 1
ans[jid] = cnt
d(t, cnt)
cnt += 1
d(0, 0)
print(max(ans))
for i in ans:
print(i)
| import sys
sys.setrecursionlimit(10**7)
n = int(input())
ki = [[] for _ in range(n)]
for i in range(n - 1):
a, b = map(int, input().split())
a -= 1
b -= 1
ki[a].append([b, i])
ans = [-1] * (n - 1)
# print(ki)
def d(index, color):
cnt = 1
for t, jid in ki[index]:
if cnt == color:
cnt += 1
ans[jid] = cnt
d(t, cnt)
cnt += 1
d(0, 0)
print(max(ans))
for i in ans:
print(i)
| insert | 0 | 0 | 0 | 4 | 0 | |
p02850 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template <class T> void print1d(T x, ll n = -1) {
if (n == -1)
n = x.size();
rep(i, 0, n) { cout << x[i] << ' '; }
cout << '\n';
}
template <class T> void print2d(T x, ll r = -1, ll c = -1) {
if (r == -1)
r = x.size();
if (c == -1)
c = x[0].size();
rep(i, 0, r) print1d(x[i], c);
}
template <class T, class U> bool haskey(T mp, U key) {
return mp.find(key) != mp.end();
}
template <class T, class U> bool isin(T el, U container) {
return find(all(container), el) != container.end();
}
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;
}
template <class T> bool even(T n) { return !(n & 1); }
template <class T> bool odd(T n) { return n & 1; }
template <class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template <class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a, ll n) {
ll p = 1;
while (n) {
if (n & 1)
p *= a;
a *= a;
n >>= 1;
}
return p;
}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
const long long BFSMAX = 10010; // Set
vllvll bfsGraph(BFSMAX);
vll bfsdist(BFSMAX);
vector<bool> seen(BFSMAX);
map<pll, ll> colors;
ll diff = 0;
template <class T> void bfs(T start) {
fill(bfsdist.begin(), bfsdist.end(), inf);
bfsdist[start] = 0;
fill(seen.begin(), seen.end(), false);
queue<T> q;
q.push(start);
vll prevc(BFSMAX);
while (!q.empty()) {
auto now = q.front();
q.pop();
ll c = 0;
for (auto adj : bfsGraph[now]) {
if (bfsdist[adj] == inf) {
bfsdist[adj] = bfsdist[now] + 1;
++c;
if (c == prevc[now])
++c;
colors[pll{now, adj}] = c;
q.push(adj);
prevc[adj] = c;
}
}
}
}
// Prepare for `bfsGraph`
int main() {
ll N;
cin >> N;
vll e1(N), e2(N);
rep(i, 0, N - 1) {
ll a, b;
cin >> a >> b;
bfsGraph[a].push_back(b);
bfsGraph[b].push_back(a);
e1[i] = a;
e2[i] = b;
}
bfs(1);
vll ans;
rep(i, 0, N - 1) {
ans.push_back(max(colors[pll{e1[i], e2[i]}], colors[pll{e2[i], e1[i]}]));
}
cout << *max_element(all(ans)) << endl;
rep(i, 0, N - 1) { cout << ans[i] << endl; }
}
| #include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template <class T> void print1d(T x, ll n = -1) {
if (n == -1)
n = x.size();
rep(i, 0, n) { cout << x[i] << ' '; }
cout << '\n';
}
template <class T> void print2d(T x, ll r = -1, ll c = -1) {
if (r == -1)
r = x.size();
if (c == -1)
c = x[0].size();
rep(i, 0, r) print1d(x[i], c);
}
template <class T, class U> bool haskey(T mp, U key) {
return mp.find(key) != mp.end();
}
template <class T, class U> bool isin(T el, U container) {
return find(all(container), el) != container.end();
}
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;
}
template <class T> bool even(T n) { return !(n & 1); }
template <class T> bool odd(T n) { return n & 1; }
template <class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template <class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a, ll n) {
ll p = 1;
while (n) {
if (n & 1)
p *= a;
a *= a;
n >>= 1;
}
return p;
}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
const long long BFSMAX = 101010; // Set
vllvll bfsGraph(BFSMAX);
vll bfsdist(BFSMAX);
vector<bool> seen(BFSMAX);
map<pll, ll> colors;
ll diff = 0;
template <class T> void bfs(T start) {
fill(bfsdist.begin(), bfsdist.end(), inf);
bfsdist[start] = 0;
fill(seen.begin(), seen.end(), false);
queue<T> q;
q.push(start);
vll prevc(BFSMAX);
while (!q.empty()) {
auto now = q.front();
q.pop();
ll c = 0;
for (auto adj : bfsGraph[now]) {
if (bfsdist[adj] == inf) {
bfsdist[adj] = bfsdist[now] + 1;
++c;
if (c == prevc[now])
++c;
colors[pll{now, adj}] = c;
q.push(adj);
prevc[adj] = c;
}
}
}
}
// Prepare for `bfsGraph`
int main() {
ll N;
cin >> N;
vll e1(N), e2(N);
rep(i, 0, N - 1) {
ll a, b;
cin >> a >> b;
bfsGraph[a].push_back(b);
bfsGraph[b].push_back(a);
e1[i] = a;
e2[i] = b;
}
bfs(1);
vll ans;
rep(i, 0, N - 1) {
ans.push_back(max(colors[pll{e1[i], e2[i]}], colors[pll{e2[i], e1[i]}]));
}
cout << *max_element(all(ans)) << endl;
rep(i, 0, N - 1) { cout << ans[i] << endl; }
}
| replace | 64 | 65 | 64 | 65 | 0 | |
p02850 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
struct Edge {
int to, id;
};
vector<vector<Edge>> g;
vector<int> ans;
void dfs(int v, int c = -1, int p = -1) {
int k = 1;
rep(i, g[v].size()) {
int u = g[v][i].to, ei = g[v][i].id;
if (u == p)
continue;
if (k == c)
++k;
ans[ei] = k;
++k;
dfs(u, ans[ei], v);
}
}
int main() {
int n;
cin >> n;
rep(i, n - 1) {
int a, b;
cin >> a >> b;
--a, --b;
g[a].push_back((Edge){b, i});
g[b].push_back((Edge){a, i});
}
dfs(0);
int mx = 0;
rep(i, n) mx = max(mx, int(g[i].size()));
cout << mx << endl;
rep(i, n - 1) { cout << ans[i] << endl; }
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
struct Edge {
int to, id;
};
vector<vector<Edge>> g;
vector<int> ans;
void dfs(int v, int c = -1, int p = -1) {
int k = 1;
rep(i, g[v].size()) {
int u = g[v][i].to, ei = g[v][i].id;
if (u == p)
continue;
if (k == c)
++k;
ans[ei] = k;
++k;
dfs(u, ans[ei], v);
}
}
int main() {
int n;
cin >> n;
g.resize(n);
ans = vector<int>(n - 1);
rep(i, n - 1) {
int a, b;
cin >> a >> b;
--a, --b;
g[a].push_back((Edge){b, i});
g[b].push_back((Edge){a, i});
}
dfs(0);
int mx = 0;
rep(i, n) mx = max(mx, int(g[i].size()));
cout << mx << endl;
rep(i, n - 1) { cout << ans[i] << endl; }
} | insert | 29 | 29 | 29 | 31 | -11 | |
p02850 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int n;
vector<int> way[10010], way2[10010];
int way_num[10010], point[10010], max_c;
bool v[10010];
void dfs(int now, int colour) {
v[now] = 1;
int n_c = 1;
for (int i = 0; i < way[now].size(); i++) {
if (v[way[now][i]] == 0) {
if (n_c == colour)
n_c++;
way_num[way2[now][i]] = n_c;
dfs(way[now][i], n_c);
n_c++;
}
}
max_c = max(max_c, n_c - 1);
}
int main() {
cin >> n;
for (int i = 1; i < n; i++) {
int in1, in2;
cin >> in1 >> in2;
way[in1].push_back(in2);
way[in2].push_back(in1);
way2[in2].push_back(i);
way2[in1].push_back(i);
}
dfs(1, 0);
cout << max_c << endl;
for (int i = 1; i < n; i++)
cout << way_num[i] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int n;
vector<int> way[100010], way2[100010];
int way_num[100010], point[100010], max_c;
bool v[100010];
void dfs(int now, int colour) {
v[now] = 1;
int n_c = 1;
for (int i = 0; i < way[now].size(); i++) {
if (v[way[now][i]] == 0) {
if (n_c == colour)
n_c++;
way_num[way2[now][i]] = n_c;
dfs(way[now][i], n_c);
n_c++;
}
}
max_c = max(max_c, n_c - 1);
}
int main() {
cin >> n;
for (int i = 1; i < n; i++) {
int in1, in2;
cin >> in1 >> in2;
way[in1].push_back(in2);
way[in2].push_back(in1);
way2[in2].push_back(i);
way2[in1].push_back(i);
}
dfs(1, 0);
cout << max_c << endl;
for (int i = 1; i < n; i++)
cout << way_num[i] << endl;
return 0;
}
| replace | 4 | 7 | 4 | 7 | 0 | |
p02850 | C++ | Runtime Error | // ----- + ------ + + ------ JAI SHREE RAM ----- +------ + ------ + ------ +
// ------
/* _人人人人人人人人人人人人人人人_
> S H U B H A M A N A N D <
 ̄Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y ̄ */
#include <bits/stdc++.h>
using namespace std;
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define int long long
const int N = 1e3 + 10;
vector<pair<int, int>> adj[N];
vector<int> vis(N);
vector<int> color(N);
void dfs(int x, int par, int clr) {
vis[x] = 1;
int tempclr = 1;
for (auto i : adj[x]) {
if (!vis[i.first]) {
if (tempclr == clr)
tempclr++;
color[i.second] = tempclr;
dfs(i.first, x, tempclr);
tempclr++;
}
}
}
int32_t main() {
int n;
cin >> n;
int ans = 0;
for (int i = 1; i < n; i++) {
int x, y;
cin >> x >> y;
adj[x].push_back({y, i});
adj[y].push_back({x, i});
}
dfs(1, -1, -1);
for (int i = 1; i <= n; i++)
ans = max(ans, (int)adj[i].size());
cout << ans << endl;
for (int i = 1; i < n; i++)
cout << color[i] << endl;
return 0;
}
| // ----- + ------ + + ------ JAI SHREE RAM ----- +------ + ------ + ------ +
// ------
/* _人人人人人人人人人人人人人人人_
> S H U B H A M A N A N D <
 ̄Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y ̄ */
#include <bits/stdc++.h>
using namespace std;
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define int long long
const int N = 1e5 + 10;
vector<pair<int, int>> adj[N];
vector<int> vis(N);
vector<int> color(N);
void dfs(int x, int par, int clr) {
vis[x] = 1;
int tempclr = 1;
for (auto i : adj[x]) {
if (!vis[i.first]) {
if (tempclr == clr)
tempclr++;
color[i.second] = tempclr;
dfs(i.first, x, tempclr);
tempclr++;
}
}
}
int32_t main() {
int n;
cin >> n;
int ans = 0;
for (int i = 1; i < n; i++) {
int x, y;
cin >> x >> y;
adj[x].push_back({y, i});
adj[y].push_back({x, i});
}
dfs(1, -1, -1);
for (int i = 1; i <= n; i++)
ans = max(ans, (int)adj[i].size());
cout << ans << endl;
for (int i = 1; i < n; i++)
cout << color[i] << endl;
return 0;
}
| replace | 13 | 14 | 13 | 14 | 0 | |
p02850 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()
typedef long long int64;
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1 << 29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
struct Edge {
int to, id;
};
vector<vector<Edge>> g;
vector<int> ans;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
// 逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 組み合わせ
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
void dfs(int v, int c = -1, int p = -1) {
int k = 1;
rep(i, g[v].size()) {
int u = g[v][i].to, ei = g[v][i].id;
if (u == p)
continue;
if (k == c)
++k;
ans[ei] = k;
++k;
dfs(u, ans[ei], v);
}
}
void solve() {
int n;
cin >> n;
g.resize(n);
rep(i, n - 1) {
int a, b;
cin >> a >> b;
--a;
--b;
g[a].push_back((Edge){b, i});
g[b].push_back((Edge){a, i});
}
dfs(0);
int mx = 0;
rep(i, n) { mx = max(mx, int(g[i].size())); }
cout << mx << endl;
rep(i, n - 1) { cout << ans[i] << endl; }
return;
}
int main() {
solve();
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()
typedef long long int64;
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1 << 29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
struct Edge {
int to, id;
};
vector<vector<Edge>> g;
vector<int> ans;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
// 逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 組み合わせ
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
void dfs(int v, int c = -1, int p = -1) {
int k = 1;
rep(i, g[v].size()) {
int u = g[v][i].to, ei = g[v][i].id;
if (u == p)
continue;
if (k == c)
++k;
ans[ei] = k;
++k;
dfs(u, ans[ei], v);
}
}
void solve() {
int n;
cin >> n;
g.resize(n);
ans = vector<int>(n - 1);
rep(i, n - 1) {
int a, b;
cin >> a >> b;
--a;
--b;
g[a].push_back((Edge){b, i});
g[b].push_back((Edge){a, i});
}
dfs(0);
int mx = 0;
rep(i, n) { mx = max(mx, int(g[i].size())); }
cout << mx << endl;
rep(i, n - 1) { cout << ans[i] << endl; }
return;
}
int main() {
solve();
return 0;
}
| insert | 82 | 82 | 82 | 83 | -11 | |
p02850 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
template <class Read> void in(Read &x) {
x = 0;
int f = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
f |= (ch == '-');
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
x = f ? -x : x;
return;
}
struct Node {
int next;
int to;
int id;
int col;
} a[100005];
int n, top, ans, head[100005];
void add(int x, int y, int id) {
a[++top].next = head[x];
a[top].to = y;
a[top].id = id;
head[x] = top;
}
bool cmp(Node x, Node y) {
if (x.id != y.id)
return x.id < y.id;
return x.col > y.col;
}
void dfs(int x, int fa, int col) {
int sum = 0;
for (int i = head[x]; i; i = a[i].next) {
if (a[i].to != fa) {
sum++;
if (sum == col)
sum++;
a[i].col = sum;
ans = max(ans, sum);
dfs(a[i].to, x, sum);
}
}
}
int main() {
in(n);
for (int i = 1; i < n; i++) {
int x, y;
in(x);
in(y);
add(x, y, i);
add(y, x, i);
}
dfs(1, 0, 0);
cout << ans << endl;
sort(a + 1, a + (n - 1) * 2 + 1, cmp);
for (int i = 1; i <= (n - 1) * 2; i++) {
if (a[i].id != a[i - 1].id)
printf("%d\n", a[i].col);
}
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
template <class Read> void in(Read &x) {
x = 0;
int f = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
f |= (ch == '-');
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
x = f ? -x : x;
return;
}
struct Node {
int next;
int to;
int id;
int col;
} a[200005];
int n, top, ans, head[100005];
void add(int x, int y, int id) {
a[++top].next = head[x];
a[top].to = y;
a[top].id = id;
head[x] = top;
}
bool cmp(Node x, Node y) {
if (x.id != y.id)
return x.id < y.id;
return x.col > y.col;
}
void dfs(int x, int fa, int col) {
int sum = 0;
for (int i = head[x]; i; i = a[i].next) {
if (a[i].to != fa) {
sum++;
if (sum == col)
sum++;
a[i].col = sum;
ans = max(ans, sum);
dfs(a[i].to, x, sum);
}
}
}
int main() {
in(n);
for (int i = 1; i < n; i++) {
int x, y;
in(x);
in(y);
add(x, y, i);
add(y, x, i);
}
dfs(1, 0, 0);
cout << ans << endl;
sort(a + 1, a + (n - 1) * 2 + 1, cmp);
for (int i = 1; i <= (n - 1) * 2; i++) {
if (a[i].id != a[i - 1].id)
printf("%d\n", a[i].col);
}
return 0;
}
| replace | 31 | 32 | 31 | 32 | 0 | |
p02850 | C++ | Runtime Error |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
int n;
cin >> n;
vector<vector<int>> G(n);
vector<pair<int, int>> vp;
rep(i, n) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].emplace_back(b);
G[b].emplace_back(a);
vp.emplace_back(a, b);
}
vector<int> cs(n, 0);
map<pair<int, int>, int> I;
vector<int> used(n, 0);
queue<int> que;
que.emplace(0);
used[0] = 1;
int k = 0;
while (!que.empty()) {
int v = que.front();
que.pop();
if (k < (int)G[v].size())
k = G[v].size();
int cur = 1;
for (int u : G[v]) {
if (used[u])
continue;
if (cur == cs[v])
cur++;
cs[u] = I[make_pair(u, v)] = I[make_pair(v, u)] = cur++;
used[u] = 1;
que.emplace(u);
}
}
cout << k << endl;
for (auto p : vp)
cout << I[p] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
int n;
cin >> n;
vector<vector<int>> G(n);
vector<pair<int, int>> vp;
rep(i, n - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].emplace_back(b);
G[b].emplace_back(a);
vp.emplace_back(a, b);
}
vector<int> cs(n, 0);
map<pair<int, int>, int> I;
vector<int> used(n, 0);
queue<int> que;
que.emplace(0);
used[0] = 1;
int k = 0;
while (!que.empty()) {
int v = que.front();
que.pop();
if (k < (int)G[v].size())
k = G[v].size();
int cur = 1;
for (int u : G[v]) {
if (used[u])
continue;
if (cur == cs[v])
cur++;
cs[u] = I[make_pair(u, v)] = I[make_pair(v, u)] = cur++;
used[u] = 1;
que.emplace(u);
}
}
cout << k << endl;
for (auto p : vp)
cout << I[p] << endl;
return 0;
}
| replace | 11 | 12 | 11 | 12 | 0 | |
p02850 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100000;
pair<int, int> edge_color[N];
vector<int> tree[N];
int maxc = 0;
void dfs(pair<int, int> now) {
int next_color = 1;
for (auto i : tree[now.first]) {
if (edge_color[i].second)
continue;
if (next_color == now.second)
next_color++;
maxc = max(maxc, next_color);
edge_color[i].second = next_color;
dfs(edge_color[i]);
next_color++;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
if (a > b)
swap(a, b);
tree[a].push_back(i);
edge_color[i] = {b, 0};
}
dfs({1, 0});
cout << maxc << endl;
for (int i = 0; i < n - 1; i++) {
cout << edge_color[i].second << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100001;
pair<int, int> edge_color[N];
vector<int> tree[N];
int maxc = 0;
void dfs(pair<int, int> now) {
int next_color = 1;
for (auto i : tree[now.first]) {
if (edge_color[i].second)
continue;
if (next_color == now.second)
next_color++;
maxc = max(maxc, next_color);
edge_color[i].second = next_color;
dfs(edge_color[i]);
next_color++;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
if (a > b)
swap(a, b);
tree[a].push_back(i);
edge_color[i] = {b, 0};
}
dfs({1, 0});
cout << maxc << endl;
for (int i = 0; i < n - 1; i++) {
cout << edge_color[i].second << endl;
}
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p02850 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<vector<int>> G(N);
vector<pair<int, int>> vp;
for (int i = 0; i < N; i++) {
int a, b;
cin >> a >> b;
a--, b--;
G[a].emplace_back(b);
G[b].emplace_back(a);
vp.emplace_back(a, b);
}
int K = 0;
map<pair<int, int>, int> I;
vector<int> cs(N, 0);
vector<int> used(N, 0);
queue<int> que;
used[0] = 1;
que.emplace(0);
while (!que.empty()) {
int v = que.front();
que.pop();
if (K < (int)G[v].size())
K = G[v].size();
int cur = 1;
for (int u : G[v]) {
if (used[u])
continue;
if (cur == cs[v])
cur++;
cs[u] = I[make_pair(u, v)] = I[make_pair(v, u)] = cur++;
used[u] = 1;
que.emplace(u);
}
}
cout << K << endl;
for (auto p : vp) {
cout << I[p] << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<vector<int>> G(N);
vector<pair<int, int>> vp;
for (int i = 1; i < N; i++) {
int a, b;
cin >> a >> b;
a--, b--;
G[a].emplace_back(b);
G[b].emplace_back(a);
vp.emplace_back(a, b);
}
int K = 0;
map<pair<int, int>, int> I;
vector<int> cs(N, 0);
vector<int> used(N, 0);
queue<int> que;
used[0] = 1;
que.emplace(0);
while (!que.empty()) {
int v = que.front();
que.pop();
if (K < (int)G[v].size())
K = G[v].size();
int cur = 1;
for (int u : G[v]) {
if (used[u])
continue;
if (cur == cs[v])
cur++;
cs[u] = I[make_pair(u, v)] = I[make_pair(v, u)] = cur++;
used[u] = 1;
que.emplace(u);
}
}
cout << K << endl;
for (auto p : vp) {
cout << I[p] << endl;
}
return 0;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02850 | C++ | Runtime Error | #include <bits/stdc++.h>
#define debug(...)
#include <complex.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
vvi g;
int n;
template <typename T> class Queue {
int head, tail, capacity;
T *a;
public:
Queue() {
head = 0, tail = 0, capacity = 1;
a = new T[1];
}
T push(T data) {
if (tail == capacity) {
T *tmp = new T[capacity * 2];
int id = 0;
for (int i = head; i < tail; i++) {
tmp[id++] = a[i];
}
tail = tail - head;
head = 0;
delete[] a;
a = tmp;
}
a[tail++] = data;
}
T front() { return a[head]; }
void pop() { head++; }
int size() { return tail - head; }
};
map<pair<int, int>, int> BFS(int s) {
vi clr(n + 1, -1);
const int N = (int)1e6;
Queue<int> q;
q.push(s);
vi used(n + 1);
used[s] = 1;
map<pair<int, int>, int> hhh;
while (q.size()) {
int from = q.front();
q.pop();
int id = 1;
for (int to : g[from])
if (!used[to]) {
if (id == clr[from])
id++;
used[to] = 1;
hhh[make_pair(from, to)] = clr[to] = id;
id++;
q.push(to);
}
}
return hhh;
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
#ifdef LOCAL
freopen("f.txt", "r", stdin);
// freopen("g.txt", "w", stdout);
#endif
cin >> n;
g = vvi(n + 1);
size_t mx = 0;
vector<pair<int, int>> edges;
for (int i = 1; i < n; i++) {
int from, to;
cin >> from >> to;
g[from].push_back(to);
g[to].push_back(from);
mx = max({mx, g[from].size(), g[to].size()});
if (from > to)
swap(from, to);
edges.emplace_back(from, to);
}
map<pair<int, int>, int> clr = BFS(1);
cout << mx << '\n';
for (pair<int, int> p : edges) {
cout << clr[p] << '\n';
}
return 0;
}
| #include <bits/stdc++.h>
#define debug(...)
#include <complex.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
vvi g;
int n;
template <typename T> class Queue {
int head, tail, capacity;
T *a;
public:
Queue() {
head = 0, tail = 0, capacity = 1;
a = new T[1];
}
T push(T data) {
if (tail == capacity) {
T *tmp = new T[capacity * 2];
capacity *= 2;
int id = 0;
for (int i = head; i < tail; i++) {
tmp[id++] = a[i];
}
tail = tail - head;
head = 0;
delete[] a;
a = tmp;
}
a[tail++] = data;
}
T front() { return a[head]; }
void pop() { head++; }
int size() { return tail - head; }
};
map<pair<int, int>, int> BFS(int s) {
vi clr(n + 1, -1);
const int N = (int)1e6;
Queue<int> q;
q.push(s);
vi used(n + 1);
used[s] = 1;
map<pair<int, int>, int> hhh;
while (q.size()) {
int from = q.front();
q.pop();
int id = 1;
for (int to : g[from])
if (!used[to]) {
if (id == clr[from])
id++;
used[to] = 1;
hhh[make_pair(from, to)] = clr[to] = id;
id++;
q.push(to);
}
}
return hhh;
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
#ifdef LOCAL
freopen("f.txt", "r", stdin);
// freopen("g.txt", "w", stdout);
#endif
cin >> n;
g = vvi(n + 1);
size_t mx = 0;
vector<pair<int, int>> edges;
for (int i = 1; i < n; i++) {
int from, to;
cin >> from >> to;
g[from].push_back(to);
g[to].push_back(from);
mx = max({mx, g[from].size(), g[to].size()});
if (from > to)
swap(from, to);
edges.emplace_back(from, to);
}
map<pair<int, int>, int> clr = BFS(1);
cout << mx << '\n';
for (pair<int, int> p : edges) {
cout << clr[p] << '\n';
}
return 0;
}
| insert | 23 | 23 | 23 | 24 | 0 | |
p02850 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll
const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))
// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend() // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) // 最大値を求める
#define MIN(x) *min_element(ALL(x)) // 最小値を求める
#define all(x) (x).begin(), (x).end()
// 略記
#define pb emplace_back // vectorヘの挿入
#define mp make_pair // pairのコンストラクタ
#define F first // pairの一つ目の要素
#define S second // pairの二つ目の要素
#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)
#define perm(c) \
sort(all(c)); \
for (bool c##p = 1; c##p; \
c##p = next_permutation(all(c))) // 順列 123 132 213 231 312 321
#define BIT(n) (1LL << (n))
#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif
// 入力高速化
struct IoSetup {
IoSetup() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
}
} iosetup;
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;
}
struct Edge {
int from, to, color;
};
signed main() {
int N;
cin >> N;
vector<vector<int>> v(N);
map<P, int> m;
vector<P> p(N);
rep(i, N - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
v[a].pb(b);
v[b].pb(a);
p[i] = mp(a, b);
}
// BFS
// queに入れるデータは、都度変更必要。構造体作ったほうがいいケース多い。
queue<int> que;
// ここでは深さで管理しているが、何を入れるかは問題次第
vector<set<int>> color(N + 1);
vector<bool> seen(N + 1);
que.push(0);
int maxColor = 0;
while (!que.empty()) {
auto now = que.front();
que.pop();
if (seen[now] == true)
continue;
seen[now] = true;
for (auto next : v[now]) {
if (seen[next] == true)
continue;
PRINT(now)
PRINT(next)
FOR(i, 1, N + 1) {
if (color[next].find(i) == color[next].end() &&
color[now].find(i) == color[now].end()) {
color[next].emplace(i);
color[now].emplace(i);
m[mp(min(now, next), max(now, next))] = i;
chmax(maxColor, i);
break;
}
}
que.push(next);
}
}
cout << maxColor << endl;
rep(i, N - 1) { cout << m[p[i]] << endl; }
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll
const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))
// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend() // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) // 最大値を求める
#define MIN(x) *min_element(ALL(x)) // 最小値を求める
#define all(x) (x).begin(), (x).end()
// 略記
#define pb emplace_back // vectorヘの挿入
#define mp make_pair // pairのコンストラクタ
#define F first // pairの一つ目の要素
#define S second // pairの二つ目の要素
#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)
#define perm(c) \
sort(all(c)); \
for (bool c##p = 1; c##p; \
c##p = next_permutation(all(c))) // 順列 123 132 213 231 312 321
#define BIT(n) (1LL << (n))
#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif
// 入力高速化
struct IoSetup {
IoSetup() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
}
} iosetup;
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;
}
struct Edge {
int from, to, color;
};
signed main() {
int N;
cin >> N;
vector<vector<int>> v(N);
map<P, int> m;
vector<P> p(N);
rep(i, N - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
v[a].pb(b);
v[b].pb(a);
p[i] = mp(a, b);
}
// BFS
// queに入れるデータは、都度変更必要。構造体作ったほうがいいケース多い。
queue<int> que;
// ここでは深さで管理しているが、何を入れるかは問題次第
vector<set<int>> color(N + 1);
vector<bool> seen(N + 1);
que.push(0);
int maxColor = 0;
while (!que.empty()) {
auto now = que.front();
que.pop();
if (seen[now] == true)
continue;
seen[now] = true;
for (auto next : v[now]) {
if (seen[next] == true)
continue;
PRINT(now)
PRINT(next)
FOR(i, 1, N + 1) {
if (color[now].size() == maxColor)
i = maxColor + 1;
if (color[next].find(i) == color[next].end() &&
color[now].find(i) == color[now].end()) {
color[next].emplace(i);
color[now].emplace(i);
m[mp(min(now, next), max(now, next))] = i;
chmax(maxColor, i);
break;
}
}
que.push(next);
}
}
cout << maxColor << endl;
rep(i, N - 1) { cout << m[p[i]] << endl; }
} | insert | 120 | 120 | 120 | 122 | TLE | |
p02850 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
for (ll i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
for (ll i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
// #define endl "\n"
#define ciosup \
cin.tie(0); \
ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (int i = 0; i < v.size(); ++i) {
is >> v[i];
}
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < v.size() - 1; ++i) {
os << v[i] << " ";
}
if (v.size() > 0) {
os << v[v.size() - 1] << endl;
}
return os;
}
struct edge {
int to, color;
};
ll n, colornum;
vector<map<int, int>> G(100008);
void dfs(int now, int from) {
int prevcolor = -1;
if (from != -1) {
for (auto elem : G[from]) {
if (elem.FI == now) {
prevcolor = elem.SE;
}
}
}
ll nowcolor = 1;
for (auto elem : G[now]) {
if (elem.FI != from) {
if (nowcolor == prevcolor) {
nowcolor++;
}
G[now][elem.FI] = nowcolor;
dfs(elem.FI, now);
colornum = max(colornum, nowcolor);
++nowcolor;
}
}
}
int main() {
cin >> n;
colornum = -1;
vint avec(n - 1), bvec(n - 1);
REP(i, n - 1) {
int a, b;
cin >> a >> b;
--a;
--b;
edge e;
e.to = b;
e.color = 0;
G[a][b] = 0;
G[b][a] = 0;
avec[i] = a;
bvec[i] = b;
}
dfs(0, -1);
cout << colornum << endl;
REP(i, n - 1) {
int a = avec[i], b = bvec[i];
if (G[a][b] != 0) {
cout << G[a][b] << endl;
} else {
cout << G[b][a] << endl;
}
}
} | #include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
for (ll i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
for (ll i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
// #define endl "\n"
#define ciosup \
cin.tie(0); \
ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (int i = 0; i < v.size(); ++i) {
is >> v[i];
}
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < v.size() - 1; ++i) {
os << v[i] << " ";
}
if (v.size() > 0) {
os << v[v.size() - 1] << endl;
}
return os;
}
struct edge {
int to, color;
};
ll n, colornum;
vector<map<int, int>> G(100008);
void dfs(int now, int from) {
int prevcolor = -1;
if (from != -1) {
prevcolor = G[from][now];
}
ll nowcolor = 1;
for (auto elem : G[now]) {
if (elem.FI != from) {
if (nowcolor == prevcolor) {
nowcolor++;
}
G[now][elem.FI] = nowcolor;
dfs(elem.FI, now);
colornum = max(colornum, nowcolor);
++nowcolor;
}
}
}
int main() {
cin >> n;
colornum = -1;
vint avec(n - 1), bvec(n - 1);
REP(i, n - 1) {
int a, b;
cin >> a >> b;
--a;
--b;
edge e;
e.to = b;
e.color = 0;
G[a][b] = 0;
G[b][a] = 0;
avec[i] = a;
bvec[i] = b;
}
dfs(0, -1);
cout << colornum << endl;
REP(i, n - 1) {
int a = avec[i], b = bvec[i];
if (G[a][b] != 0) {
cout << G[a][b] << endl;
} else {
cout << G[b][a] << endl;
}
}
} | replace | 53 | 58 | 53 | 54 | TLE | |
p02850 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int N = 1e5 + 5;
vector<pii> a[N];
int visited[N];
int mincolor;
int color[N];
void dfs(int cur, int col) {
vector<int> used(a[cur].size() + 1);
int st = 1;
for (auto branch : a[cur]) {
if (!visited[branch.first]) {
visited[branch.first] = 1;
for (int i = st; i <= mincolor; i++) {
if (!used[i] && i != col) {
used[i] = 1;
color[branch.second] = i;
st = i + 1;
break;
}
}
dfs(branch.first, color[branch.second]);
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
a[u].push_back({v, i});
a[v].push_back({u, i});
}
mincolor = 1;
for (int i = 1; i <= n; i++) {
mincolor = max(mincolor, (int)a[i].size());
}
cout << mincolor << "\n";
int root;
for (int i = 1; i <= n; i++) {
if (mincolor == a[i].size()) {
root = i;
break;
}
}
dfs(root, 1);
for (int i = 1; i < n; i++) {
cout << color[i] << "\n";
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int N = 1e5 + 5;
vector<pii> a[N];
int visited[N];
int mincolor;
int color[N];
void dfs(int cur, int col) {
vector<int> used(mincolor + 1);
int st = 1;
for (auto branch : a[cur]) {
if (!visited[branch.first]) {
visited[branch.first] = 1;
for (int i = st; i <= mincolor; i++) {
if (!used[i] && i != col) {
used[i] = 1;
color[branch.second] = i;
st = i + 1;
break;
}
}
dfs(branch.first, color[branch.second]);
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
a[u].push_back({v, i});
a[v].push_back({u, i});
}
mincolor = 1;
for (int i = 1; i <= n; i++) {
mincolor = max(mincolor, (int)a[i].size());
}
cout << mincolor << "\n";
int root;
for (int i = 1; i <= n; i++) {
if (mincolor == a[i].size()) {
root = i;
break;
}
}
dfs(root, 1);
for (int i = 1; i < n; i++) {
cout << color[i] << "\n";
}
return 0;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p02850 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int ans[N], k;
vector<pair<int, int>> adj[N];
int dfs(int node, int par, int col) {
int nxt = 1;
for (auto &c : adj[node]) {
if (c.first == par)
continue;
nxt += nxt == col;
k = max(k, nxt);
ans[c.second] = nxt;
dfs(c.first, node, nxt);
nxt++;
}
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back({v, i});
adj[v].push_back({u, i});
}
dfs(1, 1, -1);
cout << k << '\n';
for (int i = 0; i < n - 1; i++)
cout << ans[i] << '\n';
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int ans[N], k;
vector<pair<int, int>> adj[N];
void dfs(int node, int par, int col) {
int nxt = 1;
for (auto &c : adj[node]) {
if (c.first == par)
continue;
nxt += nxt == col;
k = max(k, nxt);
ans[c.second] = nxt;
dfs(c.first, node, nxt);
nxt++;
}
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back({v, i});
adj[v].push_back({u, i});
}
dfs(1, 1, -1);
cout << k << '\n';
for (int i = 0; i < n - 1; i++)
cout << ans[i] << '\n';
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p02850 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define P pair<int, int>
#define MAX_N 1000010
using namespace std;
// 辺の塗り分けの最小値 = 出次数の最大値 = max(k,G[u].size())
// 節点uに対し時節点vの色は 1,2,~,G[u].size()
// ただし、節点uの色以外 if(c[u] == cur(=c[v])) cur++;
// 組み合わせ(辺) (u,v)の色(cur)を保存 map<P,int> ec
// c[v = 0~G[u].size()] = cur++;
// ただし(c[u] == c[v](=cur) ) cur++;
// e_c[u,v] = ec[v,c] = cur;
int main() {
int n;
cin >> n;
vector<vector<int>> G;
vector<int> visited(n, 0);
vector<int> c(n, 0);
vector<P> e;
map<P, int> ec;
for (int i = 0; i < (n - 1); i++) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].push_back(b);
G[b].push_back(a);
e.push_back(make_pair(a, b));
}
int k = 0;
visited[0] = 1;
queue<int> que;
que.push(0);
while (!que.empty()) {
int u = que.front();
que.pop();
if (k < G[u].size())
k = G[u].size();
int cur = 1;
for (int j = 0; j < G[u].size(); j++) {
int v = G[u][j];
if (visited[v])
continue;
if (c[u] == cur)
cur++;
c[v] = ec[make_pair(u, v)] = ec[make_pair(v, u)] = cur++;
que.push(v);
visited[v] = 1;
}
}
cout << k << endl;
for (int i = 0; i < (n - 1); i++) {
pair<int, int> key = e[i];
int ans = ec[key];
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define P pair<int, int>
#define MAX_N 1000010
using namespace std;
// 辺の塗り分けの最小値 = 出次数の最大値 = max(k,G[u].size())
// 節点uに対し時節点vの色は 1,2,~,G[u].size()
// ただし、節点uの色以外 if(c[u] == cur(=c[v])) cur++;
// 組み合わせ(辺) (u,v)の色(cur)を保存 map<P,int> ec
// c[v = 0~G[u].size()] = cur++;
// ただし(c[u] == c[v](=cur) ) cur++;
// e_c[u,v] = ec[v,c] = cur;
int main() {
int n;
cin >> n;
vector<vector<int>> G(n);
vector<int> visited(n, 0);
vector<int> c(n, 0);
vector<P> e;
map<P, int> ec;
for (int i = 0; i < (n - 1); i++) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].push_back(b);
G[b].push_back(a);
e.push_back(make_pair(a, b));
}
int k = 0;
visited[0] = 1;
queue<int> que;
que.push(0);
while (!que.empty()) {
int u = que.front();
que.pop();
if (k < G[u].size())
k = G[u].size();
int cur = 1;
for (int j = 0; j < G[u].size(); j++) {
int v = G[u][j];
if (visited[v])
continue;
if (c[u] == cur)
cur++;
c[v] = ec[make_pair(u, v)] = ec[make_pair(v, u)] = cur++;
que.push(v);
visited[v] = 1;
}
}
cout << k << endl;
for (int i = 0; i < (n - 1); i++) {
pair<int, int> key = e[i];
int ans = ec[key];
cout << ans << endl;
}
return 0;
} | replace | 18 | 19 | 18 | 19 | -11 | |
p02850 | C++ | Time Limit Exceeded | #pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
/*
このコード、と~おれ!
Be accepted!
∧_∧
(。・ω・。)つ━☆・*。
⊂ ノ ・゜+.
しーJ °。+ *´¨)
.· ´¸.·*´¨) ¸.·*¨)
(¸.·´ (¸.·'* ☆
*/
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <vector>
#pragma GCC optimize("Ofast")
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define rep2(i, n) for (int i = 2; i < (n); ++i)
#define repr(i, n) for (int i = n; i >= 0; --i)
#define reprm(i, n) for (int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a) // 少数出力
#define printdbd(a) printf("%.16lf\n", a) // 少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) // string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2) // 等差数列の和、初項,末項,項数
#define p push
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg) / 360.0) * 2.0 * PI)
#define rad_to_deg(rad) (((rad) / 2.0 / PI) * 360.0)
#define Please return
#define AC 0
using ll = long long;
const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);
using namespace std;
void scans(string &str) {
char c;
scanf("%c", &c);
if (c == '\n')
scanf("%c", &c); // 最初の改行対策
while (c != '\n' && c != -1) {
str += c;
scanf("%c", &c);
}
}
void scanc(char &str) {
char c;
scanf("%c", &c);
if (c == -1)
return;
while (c == '\n') {
scanf("%c", &c);
}
str = c;
}
double acot(double x) { return PI / 2 - atan(x); }
/*-----------------------------------------ここからコード-----------------------------------------*/
ll ans = 0;
ll n;
void dfs(ll now, ll nowcolour, vector<vector<pair<ll, ll>>> &graph,
vector<bool> &visited) {
ll newcolour = 1;
visited[now] = true;
ll i = 0;
for (auto a : graph[now]) {
if (a.second == 0) {
if (visited[a.first] == false) {
if (nowcolour == newcolour)
++newcolour;
graph[now][i].second = newcolour;
dfs(a.first, newcolour, graph, visited);
++newcolour;
}
}
++i;
}
ans = max(ans, newcolour);
}
int main() {
scanf("%lld", &n);
vector<vector<pair<ll, ll>>> graph(n);
vector<bool> visited(n);
vector<pair<int, int>> anss(n - 1);
ll a, b;
rep(i, n - 1) {
scanf("%lld%lld", &a, &b);
graph[a - 1].pb(make_pair(b - 1, 0));
graph[b - 1].pb(make_pair(a - 1, 0));
anss[i] = make_pair(a - 1, b - 1);
}
dfs(0, 0, graph, visited);
printf("%lld\n", ans - 1);
for (auto a : anss) {
ll ansa = -1, ansb = -1;
for (auto b : graph[a.first]) {
if (b.first == a.second)
ansa = b.second;
}
if (ansa == -1)
for (auto b : graph[a.second]) {
if (b.first == a.first)
ansb = b.second;
}
if (ansa == -1 && ansb == -1)
continue;
else
printf("%lld\n", max(ansa, ansb));
}
Please AC;
}
| /*
このコード、と~おれ!
Be accepted!
∧_∧
(。・ω・。)つ━☆・*。
⊂ ノ ・゜+.
しーJ °。+ *´¨)
.· ´¸.·*´¨) ¸.·*¨)
(¸.·´ (¸.·'* ☆
*/
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <vector>
#pragma GCC optimize("Ofast")
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define rep2(i, n) for (int i = 2; i < (n); ++i)
#define repr(i, n) for (int i = n; i >= 0; --i)
#define reprm(i, n) for (int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a) // 少数出力
#define printdbd(a) printf("%.16lf\n", a) // 少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) // string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2) // 等差数列の和、初項,末項,項数
#define p push
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg) / 360.0) * 2.0 * PI)
#define rad_to_deg(rad) (((rad) / 2.0 / PI) * 360.0)
#define Please return
#define AC 0
using ll = long long;
const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);
using namespace std;
void scans(string &str) {
char c;
scanf("%c", &c);
if (c == '\n')
scanf("%c", &c); // 最初の改行対策
while (c != '\n' && c != -1) {
str += c;
scanf("%c", &c);
}
}
void scanc(char &str) {
char c;
scanf("%c", &c);
if (c == -1)
return;
while (c == '\n') {
scanf("%c", &c);
}
str = c;
}
double acot(double x) { return PI / 2 - atan(x); }
/*-----------------------------------------ここからコード-----------------------------------------*/
ll ans = 0;
ll n;
void dfs(ll now, ll nowcolour, vector<vector<pair<ll, ll>>> &graph,
vector<bool> &visited) {
ll newcolour = 1;
visited[now] = true;
ll i = 0;
for (auto a : graph[now]) {
if (a.second == 0) {
if (visited[a.first] == false) {
if (nowcolour == newcolour)
++newcolour;
graph[now][i].second = newcolour;
dfs(a.first, newcolour, graph, visited);
++newcolour;
}
}
++i;
}
ans = max(ans, newcolour);
}
int main() {
scanf("%lld", &n);
vector<vector<pair<ll, ll>>> graph(n);
vector<bool> visited(n);
vector<pair<int, int>> anss(n - 1);
ll a, b;
rep(i, n - 1) {
scanf("%lld%lld", &a, &b);
graph[a - 1].pb(make_pair(b - 1, 0));
graph[b - 1].pb(make_pair(a - 1, 0));
anss[i] = make_pair(a - 1, b - 1);
}
dfs(0, 0, graph, visited);
printf("%lld\n", ans - 1);
for (auto a : anss) {
ll ansa = -1, ansb = -1;
for (auto b : graph[a.first]) {
if (b.first == a.second)
ansa = b.second;
}
if (ansa == -1)
for (auto b : graph[a.second]) {
if (b.first == a.first)
ansb = b.second;
}
if (ansa == -1 && ansb == -1)
continue;
else
printf("%lld\n", max(ansa, ansb));
}
Please AC;
} | delete | 0 | 3 | 0 | 0 | TLE | |
p02850 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
void dfs(vector<int> &c, vector<vector<pair<int, int>>> &E, int v = 0) {
int cnt = E[v].size();
set<int> st;
for (int i = 1; i <= cnt; i++) {
st.insert(cnt);
}
for (auto P : E[v]) {
int id = P.second;
if (c[id] != -1) {
st.erase(c[id]);
}
}
vector<int> color;
for (int x : st) {
color.push_back(x);
}
for (auto P : E[v]) {
int w = P.first;
int id = P.second;
if (c[id] == -1) {
c[id] = color.back();
color.pop_back();
dfs(c, E, w);
}
}
}
int main() {
int N;
cin >> N;
vector<vector<pair<int, int>>> E(N);
for (int i = 0; i < N - 1; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
E[a].push_back(make_pair(b, i));
E[b].push_back(make_pair(a, i));
}
vector<int> c(N - 1, -1);
dfs(c, E);
int K = 0;
for (int i = 0; i < N - 1; i++) {
K = max(K, c[i]);
}
cout << K << endl;
for (int i = 0; i < N - 1; i++) {
cout << c[i] << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
void dfs(vector<int> &c, vector<vector<pair<int, int>>> &E, int v = 0) {
int cnt = E[v].size();
set<int> st;
for (int i = 1; i <= cnt; i++) {
st.insert(i);
}
for (auto P : E[v]) {
int id = P.second;
if (c[id] != -1) {
st.erase(c[id]);
}
}
vector<int> color;
for (int x : st) {
color.push_back(x);
}
for (auto P : E[v]) {
int w = P.first;
int id = P.second;
if (c[id] == -1) {
c[id] = color.back();
color.pop_back();
dfs(c, E, w);
}
}
}
int main() {
int N;
cin >> N;
vector<vector<pair<int, int>>> E(N);
for (int i = 0; i < N - 1; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
E[a].push_back(make_pair(b, i));
E[b].push_back(make_pair(a, i));
}
vector<int> c(N - 1, -1);
dfs(c, E);
int K = 0;
for (int i = 0; i < N - 1; i++) {
K = max(K, c[i]);
}
cout << K << endl;
for (int i = 0; i < N - 1; i++) {
cout << c[i] << endl;
}
} | replace | 6 | 7 | 6 | 7 | 0 | |
p02850 | C++ | Runtime Error | #define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 1000000007;
// const ll MOD = 998244353
const int inf = 1 << 30;
const ll linf = 1LL << 60;
int N;
int par[100000];
int ans[100000];
vector<pi> edge[100000];
void dfs(int v) {
int cnt = 1;
int ex = 0;
rep(i, edge[v].size()) {
if (edge[v][i].first == par[v]) {
ex = ans[edge[v][i].second];
}
par[edge[v][i].first] = v;
}
rep(i, edge[v].size()) {
if (edge[v][i].first == par[v]) {
continue;
}
if (cnt == ex)
cnt++;
ans[edge[v][i].second] = cnt++;
}
rep(i, edge[v].size()) {
if (edge[v][i].first == par[v]) {
continue;
}
dfs(edge[v][i].first);
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N;
rep(i, N - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
edge[a].push_back(pi(b, i));
edge[b].push_back(pi(a, i));
}
memset(par, -1, sizeof(par));
dfs(0);
cout << *max_element(ans, ans + N - 1) << endl;
rep(i, N - 1) { cout << ans[i] << endl; }
} | #define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 1000000007;
// const ll MOD = 998244353
const int inf = 1 << 30;
const ll linf = 1LL << 60;
int N;
int par[100000];
int ans[100000];
vector<pi> edge[100000];
void dfs(int v) {
int cnt = 1;
int ex = 0;
rep(i, edge[v].size()) {
if (edge[v][i].first == par[v]) {
ex = ans[edge[v][i].second];
continue;
}
par[edge[v][i].first] = v;
}
rep(i, edge[v].size()) {
if (edge[v][i].first == par[v]) {
continue;
}
if (cnt == ex)
cnt++;
ans[edge[v][i].second] = cnt++;
}
rep(i, edge[v].size()) {
if (edge[v][i].first == par[v]) {
continue;
}
dfs(edge[v][i].first);
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N;
rep(i, N - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
edge[a].push_back(pi(b, i));
edge[b].push_back(pi(a, i));
}
memset(par, -1, sizeof(par));
dfs(0);
cout << *max_element(ans, ans + N - 1) << endl;
rep(i, N - 1) { cout << ans[i] << endl; }
} | insert | 39 | 39 | 39 | 40 | 0 | |
p02850 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
struct Edge {
int to, id;
};
vector<vector<Edge>> g;
vector<int> ans;
void dfs(int v, int c = -1, int p = -1) {
int k = 1;
rep(i, g[v].size()) {
int u = g[v][i].to, ei = g[v][i].id;
if (u == p)
continue;
if (k == c)
++k;
ans[ei] = k;
++k;
dfs(u, ans[ei], v);
}
}
int main() {
int n;
cin >> n;
g.resize(n);
rep(i, n - 1) {
int a, b;
cin >> a >> b;
--a;
--b;
g[a].push_back((Edge){b, i});
g[b].push_back((Edge){a, i});
}
dfs(0);
int mx = 0;
rep(i, n) mx = max(mx, int(g[i].size()));
cout << mx << endl;
rep(i, n - 1) { cout << ans[i] << endl; }
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
struct Edge {
int to, id;
};
vector<vector<Edge>> g;
vector<int> ans;
void dfs(int v, int c = -1, int p = -1) {
int k = 1;
rep(i, g[v].size()) {
int u = g[v][i].to, ei = g[v][i].id;
if (u == p)
continue;
if (k == c)
++k;
ans[ei] = k;
++k;
dfs(u, ans[ei], v);
}
}
int main() {
int n;
cin >> n;
g.resize(n);
ans = vector<int>(n - 1);
rep(i, n - 1) {
int a, b;
cin >> a >> b;
--a;
--b;
g[a].push_back((Edge){b, i});
g[b].push_back((Edge){a, i});
}
dfs(0);
int mx = 0;
rep(i, n) mx = max(mx, int(g[i].size()));
cout << mx << endl;
rep(i, n - 1) { cout << ans[i] << endl; }
return 0;
} | insert | 30 | 30 | 30 | 31 | -11 | |
p02850 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
const int maxn = 1e5 + 10;
map<pair<int, int>, int> ans;
vector<int> edge[maxn];
priority_queue<int, vector<int>, greater<int>> q[maxn];
priority_queue<int, vector<int>, less<int>> Q[maxn];
int n, a[maxn], b[maxn], Max;
inline void dfs(int now, int fa) {
for (size_t i = 0; i < edge[now].size(); i++) {
int to = edge[now][i];
if (to ^ fa) {
int val = 0;
if (q[now].size())
val = q[now].top() - 1;
if (!val)
val = Q[now].top() + 1;
Max = max(Max, val);
q[now].push(val);
q[to].push(val);
Q[now].push(val);
Q[to].push(val);
ans[make_pair(now, to)] = val;
ans[make_pair(to, now)] = val;
dfs(to, now);
}
}
}
signed main() {
scanf("%d", &n);
for (int i = 1; i < n; i++) {
scanf("%d%d", &a[i], &b[i]);
edge[a[i]].push_back(b[i]);
edge[b[i]].push_back(a[i]);
}
dfs(1, 0);
printf("%d\n", Max);
for (int i = 1; i < n; i++)
printf("%d\n", ans[make_pair(a[i], b[i])]);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
const int maxn = 1e5 + 10;
map<pair<int, int>, int> ans;
vector<int> edge[maxn];
priority_queue<int, vector<int>, greater<int>> q[maxn];
priority_queue<int, vector<int>, less<int>> Q[maxn];
int n, a[maxn], b[maxn], Max;
inline void dfs(int now, int fa) {
for (size_t i = 0; i < edge[now].size(); i++) {
int to = edge[now][i];
if (to ^ fa) {
int val = 0;
if (q[now].size())
val = q[now].top() - 1;
else
val = 1;
if (!val)
val = Q[now].top() + 1;
Max = max(Max, val);
q[now].push(val);
q[to].push(val);
Q[now].push(val);
Q[to].push(val);
ans[make_pair(now, to)] = val;
ans[make_pair(to, now)] = val;
dfs(to, now);
}
}
}
signed main() {
scanf("%d", &n);
for (int i = 1; i < n; i++) {
scanf("%d%d", &a[i], &b[i]);
edge[a[i]].push_back(b[i]);
edge[b[i]].push_back(a[i]);
}
dfs(1, 0);
printf("%d\n", Max);
for (int i = 1; i < n; i++)
printf("%d\n", ans[make_pair(a[i], b[i])]);
return 0;
} | insert | 21 | 21 | 21 | 23 | -11 | |
p02850 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll siz = 1e5;
const ll mod = 1e9;
const ll MAXX = 1e18;
map<pair<ll, ll>, ll> col;
vector<ll> graph[siz];
ll ma = 0;
void dfs(ll node, ll par) {
ll color = 1;
if (color == col[make_pair(node, par)]) {
color++;
}
for (ll i = 0; i < graph[node].size(); i++) {
ll v = graph[node][i];
if (v != par) {
pair<ll, ll> a = make_pair(node, v);
pair<ll, ll> b = make_pair(v, node);
col[a] = col[b] = color;
dfs(v, node);
color++;
if (color == col[make_pair(node, par)]) {
color++;
}
}
}
ma = max(color - 1, ma);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("INP.txt", "r", stdin);
// freopen("OUT.txt", "w", stdout);
ll n;
cin >> n;
vector<pair<ll, ll>> hold;
for (ll i = 1; i < n; i++) {
ll a, b;
cin >> a >> b;
graph[a].push_back(b);
graph[b].push_back(a);
hold.push_back(make_pair(a, b));
}
dfs(1, 1);
cout << ma << '\n';
for (ll i = 0; i < hold.size(); i++) {
cout << col[hold[i]] << '\n';
}
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll siz = 1e5;
const ll mod = 1e9;
const ll MAXX = 1e18;
map<pair<ll, ll>, ll> col;
vector<ll> graph[siz + 10];
ll ma = 0;
void dfs(ll node, ll par) {
ll color = 1;
if (color == col[make_pair(node, par)]) {
color++;
}
for (ll i = 0; i < graph[node].size(); i++) {
ll v = graph[node][i];
if (v != par) {
pair<ll, ll> a = make_pair(node, v);
pair<ll, ll> b = make_pair(v, node);
col[a] = col[b] = color;
dfs(v, node);
color++;
if (color == col[make_pair(node, par)]) {
color++;
}
}
}
ma = max(color - 1, ma);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("INP.txt", "r", stdin);
// freopen("OUT.txt", "w", stdout);
ll n;
cin >> n;
vector<pair<ll, ll>> hold;
for (ll i = 1; i < n; i++) {
ll a, b;
cin >> a >> b;
graph[a].push_back(b);
graph[b].push_back(a);
hold.push_back(make_pair(a, b));
}
dfs(1, 1);
cout << ma << '\n';
for (ll i = 0; i < hold.size(); i++) {
cout << col[hold[i]] << '\n';
}
return 0;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p02850 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
// #define MOD 998244353
#define INF 1145141919810893364
// #define INF 810114514
// #define PI 3.141592653589
typedef pair<int, int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define OREP(i, n) for (int i = 1; i <= (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define GOODBYE \
do { \
cout << "No" << endl; \
return 0; \
} while (false)
#define MM << " " <<
#define Endl endl
std::vector<int> compress(std::vector<int> D) {
std::map<int, int> G;
std::vector<int> E, r;
int s = D.size();
for (int i = 0; i < s; i++) {
E.push_back(D[i]);
}
sort(E.begin(), E.end());
int t = 0;
for (int i = 0; i < s; i++) {
if (i != 0 && E[i] != E[i - 1]) {
t++;
}
G[E[i]] = t;
}
for (int i = 0; i < s; i++) {
r.push_back(G[D[i]]);
}
return r;
}
signed main(void) {
const int MEM = 114;
int N;
int a[MEM], b[MEM];
cin >> N;
REP(i, N - 1) {
cin >> a[i] >> b[i];
a[i]--;
b[i]--;
}
vector<int> G[MEM], child[MEM];
int color[MEM], parent[MEM];
int kai[MEM] = {};
bool visited[MEM] = {};
REP(i, N - 1) {
G[a[i]].push_back(b[i]);
G[b[i]].push_back(a[i]);
kai[a[i]]++;
kai[b[i]]++;
}
int root = 0;
REP(i, N) {
if (kai[i] == 1) {
root = i;
break;
}
}
// cout << root << endl;
queue<int> P;
P.push(root);
while (!P.empty()) {
int q = P.front();
P.pop();
visited[q] = 1;
REP(i, G[q].size()) {
if (!visited[G[q][i]]) {
P.push(G[q][i]);
child[q].push_back(G[q][i]);
parent[G[q][i]] = q;
}
}
}
parent[root] = -1;
/*REP(i,N){
cout << i << ": ";
REP(j,child[i].size()){
cout << child[i][j] << " ";
}cout << endl;
}*/
P.push(root);
color[root] = 0;
while (!P.empty()) {
int q = P.front();
P.pop();
int now = 0;
if (color[q] == now)
now++;
REP(i, child[q].size()) {
P.push(child[q][i]);
color[child[q][i]] = now;
now++;
if (color[q] == now)
now++;
}
}
vector<int> Ans;
REP(i, N - 1) {
if (a[i] == parent[b[i]]) {
Ans.push_back(color[b[i]] + 1);
} else if (b[i] == parent[a[i]]) {
Ans.push_back(color[a[i]] + 1);
}
}
Ans = compress(Ans);
int K = 0;
REP(i, Ans.size()) { K = max(K, Ans[i] + 1); }
cout << K << endl;
REP(i, Ans.size()) { cout << Ans[i] + 1 << endl; }
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
// #define MOD 998244353
#define INF 1145141919810893364
// #define INF 810114514
// #define PI 3.141592653589
typedef pair<int, int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define OREP(i, n) for (int i = 1; i <= (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define GOODBYE \
do { \
cout << "No" << endl; \
return 0; \
} while (false)
#define MM << " " <<
#define Endl endl
std::vector<int> compress(std::vector<int> D) {
std::map<int, int> G;
std::vector<int> E, r;
int s = D.size();
for (int i = 0; i < s; i++) {
E.push_back(D[i]);
}
sort(E.begin(), E.end());
int t = 0;
for (int i = 0; i < s; i++) {
if (i != 0 && E[i] != E[i - 1]) {
t++;
}
G[E[i]] = t;
}
for (int i = 0; i < s; i++) {
r.push_back(G[D[i]]);
}
return r;
}
signed main(void) {
const int MEM = 114514;
int N;
int a[MEM], b[MEM];
cin >> N;
REP(i, N - 1) {
cin >> a[i] >> b[i];
a[i]--;
b[i]--;
}
vector<int> G[MEM], child[MEM];
int color[MEM], parent[MEM];
int kai[MEM] = {};
bool visited[MEM] = {};
REP(i, N - 1) {
G[a[i]].push_back(b[i]);
G[b[i]].push_back(a[i]);
kai[a[i]]++;
kai[b[i]]++;
}
int root = 0;
REP(i, N) {
if (kai[i] == 1) {
root = i;
break;
}
}
// cout << root << endl;
queue<int> P;
P.push(root);
while (!P.empty()) {
int q = P.front();
P.pop();
visited[q] = 1;
REP(i, G[q].size()) {
if (!visited[G[q][i]]) {
P.push(G[q][i]);
child[q].push_back(G[q][i]);
parent[G[q][i]] = q;
}
}
}
parent[root] = -1;
/*REP(i,N){
cout << i << ": ";
REP(j,child[i].size()){
cout << child[i][j] << " ";
}cout << endl;
}*/
P.push(root);
color[root] = 0;
while (!P.empty()) {
int q = P.front();
P.pop();
int now = 0;
if (color[q] == now)
now++;
REP(i, child[q].size()) {
P.push(child[q][i]);
color[child[q][i]] = now;
now++;
if (color[q] == now)
now++;
}
}
vector<int> Ans;
REP(i, N - 1) {
if (a[i] == parent[b[i]]) {
Ans.push_back(color[b[i]] + 1);
} else if (b[i] == parent[a[i]]) {
Ans.push_back(color[a[i]] + 1);
}
}
Ans = compress(Ans);
int K = 0;
REP(i, Ans.size()) { K = max(K, Ans[i] + 1); }
cout << K << endl;
REP(i, Ans.size()) { cout << Ans[i] + 1 << endl; }
return 0;
}
| replace | 42 | 43 | 42 | 43 | 0 | |
p02850 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
/// Typedef
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define pb push_back
#define ppb pop_back
#define MP make_pair
#define ff first
#define ss second
#define sf scanf
#define pf printf
#define SQR(x) ((x) * (x))
#define loop(i, y) for (int i = 0; i < int(y); i++)
#define FOR(i, x, y) for (int i = int(x); i < int(y); i++)
#define ROF(i, x, y) for (int i = int(x); i >= int(y); i--)
#define all(c) c.begin(), c.end()
#define sz(c) int(c.size())
#define clr(x, y) memset(x, y, sizeof(x))
#define si(x) scanf("%d", &x)
#define sii(x, y) scanf("%d %d", &x, &y)
#define siii(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define sl(x) scanf("%lld", &x)
#define sll(x, y) scanf("%lld %lld", &x, &y)
#define slll(x, y, z) scanf("%lld %lld %lld", &x, &y, &z)
#ifdef VAMP
#define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cout << name << " = " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " = " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define dbg(...)
#endif
template <class T> inline T bigMod(T p, T e, T M) {
ll ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1)
ret = (ret * p) % M;
p = (p * p) % M;
}
return (T)ret;
}
template <class T> inline T modInverse(T a, T M) { return bigMod(a, M - 2, M); }
template <class T> inline T gcd(T a, T b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <class T> inline T lcm(T a, T b) {
a = abs(a);
b = abs(b);
return (a / gcd(a, b)) * b;
}
template <class T> inline string int2String(T a) {
ostringstream str;
str << a;
return str.str();
}
template <class T> inline T string2int(string a) {
stringstream str(a);
T b;
str >> b;
return b;
}
template <class T> inline void read(T &r) {
r = 0;
int f = 1;
char ch = getchar();
while (ch < '0' or ch > '9') {
f = (ch == '-' ? -1 : 1), ch = getchar();
}
while (ch >= '0' and ch <= '9') {
r = r * 10 + ch - '0', ch = getchar();
}
r *= f;
}
/// Constants
#define MAX 201005
#define MOD 1000000007
#define base 1000000007
#define eps 1e-9
#define INF 1llu << 61 // 2,305,843,009,213,693,952
#define inf (ll)1e18 // 536,870,912
#define PI acos(-1.0) // 3.1415926535897932
// #define INF 0x3f3f3f3f3f3f3f3f
// #define inf 0x3f3f3f3f
vi G[MAX];
bool use[MAX];
vector<pii> tmp;
map<pii, int> ans;
int main() {
#ifdef VAMP
clock_t tStart = clock();
freopen("C:\\Users\\raiha.DESKTOP-5M3GJRN\\Videos\\Raihan\\input.txt", "r",
stdin);
freopen("C:\\Users\\raiha.DESKTOP-5M3GJRN\\Videos\\Raihan\\output.txt", "w",
stdout);
#endif
int n, u, v;
si(n);
FOR(i, 1, n) {
sii(u, v);
G[u].pb(v);
G[v].pb(u);
tmp.pb(MP(u, v));
}
queue<int> q;
q.push(1);
use[1] = 1;
int k = 0;
vector<int> track(n, 0);
while (!q.empty()) {
int u = q.front();
q.pop();
if (k < sz(G[u]))
k = sz(G[u]);
int cur = 1;
for (auto v : G[u]) {
if (use[v])
continue;
if (cur == track[u])
cur++;
track[v] = ans[MP(u, v)] = ans[MP(v, u)] = cur;
use[v] = 1;
cur++;
q.push(v);
}
}
cout << k << endl;
for (auto x : tmp)
cout << ans[x] << endl;
#ifdef VAMP
printf("\n>>Runtime: %.10fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC);
#endif
return 0;
} | #include <bits/stdc++.h>
using namespace std;
/// Typedef
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define pb push_back
#define ppb pop_back
#define MP make_pair
#define ff first
#define ss second
#define sf scanf
#define pf printf
#define SQR(x) ((x) * (x))
#define loop(i, y) for (int i = 0; i < int(y); i++)
#define FOR(i, x, y) for (int i = int(x); i < int(y); i++)
#define ROF(i, x, y) for (int i = int(x); i >= int(y); i--)
#define all(c) c.begin(), c.end()
#define sz(c) int(c.size())
#define clr(x, y) memset(x, y, sizeof(x))
#define si(x) scanf("%d", &x)
#define sii(x, y) scanf("%d %d", &x, &y)
#define siii(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define sl(x) scanf("%lld", &x)
#define sll(x, y) scanf("%lld %lld", &x, &y)
#define slll(x, y, z) scanf("%lld %lld %lld", &x, &y, &z)
#ifdef VAMP
#define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cout << name << " = " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " = " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define dbg(...)
#endif
template <class T> inline T bigMod(T p, T e, T M) {
ll ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1)
ret = (ret * p) % M;
p = (p * p) % M;
}
return (T)ret;
}
template <class T> inline T modInverse(T a, T M) { return bigMod(a, M - 2, M); }
template <class T> inline T gcd(T a, T b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <class T> inline T lcm(T a, T b) {
a = abs(a);
b = abs(b);
return (a / gcd(a, b)) * b;
}
template <class T> inline string int2String(T a) {
ostringstream str;
str << a;
return str.str();
}
template <class T> inline T string2int(string a) {
stringstream str(a);
T b;
str >> b;
return b;
}
template <class T> inline void read(T &r) {
r = 0;
int f = 1;
char ch = getchar();
while (ch < '0' or ch > '9') {
f = (ch == '-' ? -1 : 1), ch = getchar();
}
while (ch >= '0' and ch <= '9') {
r = r * 10 + ch - '0', ch = getchar();
}
r *= f;
}
/// Constants
#define MAX 201005
#define MOD 1000000007
#define base 1000000007
#define eps 1e-9
#define INF 1llu << 61 // 2,305,843,009,213,693,952
#define inf (ll)1e18 // 536,870,912
#define PI acos(-1.0) // 3.1415926535897932
// #define INF 0x3f3f3f3f3f3f3f3f
// #define inf 0x3f3f3f3f
vi G[MAX];
bool use[MAX];
vector<pii> tmp;
map<pii, int> ans;
int main() {
#ifdef VAMP
clock_t tStart = clock();
freopen("C:\\Users\\raiha.DESKTOP-5M3GJRN\\Videos\\Raihan\\input.txt", "r",
stdin);
freopen("C:\\Users\\raiha.DESKTOP-5M3GJRN\\Videos\\Raihan\\output.txt", "w",
stdout);
#endif
int n, u, v;
si(n);
FOR(i, 1, n) {
sii(u, v);
G[u].pb(v);
G[v].pb(u);
tmp.pb(MP(u, v));
}
queue<int> q;
q.push(1);
use[1] = 1;
int k = 0;
vector<int> track(n + 5, 0);
while (!q.empty()) {
int u = q.front();
q.pop();
if (k < sz(G[u]))
k = sz(G[u]);
int cur = 1;
for (auto v : G[u]) {
if (use[v])
continue;
if (cur == track[u])
cur++;
track[v] = ans[MP(u, v)] = ans[MP(v, u)] = cur;
use[v] = 1;
cur++;
q.push(v);
}
}
cout << k << endl;
for (auto x : tmp)
cout << ans[x] << endl;
#ifdef VAMP
printf("\n>>Runtime: %.10fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC);
#endif
return 0;
} | replace | 126 | 127 | 126 | 127 | 0 | |
p02850 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 5;
int n;
vector<int> g[N];
vector<pair<int, int>> edge;
map<pair<int, int>, int> colorEdge;
bool used[N];
int c[N];
int main() {
#define TASK "test"
#ifndef ONLINE_JUDGE
freopen(TASK ".inp", "r", stdin);
freopen(TASK ".out", "w", stdout);
#endif
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
edge.push_back({u, v});
g[u].push_back(v);
g[v].push_back(u);
}
queue<int> q;
q.push(1);
used[1] = true;
int nColor = 0;
while (!q.empty()) {
int u = q.front();
q.pop();
nColor = max(nColor, (int)g[u].size());
int cur = 1;
for (auto v : g[u]) {
if (used[v])
continue;
if (cur == c[u])
cur++;
c[v] = colorEdge[{u, v}] = colorEdge[{v, u}] = cur++;
used[v] = true;
q.push(v);
}
}
cout << nColor << "\n";
for (auto e : edge)
cout << colorEdge[e] << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 5;
int n;
vector<int> g[N];
vector<pair<int, int>> edge;
map<pair<int, int>, int> colorEdge;
bool used[N];
int c[N];
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
edge.push_back({u, v});
g[u].push_back(v);
g[v].push_back(u);
}
queue<int> q;
q.push(1);
used[1] = true;
int nColor = 0;
while (!q.empty()) {
int u = q.front();
q.pop();
nColor = max(nColor, (int)g[u].size());
int cur = 1;
for (auto v : g[u]) {
if (used[v])
continue;
if (cur == c[u])
cur++;
c[v] = colorEdge[{u, v}] = colorEdge[{v, u}] = cur++;
used[v] = true;
q.push(v);
}
}
cout << nColor << "\n";
for (auto e : edge)
cout << colorEdge[e] << "\n";
return 0;
} | delete | 13 | 18 | 13 | 13 | 0 | |
p02850 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;
int n;
vector<int> g[100005];
vector<int> ans(100005);
map<P, int> mp;
int ans1;
void dfs(int v, int p = -1, int prev = -1) {
vector<int> k(ans1);
iota(k.begin(), k.end(), 0);
for (int i = 0; i < ans1; ++i) {
if (i == prev) {
k.erase(k.begin() + i);
break;
}
}
int pos = 0;
int li = ans1;
while (pos == prev || pos == li)
pos++;
for (int c : g[v]) {
if (c == p)
continue;
mp[P(c, v)] = pos;
mp[P(v, c)] = pos;
dfs(c, v, pos);
pos++;
while (pos == prev || pos == li)
pos++;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
vector<P> res(n - 1);
rep(i, n - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].push_back(b);
g[b].push_back(a);
res[i] = P(a, b);
}
ans1 = 0;
rep(i, n) maxs(ans1, int(g[i].size()));
printf("%d\n", ans1);
dfs(0);
rep(i, n - 1) { printf("%d\n", mp[res[i]] + 1); }
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;
int n;
vector<int> g[100005];
vector<int> ans(100005);
map<P, int> mp;
int ans1;
void dfs(int v, int p = -1, int prev = -1) {
int pos = 0;
int li = ans1;
while (pos == prev || pos == li)
pos++;
for (int c : g[v]) {
if (c == p)
continue;
mp[P(c, v)] = pos;
mp[P(v, c)] = pos;
dfs(c, v, pos);
pos++;
while (pos == prev || pos == li)
pos++;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
vector<P> res(n - 1);
rep(i, n - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].push_back(b);
g[b].push_back(a);
res[i] = P(a, b);
}
ans1 = 0;
rep(i, n) maxs(ans1, int(g[i].size()));
printf("%d\n", ans1);
dfs(0);
rep(i, n - 1) { printf("%d\n", mp[res[i]] + 1); }
return 0;
}
| delete | 21 | 29 | 21 | 21 | TLE | |
p02850 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
int fill_color(vector<vector<int>> &tree,
unordered_map<int, unordered_map<int, int>> &color, int parent,
int parent_color) {
int max_color = 0;
for (int i = 0; i < tree[parent].size(); i++) {
int current_color;
if (i + 1 < parent_color) {
current_color = i + 1;
} else {
current_color = i + 2;
}
int child = tree[parent][i];
color[parent][child] = current_color;
int submax_color = fill_color(tree, color, child, current_color);
if (max_color < current_color)
max_color = current_color;
if (max_color < submax_color)
max_color = submax_color;
}
return max_color;
}
int main() {
int n;
cin >> n;
vector<int> a(n - 1);
vector<int> b(n - 1);
vector<vector<int>> tree(n + 1);
unordered_map<int, unordered_map<int, int>> color;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
tree[a[i]].push_back(b[i]);
}
int max_color = fill_color(tree, color, 1, __INT_MAX__);
cout << max_color << endl;
for (int i = 0; i < n - 1; i++) {
cout << color[a[i]][b[i]] << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
int fill_color(vector<vector<int>> &tree,
unordered_map<int, unordered_map<int, int>> &color, int parent,
int parent_color) {
int max_color = 0;
for (int i = 0; i < tree[parent].size(); i++) {
int current_color;
if (i + 1 < parent_color) {
current_color = i + 1;
} else {
current_color = i + 2;
}
int child = tree[parent][i];
color[parent][child] = current_color;
int submax_color = fill_color(tree, color, child, current_color);
if (max_color < current_color)
max_color = current_color;
if (max_color < submax_color)
max_color = submax_color;
}
return max_color;
}
int main() {
int n;
cin >> n;
vector<int> a(n - 1);
vector<int> b(n - 1);
vector<vector<int>> tree(n + 1);
unordered_map<int, unordered_map<int, int>> color;
for (int i = 0; i < n - 1; i++) {
cin >> a[i] >> b[i];
tree[a[i]].push_back(b[i]);
}
int max_color = fill_color(tree, color, 1, __INT_MAX__);
cout << max_color << endl;
for (int i = 0; i < n - 1; i++) {
cout << color[a[i]][b[i]] << endl;
}
}
| replace | 38 | 39 | 38 | 39 | 0 | |
p02850 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for (ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rreps(i, e, n) for (ll i = (n)-1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// ifstream in("input.txt");
// cin.rdbuf(in.rdbuf());
ll n;
cin >> n;
vector<vector<pair<ll, ll>>> g(n);
rep(i, n - 1) {
ll a, b;
cin >> a >> b;
a--;
b--;
g[a].push_back(make_pair(b, i));
g[b].push_back(make_pair(a, i));
}
vector<ll> ans(n - 1, -1);
vector<set<ll>> color(n);
queue<ll> q;
q.push(0);
while (!q.empty()) {
ll v = q.front();
q.pop();
ll cur = 0;
for (auto x : g[v]) {
ll u = x.first, idx = x.second;
if (ans[idx] != -1)
continue;
reps(i, cur, n) {
if ((color[u].count(i) == 0) && (color[v].count(i) == 0)) {
color[u].insert(i);
color[v].insert(i);
ans[idx] = i;
q.push(u);
break;
}
}
}
}
printf("%lld\n", *max_element(all(ans)) + 1);
rep(i, n - 1) printf("%lld\n", ans[i] + 1);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for (ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rreps(i, e, n) for (ll i = (n)-1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// ifstream in("input.txt");
// cin.rdbuf(in.rdbuf());
ll n;
cin >> n;
vector<vector<pair<ll, ll>>> g(n);
rep(i, n - 1) {
ll a, b;
cin >> a >> b;
a--;
b--;
g[a].push_back(make_pair(b, i));
g[b].push_back(make_pair(a, i));
}
vector<ll> ans(n - 1, -1);
vector<set<ll>> color(n);
queue<ll> q;
q.push(0);
while (!q.empty()) {
ll v = q.front();
q.pop();
ll cur = 0;
for (auto x : g[v]) {
ll u = x.first, idx = x.second;
if (ans[idx] != -1)
continue;
reps(i, cur, n) {
if ((color[u].count(i) == 0) && (color[v].count(i) == 0)) {
cur = i + 1;
color[u].insert(i);
color[v].insert(i);
ans[idx] = i;
q.push(u);
break;
}
}
}
}
printf("%lld\n", *max_element(all(ans)) + 1);
rep(i, n - 1) printf("%lld\n", ans[i] + 1);
return 0;
}
| insert | 41 | 41 | 41 | 42 | TLE | |
p02850 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<set<int>>;
int main() {
int N;
cin >> N;
vector<int> A(N), B(N);
map<pair<int, int>, int> Edge;
Graph G(N + 1);
rep(i, N - 1) {
cin >> A.at(i) >> B.at(i);
Edge[make_pair(A.at(i), B.at(i))] = -1;
Edge[make_pair(B.at(i), A.at(i))] = -1;
G.at(A.at(i)).insert(B.at(i));
G.at(B.at(i)).insert(A.at(i));
}
int Colors = 1;
rep1(i, N + 1) Colors = max(Colors, (int)G.at(i).size());
cout << Colors << endl;
vector<bool> seen(N + 1, false);
queue<int> Q;
Q.push(1);
map<int, int> par;
while (!Q.empty()) {
int v = Q.front();
Q.pop();
seen.at(v) = true;
queue<int> CV;
int banned_num = -1;
if (v != 1) {
banned_num = Edge[make_pair(v, par[v])];
}
rep1(i, Colors + 1) {
if (i != banned_num)
CV.push(i);
}
for (auto nv : G.at(v)) {
if (seen.at(nv))
continue;
int edge_color = CV.front();
CV.pop();
Edge[make_pair(v, nv)] = edge_color;
Edge[make_pair(nv, v)] = edge_color;
par[nv] = v;
Q.push(nv);
}
}
rep(i, N - 1) cout << Edge[make_pair(A.at(i), B.at(i))] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<set<int>>;
int main() {
int N;
cin >> N;
vector<int> A(N), B(N);
map<pair<int, int>, int> Edge;
Graph G(N + 1);
rep(i, N - 1) {
cin >> A.at(i) >> B.at(i);
Edge[make_pair(A.at(i), B.at(i))] = -1;
Edge[make_pair(B.at(i), A.at(i))] = -1;
G.at(A.at(i)).insert(B.at(i));
G.at(B.at(i)).insert(A.at(i));
}
int Colors = 1;
rep1(i, N + 1) Colors = max(Colors, (int)G.at(i).size());
cout << Colors << endl;
vector<bool> seen(N + 1, false);
queue<int> Q;
Q.push(1);
map<int, int> par;
while (!Q.empty()) {
int v = Q.front();
Q.pop();
seen.at(v) = true;
queue<int> CV;
int banned_num = -1;
if (v != 1) {
banned_num = Edge[make_pair(v, par[v])];
}
rep1(i, (int)G.at(v).size() + 1) {
if (i != banned_num)
CV.push(i);
}
for (auto nv : G.at(v)) {
if (seen.at(nv))
continue;
int edge_color = CV.front();
CV.pop();
Edge[make_pair(v, nv)] = edge_color;
Edge[make_pair(nv, v)] = edge_color;
par[nv] = v;
Q.push(nv);
}
}
rep(i, N - 1) cout << Edge[make_pair(A.at(i), B.at(i))] << endl;
}
| replace | 41 | 42 | 41 | 42 | TLE | |
p02850 | 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>;
struct Edge {
int to, id;
};
vector<vector<Edge>> g;
vector<int> ans;
void dfs(int v, int c = -1, int p = -1) {
int k = 1;
rep(i, g[v].size()) {
int u = g[v][i].to, ei = g[v][i].id;
if (u == p)
continue;
if (k == c)
k++;
ans[ei] = k;
k++;
dfs(u, ans[ei], v);
}
}
int main() {
int n;
cin >> n;
ans = vector<int>(n - 1);
rep(i, n - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].push_back((Edge){b, i});
g[b].push_back((Edge){a, i});
}
dfs(0);
int mx = 0;
rep(i, n) mx = max(mx, (int)g[i].size());
cout << mx << endl;
rep(i, n - 1) cout << ans[i] << 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 P = pair<int, int>;
struct Edge {
int to, id;
};
vector<vector<Edge>> g;
vector<int> ans;
void dfs(int v, int c = -1, int p = -1) {
int k = 1;
rep(i, g[v].size()) {
int u = g[v][i].to, ei = g[v][i].id;
if (u == p)
continue;
if (k == c)
k++;
ans[ei] = k;
k++;
dfs(u, ans[ei], v);
}
}
int main() {
int n;
cin >> n;
g.resize(n);
ans = vector<int>(n - 1);
rep(i, n - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].push_back((Edge){b, i});
g[b].push_back((Edge){a, i});
}
dfs(0);
int mx = 0;
rep(i, n) mx = max(mx, (int)g[i].size());
cout << mx << endl;
rep(i, n - 1) cout << ans[i] << endl;
return 0;
} | insert | 30 | 30 | 30 | 31 | -11 | |
p02850 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep(i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#ifdef LOCAL
#include "../../Lib/cout_container.hpp"
#define debug(x) cout << #x " => " << (x) << endl
#else
#define debug(x) 0
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace {
struct INIT {
INIT() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
} INIT;
} // namespace
namespace std {
template <typename A, typename B> struct hash<pair<A, B>> {
size_t operator()(const pair<A, B> &p) const {
const static size_t rand_seed = random_device()() + 0x9e3779b9;
size_t seed = rand_seed;
seed ^= hash<A>()(p.first) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= hash<B>()(p.first) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
return seed;
}
};
} // namespace std
using Weight = int;
struct Edge {
int src, dst;
Weight weight;
Edge(void) {}
Edge(int src, int dst) : src(src), dst(dst) {}
Edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
void edges_to_graph(Graph &graph, const Edges &edges, const int vertices,
const bool directed = true) {
graph.clear(), graph.resize(vertices);
for (const auto &e : edges)
graph[e.src].emplace_back(e);
if (!directed)
for (const auto &e : edges)
graph[e.dst].emplace_back(Edge(e.dst, e.src, e.weight));
}
void dfs(Graph &g, int v, int p, int prev_col,
unordered_map<pair<int, int>, int> &cmap) {
int col = 0;
for (const auto &e : g[v]) {
if (e.dst == p)
continue;
++col;
if (col == prev_col)
++col;
cmap[{v, e.dst}] = col;
dfs(g, e.dst, v, col, cmap);
}
}
void bfs(Graph &g, unordered_map<pair<int, int>, int> &cmap) {
queue<tuple<int, int, int>> que;
que.push(make_tuple(0, -1, 0));
while (!que.empty()) {
int v = get<0>(que.front()), p = get<1>(que.front()),
pc = get<2>(que.front());
que.pop();
int col = 1;
for (const auto &e : g[v]) {
if (e.dst == p)
continue;
if (col == pc)
++col;
cmap[{v, e.dst}] = col;
que.push(make_tuple(e.dst, v, col));
++col;
}
}
}
Graph graph;
int main(void) {
int n;
cin >> n;
Edges edges(n - 1);
rep(i, n - 1) {
int a, b;
cin >> a >> b;
edges[i] = {--a, --b, 0};
}
edges_to_graph(graph, edges, n, false);
int maxi = 0;
rep(i, n) maxi = max(maxi, (int)graph[i].size());
unordered_map<pair<int, int>, int> cmap;
// dfs(graph, 0, -1, 0, cmap);
bfs(graph, cmap);
cout << maxi << "\n";
rep(i, n - 1) cout << cmap[{edges[i].src, edges[i].dst}] << "\n";
return 0;
} | #include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep(i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#ifdef LOCAL
#include "../../Lib/cout_container.hpp"
#define debug(x) cout << #x " => " << (x) << endl
#else
#define debug(x) 0
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace {
struct INIT {
INIT() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
} INIT;
} // namespace
namespace std {
template <typename A, typename B> struct hash<pair<A, B>> {
size_t operator()(const pair<A, B> &p) const {
const static size_t rand_seed = random_device()() + 0x9e3779b9;
size_t seed = rand_seed;
seed ^= hash<A>()(p.first) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= hash<B>()(p.second) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
return seed;
}
};
} // namespace std
using Weight = int;
struct Edge {
int src, dst;
Weight weight;
Edge(void) {}
Edge(int src, int dst) : src(src), dst(dst) {}
Edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
void edges_to_graph(Graph &graph, const Edges &edges, const int vertices,
const bool directed = true) {
graph.clear(), graph.resize(vertices);
for (const auto &e : edges)
graph[e.src].emplace_back(e);
if (!directed)
for (const auto &e : edges)
graph[e.dst].emplace_back(Edge(e.dst, e.src, e.weight));
}
void dfs(Graph &g, int v, int p, int prev_col,
unordered_map<pair<int, int>, int> &cmap) {
int col = 0;
for (const auto &e : g[v]) {
if (e.dst == p)
continue;
++col;
if (col == prev_col)
++col;
cmap[{v, e.dst}] = col;
dfs(g, e.dst, v, col, cmap);
}
}
void bfs(Graph &g, unordered_map<pair<int, int>, int> &cmap) {
queue<tuple<int, int, int>> que;
que.push(make_tuple(0, -1, 0));
while (!que.empty()) {
int v = get<0>(que.front()), p = get<1>(que.front()),
pc = get<2>(que.front());
que.pop();
int col = 1;
for (const auto &e : g[v]) {
if (e.dst == p)
continue;
if (col == pc)
++col;
cmap[{v, e.dst}] = col;
que.push(make_tuple(e.dst, v, col));
++col;
}
}
}
Graph graph;
int main(void) {
int n;
cin >> n;
Edges edges(n - 1);
rep(i, n - 1) {
int a, b;
cin >> a >> b;
edges[i] = {--a, --b, 0};
}
edges_to_graph(graph, edges, n, false);
int maxi = 0;
rep(i, n) maxi = max(maxi, (int)graph[i].size());
unordered_map<pair<int, int>, int> cmap;
// dfs(graph, 0, -1, 0, cmap);
bfs(graph, cmap);
cout << maxi << "\n";
rep(i, n - 1) cout << cmap[{edges[i].src, edges[i].dst}] << "\n";
return 0;
} | replace | 38 | 39 | 38 | 39 | TLE | |
p02850 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 10007;
const int INF = LLONG_MAX / 3;
const int MAX = 710000;
/*-----Library-----*/
struct UnionFind {
vector<int> par; // 親ノード
vector<int> rank; // ランク
vector<int> sizeuf; // 要素数
UnionFind(int n = 1) { init(n); }
void init(int n = 1) {
par.resize(n);
rank.resize(n);
sizeuf.resize(n);
for (int i = 0; i < n; ++i) {
par[i] = i;
rank[i] = 0;
sizeuf[i] = 1;
}
}
int root(int x) {
if (par[x] == x) {
return x;
} else {
int r = root(par[x]);
return par[x] = r;
}
}
bool issame(int x, int y) { return root(x) == root(y); }
bool merge(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (rank[x] < rank[y])
swap(x, y);
if (rank[x] == rank[y])
++rank[x];
par[y] = x;
sizeuf[x] += sizeuf[y];
return true;
}
int size(int x) { return sizeuf[root(x)]; }
};
long long gcd(long long a, long long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
long long lcm(long long i, long long j) { return i * (j / gcd(i, j)); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*-----Library-----*/
vector<int> es[110000];
map<pair<int, int>, int> c;
bool reached[110000] = {};
void dfs(int s, int co) {
reached[s] = true;
int cnt = 1;
for (int i = 0; i < es[s].size(); i++) {
if (reached[es[s][i]] == true)
continue;
if (cnt == co)
cnt++;
c[P(s, es[s][i])] = cnt;
c[P(es[s][i], s)] = cnt;
dfs(es[s][i], cnt);
cnt++;
}
}
signed main() {
int n;
cin >> n;
int cnt[110000] = {};
P t[11000];
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
cnt[a - 1]++;
cnt[b - 1]++;
es[a - 1].push_back(b - 1);
es[b - 1].push_back(a - 1);
t[i] = P(a - 1, b - 1);
}
int k = 0;
for (int i = 0; i < n; i++) {
k = max(k, cnt[i]);
}
cout << k << endl;
dfs(0, 0);
for (int i = 0; i < n - 1; i++) {
cout << c[P(t[i].first, t[i].second)] << endl;
}
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 10007;
const int INF = LLONG_MAX / 3;
const int MAX = 710000;
/*-----Library-----*/
struct UnionFind {
vector<int> par; // 親ノード
vector<int> rank; // ランク
vector<int> sizeuf; // 要素数
UnionFind(int n = 1) { init(n); }
void init(int n = 1) {
par.resize(n);
rank.resize(n);
sizeuf.resize(n);
for (int i = 0; i < n; ++i) {
par[i] = i;
rank[i] = 0;
sizeuf[i] = 1;
}
}
int root(int x) {
if (par[x] == x) {
return x;
} else {
int r = root(par[x]);
return par[x] = r;
}
}
bool issame(int x, int y) { return root(x) == root(y); }
bool merge(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (rank[x] < rank[y])
swap(x, y);
if (rank[x] == rank[y])
++rank[x];
par[y] = x;
sizeuf[x] += sizeuf[y];
return true;
}
int size(int x) { return sizeuf[root(x)]; }
};
long long gcd(long long a, long long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
long long lcm(long long i, long long j) { return i * (j / gcd(i, j)); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*-----Library-----*/
vector<int> es[110000];
map<pair<int, int>, int> c;
bool reached[110000] = {};
void dfs(int s, int co) {
reached[s] = true;
int cnt = 1;
for (int i = 0; i < es[s].size(); i++) {
if (reached[es[s][i]] == true)
continue;
if (cnt == co)
cnt++;
c[P(s, es[s][i])] = cnt;
c[P(es[s][i], s)] = cnt;
dfs(es[s][i], cnt);
cnt++;
}
}
signed main() {
int n;
cin >> n;
int cnt[110000] = {};
P t[110000];
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
cnt[a - 1]++;
cnt[b - 1]++;
es[a - 1].push_back(b - 1);
es[b - 1].push_back(a - 1);
t[i] = P(a - 1, b - 1);
}
int k = 0;
for (int i = 0; i < n; i++) {
k = max(k, cnt[i]);
}
cout << k << endl;
dfs(0, 0);
for (int i = 0; i < n - 1; i++) {
cout << c[P(t[i].first, t[i].second)] << endl;
}
return 0;
}
| replace | 125 | 126 | 125 | 126 | 0 | |
p02850 | C++ | Runtime Error | #include <iostream>
#include <queue>
#include <vector>
using namespace std;
int N;
int a[150000];
int b[150000];
int i, j;
queue<pair<int, int>> que;
pair<int, int> p;
int main() {
vector<int> v[100000];
int cnt[100000];
int c[100000];
int s = 1;
cin >> N;
for (i = 0; i < N; i++) {
cnt[i] = 0;
c[i] = 0;
}
for (i = 0; i < N - 1; i++) {
cin >> a[i] >> b[i];
cnt[a[i] - 1]++;
cnt[b[i] - 1]++;
v[a[i]].push_back(i);
v[b[i]].push_back(i);
}
int k = 0;
for (i = 0; i < N; i++) {
k = max(k, cnt[i]);
}
int color = 1;
for (i = 0; i < N - 1; i++) {
if (a[i] == s) {
que.push(make_pair(i, b[i]));
c[i] = color;
color++;
}
}
while (!que.empty()) {
color = 1;
p = que.front();
que.pop();
for (i = 0; i < v[p.second].size(); i++) {
if (color == c[p.first])
color++;
int t = v[p.second][i];
if (a[t] == p.second && c[t] == 0) {
que.push(make_pair(t, b[t]));
c[t] = color;
color++;
}
if (b[t] == p.second && c[t] == 0) {
que.push(make_pair(i, a[i]));
c[t] = color;
color++;
}
}
}
cout << k << endl;
for (i = 0; i < N - 1; i++)
cout << c[i] << endl;
}
| #include <iostream>
#include <queue>
#include <vector>
using namespace std;
int N;
int a[150000];
int b[150000];
int i, j;
queue<pair<int, int>> que;
pair<int, int> p;
int main() {
vector<int> v[100005];
int cnt[100000];
int c[100000];
int s = 1;
cin >> N;
for (i = 0; i < N; i++) {
cnt[i] = 0;
c[i] = 0;
}
for (i = 0; i < N - 1; i++) {
cin >> a[i] >> b[i];
cnt[a[i] - 1]++;
cnt[b[i] - 1]++;
v[a[i]].push_back(i);
v[b[i]].push_back(i);
}
int k = 0;
for (i = 0; i < N; i++) {
k = max(k, cnt[i]);
}
int color = 1;
for (i = 0; i < N - 1; i++) {
if (a[i] == s) {
que.push(make_pair(i, b[i]));
c[i] = color;
color++;
}
}
while (!que.empty()) {
color = 1;
p = que.front();
que.pop();
for (i = 0; i < v[p.second].size(); i++) {
if (color == c[p.first])
color++;
int t = v[p.second][i];
if (a[t] == p.second && c[t] == 0) {
que.push(make_pair(t, b[t]));
c[t] = color;
color++;
}
if (b[t] == p.second && c[t] == 0) {
que.push(make_pair(i, a[i]));
c[t] = color;
color++;
}
}
}
cout << k << endl;
for (i = 0; i < N - 1; i++)
cout << c[i] << endl;
}
| replace | 13 | 14 | 13 | 14 | 0 | |
p02850 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n - 1), b(n - 1);
vector<queue<int>> edge(n);
for (int i = 0; i < n - 1; i++) {
cin >> a[i] >> b[i];
--a[i];
--b[i];
edge[a[i]].push(i);
edge[b[i]].push(i);
}
int ans = 0; // 塗られた色の種類数
vector<int> ANS(n - 1, 0); // 各辺に塗る色,0のときは未訪問
vector<set<int>> colors(n); // 各頂点を端点とする辺に塗られた色の集合
queue<int> st; // 訪問待ちの頂点
st.push(a[0]);
colors[a[0]].insert(1);
colors[b[0]].insert(1);
while (st.size()) {
int v = st.front();
st.pop();
while (edge[v].size()) {
int i = edge[v].front();
edge[v].pop();
if (ANS[i] == 0 && (v == a[i] || v == b[i])) {
// 訪問待ちの頂点を追加
if (v == a[i]) {
st.push(b[i]);
} else {
st.push(a[i]);
}
// 色の決定
for (int j = 1; j <= ans; j++) {
if (colors[a[i]].find(j) == colors[a[i]].end() &&
colors[b[i]].find(j) == colors[b[i]].end()) {
ANS[i] = j;
colors[a[i]].insert(j);
colors[b[i]].insert(j);
break;
}
}
if (ANS[i] == 0) {
ans++;
ANS[i] = ans;
colors[a[i]].insert(ans);
colors[b[i]].insert(ans);
}
}
}
}
cout << ans << endl;
for (int i = 0; i < n - 1; i++) {
cout << ANS[i] << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n - 1), b(n - 1);
vector<queue<int>> edge(n);
for (int i = 0; i < n - 1; i++) {
cin >> a[i] >> b[i];
--a[i];
--b[i];
edge[a[i]].push(i);
edge[b[i]].push(i);
}
int ans = 0; // 塗られた色の種類数
vector<int> ANS(n - 1, 0); // 各辺に塗る色,0のときは未訪問
vector<set<int>> colors(n); // 各頂点を端点とする辺に塗られた色の集合
queue<int> st; // 訪問待ちの頂点
st.push(a[0]);
colors[a[0]].insert(1);
colors[b[0]].insert(1);
while (st.size()) {
int v = st.front();
st.pop();
while (edge[v].size()) {
int i = edge[v].front();
edge[v].pop();
if (ANS[i] == 0 && (v == a[i] || v == b[i])) {
// 訪問待ちの頂点を追加
if (v == a[i]) {
st.push(b[i]);
} else {
st.push(a[i]);
}
// 色の決定
if (colors[a[i]].size() == ans || colors[b[i]].size() == ans) {
ans++;
ANS[i] = ans;
colors[a[i]].insert(ans);
colors[b[i]].insert(ans);
continue;
}
for (int j = 1; j <= ans; j++) {
if (colors[a[i]].find(j) == colors[a[i]].end() &&
colors[b[i]].find(j) == colors[b[i]].end()) {
ANS[i] = j;
colors[a[i]].insert(j);
colors[b[i]].insert(j);
break;
}
}
if (ANS[i] == 0) {
ans++;
ANS[i] = ans;
colors[a[i]].insert(ans);
colors[b[i]].insert(ans);
}
}
}
}
cout << ans << endl;
for (int i = 0; i < n - 1; i++) {
cout << ANS[i] << endl;
}
return 0;
} | insert | 43 | 43 | 43 | 50 | TLE | |
p02850 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
struct Edge {
int next;
int to;
int color;
} edge[100005];
int head[100005], cnt, m[100005], ans, n;
void add(int u, int v) {
edge[++cnt].next = head[u];
edge[cnt].to = v;
head[u] = cnt;
}
void dfs(int x, int fa) {
// cout<<x<<endl;
int us = 1, ban = 0;
for (int i = head[x]; i; i = edge[i].next) {
if (edge[i].to == fa) {
// cout<<i<<endl;
ban = edge[i].color;
break;
}
}
// cout<<x<<' '<<ban<<endl;
for (int i = head[x]; i; i = edge[i].next) {
if (edge[i].to == fa)
continue; // cout<<x<<' '<<us<<endl;
if (us == ban)
us++;
edge[i].color = edge[i + 1].color = us;
dfs(edge[i].to, x);
us++;
}
}
int main() {
cin >> n;
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
if (u > v)
swap(u, v);
add(u, v);
add(v, u);
m[u]++;
m[v]++;
}
for (int i = 1; i <= n; i++) {
// t[i]=m[i];
ans = max(ans, m[i]);
}
cout << ans << endl;
dfs(1, 0);
for (int i = 1; i <= 2 * (n - 1); i += 2)
cout << edge[i].color << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
struct Edge {
int next;
int to;
int color;
} edge[200005];
int head[100005], cnt, m[100005], ans, n;
void add(int u, int v) {
edge[++cnt].next = head[u];
edge[cnt].to = v;
head[u] = cnt;
}
void dfs(int x, int fa) {
// cout<<x<<endl;
int us = 1, ban = 0;
for (int i = head[x]; i; i = edge[i].next) {
if (edge[i].to == fa) {
// cout<<i<<endl;
ban = edge[i].color;
break;
}
}
// cout<<x<<' '<<ban<<endl;
for (int i = head[x]; i; i = edge[i].next) {
if (edge[i].to == fa)
continue; // cout<<x<<' '<<us<<endl;
if (us == ban)
us++;
edge[i].color = edge[i + 1].color = us;
dfs(edge[i].to, x);
us++;
}
}
int main() {
cin >> n;
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
if (u > v)
swap(u, v);
add(u, v);
add(v, u);
m[u]++;
m[v]++;
}
for (int i = 1; i <= n; i++) {
// t[i]=m[i];
ans = max(ans, m[i]);
}
cout << ans << endl;
dfs(1, 0);
for (int i = 1; i <= 2 * (n - 1); i += 2)
cout << edge[i].color << endl;
return 0;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p02850 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
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;
}
using Edge = pair<int, int>; // (隣接頂点, 辺番号)
using Graph = vector<Edge>;
int N;
int main() {
cin >> N;
Graph G[N];
for (int i = 0; i < N - 1; ++i) {
int a, b;
cin >> a >> b;
--a, --b;
G[a].push_back(Edge(b, -1));
G[b].push_back(Edge(a, -1));
}
int max_color = 0;
for (int i = 0; i < N; ++i)
chmax(max_color, (int)G[i].size());
vector<int> res(N - 1, -1);
vector<int> dist(N, -1);
queue<pair<int, int>> que; // (頂点, 前回の色)
que.push({0, -1});
dist[0] = 0;
while (!que.empty()) {
auto p = que.front();
que.pop();
int v = p.first, c = p.second;
int color = 1;
if (color == c)
++color;
for (auto e : G[v]) {
if (dist[e.first] == -1) {
dist[e.first] = dist[v] + 1;
que.push({e.first, color});
res[e.second] = color;
++color;
if (color == c)
++color;
}
}
}
cout << max_color << endl;
for (auto v : res)
cout << v << endl;
}
| #include <bits/stdc++.h>
using namespace std;
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;
}
using Edge = pair<int, int>; // (隣接頂点, 辺番号)
using Graph = vector<Edge>;
int N;
int main() {
cin >> N;
Graph G[N];
for (int i = 0; i < N - 1; ++i) {
int a, b;
cin >> a >> b;
--a, --b;
G[a].push_back(Edge(b, i));
G[b].push_back(Edge(a, i));
}
int max_color = 0;
for (int i = 0; i < N; ++i)
chmax(max_color, (int)G[i].size());
vector<int> res(N - 1, -1);
vector<int> dist(N, -1);
queue<pair<int, int>> que; // (頂点, 前回の色)
que.push({0, -1});
dist[0] = 0;
while (!que.empty()) {
auto p = que.front();
que.pop();
int v = p.first, c = p.second;
int color = 1;
if (color == c)
++color;
for (auto e : G[v]) {
if (dist[e.first] == -1) {
dist[e.first] = dist[v] + 1;
que.push({e.first, color});
res[e.second] = color;
++color;
if (color == c)
++color;
}
}
}
cout << max_color << endl;
for (auto v : res)
cout << v << endl;
}
| replace | 28 | 30 | 28 | 30 | -6 | double free or corruption (out)
|
p02850 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 1; i <= (n); i++)
typedef long long ll;
typedef pair<int, int> pii;
int main() {
int n;
cin >> n;
vector<vector<int>> G(n);
vector<pii> vp;
rep(i, n) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].emplace_back(b);
G[b].emplace_back(a);
vp.emplace_back(a, b);
}
int K = 0;
vector<int> cs(n, 0);
vector<int> used(n, 0);
used[0] = 1;
map<pii, int> I;
queue<int> que;
que.emplace(0);
while (!que.empty()) {
int v = que.front();
que.pop();
if (K < (int)G[v].size())
K = G[v].size();
int cur = 1;
for (int u : G[v]) {
if (used[u])
continue;
if (cs[v] == cur)
cur++;
cs[u] = I[make_pair(u, v)] = I[make_pair(v, u)] = cur;
cur++;
used[u] = 1;
que.emplace(u);
}
}
cout << K << endl;
for (auto p : vp)
cout << I[p] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 1; i <= (n); i++)
typedef long long ll;
typedef pair<int, int> pii;
int main() {
int n;
cin >> n;
vector<vector<int>> G(n);
vector<pii> vp;
for (int i = 1; i < n; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].emplace_back(b);
G[b].emplace_back(a);
vp.emplace_back(a, b);
}
int K = 0;
vector<int> cs(n, 0);
vector<int> used(n, 0);
used[0] = 1;
map<pii, int> I;
queue<int> que;
que.emplace(0);
while (!que.empty()) {
int v = que.front();
que.pop();
if (K < (int)G[v].size())
K = G[v].size();
int cur = 1;
for (int u : G[v]) {
if (used[u])
continue;
if (cs[v] == cur)
cur++;
cs[u] = I[make_pair(u, v)] = I[make_pair(v, u)] = cur;
cur++;
used[u] = 1;
que.emplace(u);
}
}
cout << K << endl;
for (auto p : vp)
cout << I[p] << endl;
return 0;
} | replace | 13 | 14 | 13 | 14 | 0 | |
p02850 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end() // 昇順ソート
#define rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define FastIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
typedef long long ll;
typedef long long int lli;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
int main() {
int n;
cin >> n;
vector<vector<int>> g(n + 1);
vector<pair<int, int>> ab(n - 1);
rep(i, n - 1) {
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
ab[i] = make_pair(a, b);
}
map<pair<int, int>, int> cols;
vector<int> pre(n, -1);
queue<int> q;
q.push(ab[0].first);
int maxCol = 0;
while (!q.empty()) {
int v = q.front();
q.pop();
int col = 1;
int vp = pre[v];
int usedCol = cols[make_pair(v, vp)];
for (int vc : g[v]) {
pair<int, int> vvc, vcv;
vvc = make_pair(v, vc);
vcv = make_pair(vc, v);
if (cols[vvc] != 0 || cols[vcv] != 0)
continue;
if (col == usedCol)
col++;
cols[vvc] = cols[vcv] = col;
col++;
pre[vc] = v;
q.push(vc);
}
maxCol = max(maxCol, col - 1);
}
cout << maxCol << endl;
rep(i, n - 1) { cout << cols[ab[i]] << endl; }
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end() // 昇順ソート
#define rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define FastIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
typedef long long ll;
typedef long long int lli;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
int main() {
int n;
cin >> n;
vector<vector<int>> g(n + 1);
vector<pair<int, int>> ab(n - 1);
rep(i, n - 1) {
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
ab[i] = make_pair(a, b);
}
map<pair<int, int>, int> cols;
vector<int> pre(n + 1, -1);
queue<int> q;
q.push(ab[0].first);
int maxCol = 0;
while (!q.empty()) {
int v = q.front();
q.pop();
int col = 1;
int vp = pre[v];
int usedCol = cols[make_pair(v, vp)];
for (int vc : g[v]) {
pair<int, int> vvc, vcv;
vvc = make_pair(v, vc);
vcv = make_pair(vc, v);
if (cols[vvc] != 0 || cols[vcv] != 0)
continue;
if (col == usedCol)
col++;
cols[vvc] = cols[vcv] = col;
col++;
pre[vc] = v;
q.push(vc);
}
maxCol = max(maxCol, col - 1);
}
cout << maxCol << endl;
rep(i, n - 1) { cout << cols[ab[i]] << endl; }
} | replace | 41 | 42 | 41 | 42 | 0 | |
p02850 | C++ | Runtime Error | #include <bits/stdc++.h>
// #include <ext/numeric>
using namespace std;
// using namespace __gnu_cxx;
const int MAXN = (int)1e5 + 5;
vector<int> adjList[MAXN];
int mx = 0;
map<pair<int, int>, int> mp;
int getColor(int u, int v) {
if (u > v)
swap(u, v);
return mp[{u, v}];
}
int setColor(int u, int v, int color) {
if (u > v)
swap(u, v);
mp[{u, v}] = color;
}
void dfs(int u, int par) {
int c = 1;
int come = getColor(u, par);
for (int v : adjList[u]) {
if (v == par)
continue;
if (c == come)
++c;
setColor(u, v, c);
++c;
dfs(v, u);
}
mx = max(mx, max(c - 1, come));
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10),
cout << fixed;
int n;
cin >> n;
vector<pair<int, int>> edges;
for (int i = 1; i < n; ++i) {
int u, v;
cin >> u >> v;
adjList[u].push_back(v);
adjList[v].push_back(u);
edges.push_back({u, v});
}
dfs(1, 0);
cout << mx << '\n';
for (auto e : edges) {
cout << getColor(e.first, e.second) << '\n';
}
return 0;
} | #include <bits/stdc++.h>
// #include <ext/numeric>
using namespace std;
// using namespace __gnu_cxx;
const int MAXN = (int)1e5 + 5;
vector<int> adjList[MAXN];
int mx = 0;
map<pair<int, int>, int> mp;
int getColor(int u, int v) {
if (u > v)
swap(u, v);
return mp[{u, v}];
}
void setColor(int u, int v, int color) {
if (u > v)
swap(u, v);
mp[{u, v}] = color;
}
void dfs(int u, int par) {
int c = 1;
int come = getColor(u, par);
for (int v : adjList[u]) {
if (v == par)
continue;
if (c == come)
++c;
setColor(u, v, c);
++c;
dfs(v, u);
}
mx = max(mx, max(c - 1, come));
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10),
cout << fixed;
int n;
cin >> n;
vector<pair<int, int>> edges;
for (int i = 1; i < n; ++i) {
int u, v;
cin >> u >> v;
adjList[u].push_back(v);
adjList[v].push_back(u);
edges.push_back({u, v});
}
dfs(1, 0);
cout << mx << '\n';
for (auto e : edges) {
cout << getColor(e.first, e.second) << '\n';
}
return 0;
} | replace | 17 | 18 | 17 | 18 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.