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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02934 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, sum = 0;
cin >> n;
double a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
sum = sum + (1 / a[i]);
}
cout << 1 / sum << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
double sum = 0.0;
cin >> n;
double a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
sum = sum + (1 / a[i]);
}
cout << 1 / sum << endl;
}
| replace | 3 | 4 | 3 | 5 | 0 | |
p02934 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
size_t N;
std::cin >> N;
assert(N <= 100);
std::vector<double> A(N);
for (auto &ai : A)
std::cin >> ai;
double res = 0;
for (auto ai : A)
res += 1.0 / ai;
res = 1.0 / res;
std::cout << std::fixed << std::setprecision(65252854) << res << std::endl;
}
| #include <algorithm>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
size_t N;
std::cin >> N;
assert(N <= 100);
std::vector<double> A(N);
for (auto &ai : A)
std::cin >> ai;
double res = 0;
for (auto ai : A)
res += 1.0 / ai;
res = 1.0 / res;
std::cout << std::fixed << std::setprecision(65200000) << res << std::endl;
}
| replace | 29 | 30 | 29 | 30 | TLE | |
p02934 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int n;
double a[101], b[101];
cin >> n;
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
b[i] = 1 / a[i];
sum += b[i];
}
cout << 1 / sum << endl;
return 0;
} | #include <iostream>
using namespace std;
int main() {
int n;
double a[101], b[101];
cin >> n;
double sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
b[i] = 1 / a[i];
sum += b[i];
}
cout << 1 / sum << endl;
return 0;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p02934 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
size_t N;
std::cin >> N;
assert(N <= 100);
std::vector<double> A(N);
for (auto &ai : A)
std::cin >> ai;
double res = 0;
for (auto ai : A)
res += 1.0 / ai;
res = 1.0 / res;
std::cout << std::fixed << std::setprecision(75000000) << res << std::endl;
} | #include <algorithm>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
size_t N;
std::cin >> N;
assert(N <= 100);
std::vector<double> A(N);
for (auto &ai : A)
std::cin >> ai;
double res = 0;
for (auto ai : A)
res += 1.0 / ai;
res = 1.0 / res;
std::cout << std::fixed << std::setprecision(10000000) << res << std::endl;
}
| replace | 29 | 30 | 29 | 30 | TLE | |
p02934 | C++ | Runtime Error | #include <bits/stdc++.h>
#define MOD 1000000007
#define MAX 10005
#define int long long
#define T \
int t; \
cin >> t; \
while (t--)
#define f(i, a, b) for (int i = a; i < b; i++)
#define debug(x) cout << x = << x << n;
#define set_dp(dp) memset(dp, -1, sizeof(dp))
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
vector<int> v(n);
f(i, 0, n) cin >> v[i];
float ans = v[0];
f(i, 1, n) { ans = (ans * v[i]) / (ans + v[i]); }
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
#define MOD 1000000007
#define MAX 10005
#define int long long
#define T \
int t; \
cin >> t; \
while (t--)
#define f(i, a, b) for (int i = a; i < b; i++)
#define debug(x) cout << x = << x << n;
#define set_dp(dp) memset(dp, -1, sizeof(dp))
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> v(n);
f(i, 0, n) cin >> v[i];
float ans = v[0];
f(i, 1, n) { ans = (ans * v[i]) / (ans + v[i]); }
cout << ans;
return 0;
}
| replace | 17 | 21 | 17 | 18 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p02934 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int sum = 0;
int n = 0;
cin >> n;
rep(i, n) {
double A = 0;
cin >> A;
sum += 1 / A;
}
cout << 1 / sum << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
double sum = 0;
int n = 0;
cin >> n;
rep(i, n) {
double A = 0;
cin >> A;
sum += 1 / A;
}
cout << 1 / sum << endl;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p02934 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define pb push_back
#define rep(i, a, b, c) for (ll i = (a); i <= (b); i += (c))
#define repb(i, a, b, c) for (ll i = (a); i >= (b); i -= (c))
#define MOD 1000000007
#define ld long double
#define mp make_pair
#define vpll vector<pair<ll, ll>>
#define vll vector<ll>
#define vld vector<ld>
#define vvll vector<vector<ll>>
#define vvld vector<vector<ld>>
#define pll pair<ll, ll>
#define pqll priority_queue<ll>
#define mll map<ll, ll>
#define mlc map<ll, char>
#define um unordered_map
#define umll um<ll, ll>
#define umlc um<ll, char>
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define ln cout << "\n";
#define endl "\n"
#define test \
ll T; \
cin >> T; \
while (T--)
#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define show(w, size) \
for (ll i = 0; i < size; i++) \
cout << w[i] << " ";
#define print(a) cout << a << "\n";
#define mset(dp, no) memset(dp, no, sizeof(dp))
#define input(a, n) rep(i, 0, n - 1, 1) cin >> a[i];
#define countbit __builtin_popcount // Number of setbits in decimal notation
#define fbo(k) \
find_by_order(k) // Valid for ordered set //Number of items
// strictly smaller than k
#define ook(k) \
order_of_key(k) // Valid for ordered set //K-th element in a
// set (counting from zero)
#define lb(v, val) lower_bound(all(v), val) - v.begin()
#define ub(v, val) upper_bound(all(v), val) - v.begin()
#define in insert
#define SS stringstream
// #define db(x) cout <<#x<<": "<<x<<'\n';
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
ll gcd(ll a, ll b) {
if (a < b)
return gcd(b, a);
else if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll isPrime(ll n) {
ll p = (ll)sqrt(n);
rep(i, 2, p, 1) if (n % i == 0) return 0;
return 1;
} // reuturn 1 if prime
ll pow(ll b, ll e) {
if (e == 0)
return 1;
else if (e % 2 == 0) {
ll a = pow(b, e / 2);
return a * a;
} else {
ll a = pow(b, e / 2);
return b * a * a;
}
}
ll powm(ll x, ll y, ll m = MOD) {
x = x % m;
ll res = 1;
while (y) {
if (y & 1)
res = res * x;
res %= m;
y = y >> 1;
x = x * x;
x %= m;
}
return res;
}
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll modInverse(ll a, ll m) { return powm(a, m - 2, m); }
bool issq(ll n) {
ll p = sqrt(n);
return p * p == n;
}
vll prime;
void seive(ll n) {
prime.resize(n + 1, 1);
prime[0] = 0, prime[1] = 0;
for (ll i = 2; i * i <= n; i++)
if (prime[i])
for (ll j = i * i; j <= n; j += i)
prime[j] = 0;
}
ll extended_GCD(ll a, ll b, ll &x, ll &y) {
if (a == 0) {
x = 0;
y = 1;
return b;
}
ll x1, y1;
ll gcd = extended_GCD(b % a, a, x1, y1);
x = y1 - (b / a) * x1;
y = x1;
return gcd;
}
ll mulInv(ll a, ll mod = MOD) {
ll x, y;
extended_GCD(a, mod, x, y);
if (x < 0)
x += mod;
return x;
}
ll find(ll num[], ll rem[], ll k, ll prod) {
// Compute product of all numbers
ll result = 0;
// Apply above formula
for (ll i = 0; i < k; i++) {
ll pp = prod / num[i];
result += rem[i] * mulInv(pp, num[i]) * pp;
}
return result % prod;
}
bool cmp(pair<ll, ll> &p1, pair<ll, ll> &p2) {
if (p1.ff == p2.ff) {
return p1.ss > p2.ss;
}
return p1.ff < p2.ff;
}
bool isPalindrome(string s) {
ll i, j;
for (i = 0, j = s.length() - 1; i <= j; i++, j--) {
if (s[i] != s[j]) {
return 0;
}
}
return 1;
}
bool isSubSeq(string str1, string str2, ll m, ll n) {
// Base Cases
if (m == 0)
return true;
if (n == 0)
return false;
// If last characters of two strings are matching
if (str1[m - 1] == str2[n - 1])
return isSubSeq(str1, str2, m - 1, n - 1);
// If last characters are not matching
return isSubSeq(str1, str2, m, n - 1);
}
void modBigNumber(string num, ll m) {
// Store the modulus of big number
vector<int> vec;
ll mod = 0;
// Do step by step division
for (int i = 0; i < num.size(); i++) {
int digit = num[i] - '0';
// Update modulo by concatenating
// current digit.
mod = mod * 10 + digit;
// Update quotient
int quo = mod / m;
if ((vec.size() != 0) || (quo != 0)) // to remove initiale zeros
vec.push_back(quo);
// Update mod for next iteration.
mod = mod % m;
}
// cout << "\nRemainder : " << mod << "\n";
// cout << "Quotient : ";rep(i,0,vec.size()-1,1)cout<<vec[i];cout<<"\n";
return;
}
ll sumofdigits(ll a) {
ll val = 0;
while (a > 0) {
val += a % 10;
a /= 10;
}
return val;
}
ll stn(string s) // stn=string_to_number
{
SS s1;
s1 << s;
ll num;
s1 >> num;
return num;
}
string nts(ll n) // nts=number_to_string
{
SS s1;
s1 << n;
string s;
s1 >> s;
return s;
}
struct BIT {
vll v;
BIT(ll n) { v.resize(n + 1, 0); }
void update_BIT(ll index, ll n) {
index++;
while (index < v.size()) {
v[index] += n;
index += index & (-index);
}
}
ll get_sum(ll index) {
ll sum = 0;
index++;
while (index > 0) {
sum += v[index];
index -= index & (-index);
}
return sum;
}
};
class DSU {
public:
vll v, size;
DSU(ll n) {
v.resize(n + 1);
size.resize(n + 1, 1);
rep(i, 1, n, 1) v[i] = i;
}
ll find_set(ll a) {
if (v[a] == a)
return a;
else
return v[a] = find_set(v[a]);
}
void union_sets(ll a, ll b) {
a = find_set(a);
b = find_set(b);
if (a != b) {
if (size[a] < size[b]) {
v[a] = b;
size[b] += size[a];
} else {
v[b] = a;
size[a] += size[b];
}
}
}
};
using namespace std;
int main() {
fastIO ll n;
cin >> n;
ll a[n], val = 1;
ld sum = 0;
rep(i, 0, n - 1, 1) {
cin >> a[i];
val = lcm(a[i], val);
}
rep(i, 0, n - 1, 1) sum += val / a[i];
cout << setprecision(8) << val / sum;
return 0;
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define pb push_back
#define rep(i, a, b, c) for (ll i = (a); i <= (b); i += (c))
#define repb(i, a, b, c) for (ll i = (a); i >= (b); i -= (c))
#define MOD 1000000007
#define ld long double
#define mp make_pair
#define vpll vector<pair<ll, ll>>
#define vll vector<ll>
#define vld vector<ld>
#define vvll vector<vector<ll>>
#define vvld vector<vector<ld>>
#define pll pair<ll, ll>
#define pqll priority_queue<ll>
#define mll map<ll, ll>
#define mlc map<ll, char>
#define um unordered_map
#define umll um<ll, ll>
#define umlc um<ll, char>
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define ln cout << "\n";
#define endl "\n"
#define test \
ll T; \
cin >> T; \
while (T--)
#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define show(w, size) \
for (ll i = 0; i < size; i++) \
cout << w[i] << " ";
#define print(a) cout << a << "\n";
#define mset(dp, no) memset(dp, no, sizeof(dp))
#define input(a, n) rep(i, 0, n - 1, 1) cin >> a[i];
#define countbit __builtin_popcount // Number of setbits in decimal notation
#define fbo(k) \
find_by_order(k) // Valid for ordered set //Number of items
// strictly smaller than k
#define ook(k) \
order_of_key(k) // Valid for ordered set //K-th element in a
// set (counting from zero)
#define lb(v, val) lower_bound(all(v), val) - v.begin()
#define ub(v, val) upper_bound(all(v), val) - v.begin()
#define in insert
#define SS stringstream
// #define db(x) cout <<#x<<": "<<x<<'\n';
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
ll gcd(ll a, ll b) {
if (a < b)
return gcd(b, a);
else if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll isPrime(ll n) {
ll p = (ll)sqrt(n);
rep(i, 2, p, 1) if (n % i == 0) return 0;
return 1;
} // reuturn 1 if prime
ll pow(ll b, ll e) {
if (e == 0)
return 1;
else if (e % 2 == 0) {
ll a = pow(b, e / 2);
return a * a;
} else {
ll a = pow(b, e / 2);
return b * a * a;
}
}
ll powm(ll x, ll y, ll m = MOD) {
x = x % m;
ll res = 1;
while (y) {
if (y & 1)
res = res * x;
res %= m;
y = y >> 1;
x = x * x;
x %= m;
}
return res;
}
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll modInverse(ll a, ll m) { return powm(a, m - 2, m); }
bool issq(ll n) {
ll p = sqrt(n);
return p * p == n;
}
vll prime;
void seive(ll n) {
prime.resize(n + 1, 1);
prime[0] = 0, prime[1] = 0;
for (ll i = 2; i * i <= n; i++)
if (prime[i])
for (ll j = i * i; j <= n; j += i)
prime[j] = 0;
}
ll extended_GCD(ll a, ll b, ll &x, ll &y) {
if (a == 0) {
x = 0;
y = 1;
return b;
}
ll x1, y1;
ll gcd = extended_GCD(b % a, a, x1, y1);
x = y1 - (b / a) * x1;
y = x1;
return gcd;
}
ll mulInv(ll a, ll mod = MOD) {
ll x, y;
extended_GCD(a, mod, x, y);
if (x < 0)
x += mod;
return x;
}
ll find(ll num[], ll rem[], ll k, ll prod) {
// Compute product of all numbers
ll result = 0;
// Apply above formula
for (ll i = 0; i < k; i++) {
ll pp = prod / num[i];
result += rem[i] * mulInv(pp, num[i]) * pp;
}
return result % prod;
}
bool cmp(pair<ll, ll> &p1, pair<ll, ll> &p2) {
if (p1.ff == p2.ff) {
return p1.ss > p2.ss;
}
return p1.ff < p2.ff;
}
bool isPalindrome(string s) {
ll i, j;
for (i = 0, j = s.length() - 1; i <= j; i++, j--) {
if (s[i] != s[j]) {
return 0;
}
}
return 1;
}
bool isSubSeq(string str1, string str2, ll m, ll n) {
// Base Cases
if (m == 0)
return true;
if (n == 0)
return false;
// If last characters of two strings are matching
if (str1[m - 1] == str2[n - 1])
return isSubSeq(str1, str2, m - 1, n - 1);
// If last characters are not matching
return isSubSeq(str1, str2, m, n - 1);
}
void modBigNumber(string num, ll m) {
// Store the modulus of big number
vector<int> vec;
ll mod = 0;
// Do step by step division
for (int i = 0; i < num.size(); i++) {
int digit = num[i] - '0';
// Update modulo by concatenating
// current digit.
mod = mod * 10 + digit;
// Update quotient
int quo = mod / m;
if ((vec.size() != 0) || (quo != 0)) // to remove initiale zeros
vec.push_back(quo);
// Update mod for next iteration.
mod = mod % m;
}
// cout << "\nRemainder : " << mod << "\n";
// cout << "Quotient : ";rep(i,0,vec.size()-1,1)cout<<vec[i];cout<<"\n";
return;
}
ll sumofdigits(ll a) {
ll val = 0;
while (a > 0) {
val += a % 10;
a /= 10;
}
return val;
}
ll stn(string s) // stn=string_to_number
{
SS s1;
s1 << s;
ll num;
s1 >> num;
return num;
}
string nts(ll n) // nts=number_to_string
{
SS s1;
s1 << n;
string s;
s1 >> s;
return s;
}
struct BIT {
vll v;
BIT(ll n) { v.resize(n + 1, 0); }
void update_BIT(ll index, ll n) {
index++;
while (index < v.size()) {
v[index] += n;
index += index & (-index);
}
}
ll get_sum(ll index) {
ll sum = 0;
index++;
while (index > 0) {
sum += v[index];
index -= index & (-index);
}
return sum;
}
};
class DSU {
public:
vll v, size;
DSU(ll n) {
v.resize(n + 1);
size.resize(n + 1, 1);
rep(i, 1, n, 1) v[i] = i;
}
ll find_set(ll a) {
if (v[a] == a)
return a;
else
return v[a] = find_set(v[a]);
}
void union_sets(ll a, ll b) {
a = find_set(a);
b = find_set(b);
if (a != b) {
if (size[a] < size[b]) {
v[a] = b;
size[b] += size[a];
} else {
v[b] = a;
size[a] += size[b];
}
}
}
};
using namespace std;
int main() {
fastIO ll n;
cin >> n;
ll a[n], val = 1;
ld sum = 0;
rep(i, 0, n - 1, 1) {
cin >> a[i];
val = a[i] * val / __gcd(a[i], val);
}
rep(i, 0, n - 1, 1) sum += val / a[i];
cout << setprecision(8) << val / sum;
return 0;
}
| replace | 299 | 300 | 299 | 300 | TLE | |
p02934 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define debug(x) '[' << #x << " is: " << x << "] "
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int n;
cin >> n;
double ans = 0;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
ans += 1.0 / a;
}
ans = 1 / ans;
cout << setprecision(12) << fixed << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define debug(x) '[' << #x << " is: " << x << "] "
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;
int n;
cin >> n;
double ans = 0;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
ans += 1.0 / a;
}
ans = 1 / ans;
cout << setprecision(12) << fixed << ans << endl;
} | delete | 14 | 17 | 14 | 14 | 0 | |
p02934 | C++ | Runtime Error | #include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n = 1;
cin >> n;
vector<double> a(n);
double s1 = 0, s2 = 1;
for (int i = 0; i < n; i++) {
cin >> a[n];
s1 += 1 / a[n];
}
cout << 1 / s1 << endl;
return 0;
} | #include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n = 1;
cin >> n;
// vector<double>a(n);
double a[105];
double s1 = 0, s2 = 1;
for (int i = 0; i < n; i++) {
cin >> a[n];
s1 += 1 / a[n];
}
cout << 1 / s1 << endl;
return 0;
} | replace | 7 | 8 | 7 | 9 | 0 | |
p02934 | C++ | Runtime Error | #include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> A(N);
float ans = 0;
for (int i = 0; i < N; i++) {
cin >> A[i];
ans += (float)1 / A[i];
}
return (float)1 / ans;
}
| #include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> A(N);
float ans = 0;
for (int i = 0; i < N; i++) {
cin >> A[i];
ans += (float)1 / A[i];
}
cout << (float)1 / ans << endl;
return 0;
} | replace | 16 | 17 | 16 | 18 | 7 | |
p02934 | C++ | Runtime Error | #include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (int)a; i <= (int)b; i++)
#define fi first
#define sc second
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int>> vpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<int, int> pii;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;
const i64 MOD = 1000000007;
const int INF = 2000000000;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
i64 mul = 0;
REP(i, 0, n - 1) {
double x;
cin >> x;
mul += 1 / x;
}
cout << 1 / mul << endl;
return 0;
} | #include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (int)a; i <= (int)b; i++)
#define fi first
#define sc second
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int>> vpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<int, int> pii;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;
const i64 MOD = 1000000007;
const int INF = 2000000000;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
double mul = 0;
REP(i, 0, n - 1) {
double x;
cin >> x;
mul += 1 / x;
}
cout << 1 / mul << endl;
return 0;
} | replace | 31 | 32 | 31 | 32 | 0 | |
p02934 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define MX 200005
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x) \
int x; \
cin >> x; \
while (x--)
#define pw(b, p) pow(b, p) + 0.1
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
void c_p_c() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int32_t main() {
c_p_c();
int n;
cin >> n;
double ans = 0.0;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
ans += 1.0 / x;
}
ans = 1.0 / ans;
cout << ans << '\n';
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define MX 200005
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x) \
int x; \
cin >> x; \
while (x--)
#define pw(b, p) pow(b, p) + 0.1
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
void c_p_c() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int32_t main() {
// c_p_c();
int n;
cin >> n;
double ans = 0.0;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
ans += 1.0 / x;
}
ans = 1.0 / ans;
cout << ans << '\n';
return 0;
} | replace | 42 | 43 | 42 | 43 | TLE | |
p02934 | Python | Runtime Error | n = int(input())
a = list(map(int, input().split()))
div = 0
for i in range(n):
div += a / a[i]
print(1 / div)
| n = int(input())
a = list(map(int, input().split()))
div = 0
for i in range(n):
div += 1 / a[i]
print(1 / div)
| replace | 5 | 6 | 5 | 6 | TypeError: unsupported operand type(s) for /: 'list' and 'int' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02934/Python/s178492873.py", line 6, in <module>
div += a / a[i]
TypeError: unsupported operand type(s) for /: 'list' and 'int'
|
p02934 | Python | Runtime Error | n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in n:
ans += 1 / i
print(1 / ans)
| n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in a:
ans += 1 / i
print(1 / ans)
| replace | 3 | 4 | 3 | 4 | TypeError: 'int' object is not iterable | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02934/Python/s273231160.py", line 4, in <module>
for i in n:
TypeError: 'int' object is not iterable
|
p02934 | Python | Runtime Error | import numpy as np
N = int(input())
A = [float(input()) for _ in range(N)]
nA = np.array(A)
print(np.reciprocal(np.sum(np.reciprocal(nA))))
| import numpy as np
N = int(input())
A = [float(x) for x in input().split()]
nA = np.array(A)
print(np.reciprocal(np.sum(np.reciprocal(nA))))
| replace | 3 | 4 | 3 | 4 | TLE | |
p02934 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main(void) {
// Your code here!
int n;
float gyaku[10], sum = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> gyaku[i];
gyaku[i] = 1 / gyaku[i];
sum += gyaku[i];
}
cout << 1 / sum;
} | #include <iostream>
using namespace std;
int main(void) {
// Your code here!
int n;
float gyaku[100], sum = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> gyaku[i];
gyaku[i] = 1 / gyaku[i];
sum += gyaku[i];
}
cout << 1 / sum;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02935 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v;
for (int i = 0; i < n; i++)
cin >> v[i];
sort(v.begin(), v.end());
float res = (float)v[0];
for (int i = 1; i < n; i++)
res = (float)((res + v[i]) / 2);
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++)
cin >> v[i];
sort(v.begin(), v.end());
float res = (float)v[0];
for (int i = 1; i < n; i++)
res = (float)((res + v[i]) / 2);
cout << res << endl;
return 0;
} | replace | 6 | 7 | 6 | 7 | -11 | |
p02935 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <math.h>
#include <queue>
#include <vector>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> gu(n);
for (int i = 0; i < n; i++) {
cin >> gu[i];
}
sort(gu.begin(), gu.end());
double maxv = 0;
do {
double value = gu[0];
for (int i = 1; i < gu.size(); i++) {
value = (value + gu[i]) / 2;
}
maxv = max(maxv, value);
} while (next_permutation(gu.begin(), gu.end()));
cout << maxv;
}
int main() {
solve();
return 0;
} | #include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <math.h>
#include <queue>
#include <vector>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> gu(n);
for (int i = 0; i < n; i++) {
cin >> gu[i];
}
sort(gu.begin(), gu.end());
double maxv = 0;
double value = gu[0];
for (int i = 1; i < gu.size(); i++) {
value = (value + gu[i]) / 2;
}
maxv = max(maxv, value);
cout << maxv;
}
int main() {
solve();
return 0;
} | replace | 22 | 29 | 22 | 28 | TLE | |
p02935 | C++ | Runtime Error | #include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
priority_queue<double, vector<double>, greater<double>> q;
for (int i = 1; i <= n; i++) {
double v;
cin >> v;
q.push(v);
}
while (sz(q) >= 2) {
auto u = q.top();
q.pop();
auto v = q.top();
q.pop();
q.push((u + v) / 2);
}
auto ans = q.top();
cout << fixed << setprecision(12) << ans;
return 0;
}
| #include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
priority_queue<double, vector<double>, greater<double>> q;
for (int i = 1; i <= n; i++) {
double v;
cin >> v;
q.push(v);
}
while (sz(q) >= 2) {
auto u = q.top();
q.pop();
auto v = q.top();
q.pop();
q.push((u + v) / 2);
}
auto ans = q.top();
cout << fixed << setprecision(12) << ans;
return 0;
}
| insert | 17 | 17 | 17 | 18 | -11 | |
p02935 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
double a[10000];
int n;
double ans = 0;
double cnt() {
double las = a[1];
for (int i = 2; i <= n; i++) {
las = (a[i] + las) / 2;
}
return las;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + n + 1);
do {
ans = max(ans, cnt());
} while (next_permutation(a + 1, a + n + 1));
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
double a[10000];
int n;
double ans = 0;
double cnt() {
double las = a[1];
for (int i = 2; i <= n; i++) {
las = (a[i] + las) / 2;
}
return las;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + n + 1);
ans = cnt();
cout << ans;
return 0;
}
| replace | 18 | 21 | 18 | 19 | TLE | |
p02935 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
priority_queue<float, vector<float>, greater<float>> q;
for (int i = 0; i < n; i++) {
float y;
cin >> y;
q.push(y);
}
while (q.size() != 1) {
float x = q.top();
q.pop();
float y = q.top();
q.pop();
float z = (float)(x + y) / 2;
q.push(z);
}
cout << q.top() << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
priority_queue<float, vector<float>, greater<float>> q;
for (int i = 0; i < n; i++) {
float y;
cin >> y;
q.push(y);
}
while (q.size() != 1) {
float x = q.top();
q.pop();
float y = q.top();
q.pop();
float z = (float)(x + y) / 2;
q.push(z);
}
cout << q.top() << endl;
return 0;
} | insert | 4 | 4 | 4 | 5 | 0 | |
p02935 | C++ | Runtime Error | // 17571@nith.ac.in @Ankit Verma
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3")
#ifndef ONLINE_JUDGE
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << std ::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define debug(...)
#endif
#define n_l '\n'
template <typename T, size_t N> int SIZE(const T (&t)[N]) { return N; }
template <typename T> int SIZE(const T &t) { return t.size(); }
string to_string(string s, int x1 = 0, int x2 = 1e9) {
return '"' + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) : "") + '"';
}
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(char c) { return string({c}); }
template <size_t N> string to_string(bitset<N> &b, int x1 = 0, int x2 = 1e9) {
string t = "";
for (int __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1);
__iii__ <= __jjj__; ++__iii__) {
t += b[__iii__] + '0';
}
return '"' + t + '"';
}
template <typename A, typename... C>
string to_string(A(&v), int x1 = 0, int x2 = 1e9, C... coords);
int l_v_l_v_l = 0, t_a_b_s = 0;
template <typename A, typename B> string to_string(pair<A, B> &p) {
l_v_l_v_l++;
string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
l_v_l_v_l--;
return res;
}
template <typename A, typename... C>
string to_string(A(&v), int x1, int x2, C... coords) {
int rnk = rank<A>::value;
string tab(t_a_b_s, ' ');
string res = "";
bool first = true;
if (l_v_l_v_l == 0)
res += n_l;
res += tab + "[";
x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v));
auto l = begin(v);
advance(l, x1);
auto r = l;
advance(r, (x2 - x1) + (x2 < SIZE(v)));
for (auto e = l; e != r; e = next(e)) {
if (!first) {
res += ", ";
}
first = false;
l_v_l_v_l++;
if (e != l) {
if (rnk > 1) {
res += n_l;
t_a_b_s = l_v_l_v_l;
};
} else {
t_a_b_s = 0;
}
res += to_string(*e, coords...);
l_v_l_v_l--;
}
res += "]";
if (l_v_l_v_l == 0)
res += n_l;
return res;
}
void dbgs() { ; }
template <typename Heads, typename... Tails> void dbgs(Heads H, Tails... T) {
cout << to_string(H) << " | ";
dbgs(T...);
}
#define dbgm(...) \
cout << "[" << #__VA_ARGS__ << "]: "; \
dbgs(__VA_ARGS__); \
cout << endl;
#define pb push_back
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define MOD 1000000007
#define MOD9 1000000009
#define ll long long
#define gc getchar_unlocked
#define eps 1e-8
#define ms(s, n) memset(s, n, sizeof(s))
#define bolt ios::sync_with_stdio(false)
const double pie = 2 * acos(0.0);
#define prec(n) fixed << setprecision(n)
#define eof (scanf("%d", &n)) != EOF
#define Unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EraseSpace(s) s.erase(remove(s.begin(), s.end(), ' '), s.end());
#define leftrotate(str, n) rotate(str.begin(), str.begin() + n, str.end());
#define rightrotate(str, n) \
rotate(str.begin(), str.begin() + str.size() - n, str.end());
#define pii pair<int, int>
#define f(i, x, n) for (int i = x; i < n; i++)
#define MP make_pair
#define db(x) cout << #x << " :: " << x << endl;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
gp_hash_table<long long, int, custom_hash> smp;
int main() {
#ifndef ONLINE_JUDGE
freopen("inp.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
bolt;
cin.tie(NULL);
cout.tie(NULL);
ll n;
cin >> n;
double ar[n];
for (int i = 0; i < n; i++)
cin >> ar[i];
double ans = 0;
sort(ar, ar + n);
double temp = (ar[0] + ar[1]) / 2;
ans = temp;
for (int i = 2; i < n; i++) {
ans = (ans + ar[i]) / 2;
}
cout << ans << endl;
return 0;
} | // 17571@nith.ac.in @Ankit Verma
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3")
#ifndef ONLINE_JUDGE
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << std ::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define debug(...)
#endif
#define n_l '\n'
template <typename T, size_t N> int SIZE(const T (&t)[N]) { return N; }
template <typename T> int SIZE(const T &t) { return t.size(); }
string to_string(string s, int x1 = 0, int x2 = 1e9) {
return '"' + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) : "") + '"';
}
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(char c) { return string({c}); }
template <size_t N> string to_string(bitset<N> &b, int x1 = 0, int x2 = 1e9) {
string t = "";
for (int __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1);
__iii__ <= __jjj__; ++__iii__) {
t += b[__iii__] + '0';
}
return '"' + t + '"';
}
template <typename A, typename... C>
string to_string(A(&v), int x1 = 0, int x2 = 1e9, C... coords);
int l_v_l_v_l = 0, t_a_b_s = 0;
template <typename A, typename B> string to_string(pair<A, B> &p) {
l_v_l_v_l++;
string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
l_v_l_v_l--;
return res;
}
template <typename A, typename... C>
string to_string(A(&v), int x1, int x2, C... coords) {
int rnk = rank<A>::value;
string tab(t_a_b_s, ' ');
string res = "";
bool first = true;
if (l_v_l_v_l == 0)
res += n_l;
res += tab + "[";
x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v));
auto l = begin(v);
advance(l, x1);
auto r = l;
advance(r, (x2 - x1) + (x2 < SIZE(v)));
for (auto e = l; e != r; e = next(e)) {
if (!first) {
res += ", ";
}
first = false;
l_v_l_v_l++;
if (e != l) {
if (rnk > 1) {
res += n_l;
t_a_b_s = l_v_l_v_l;
};
} else {
t_a_b_s = 0;
}
res += to_string(*e, coords...);
l_v_l_v_l--;
}
res += "]";
if (l_v_l_v_l == 0)
res += n_l;
return res;
}
void dbgs() { ; }
template <typename Heads, typename... Tails> void dbgs(Heads H, Tails... T) {
cout << to_string(H) << " | ";
dbgs(T...);
}
#define dbgm(...) \
cout << "[" << #__VA_ARGS__ << "]: "; \
dbgs(__VA_ARGS__); \
cout << endl;
#define pb push_back
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define MOD 1000000007
#define MOD9 1000000009
#define ll long long
#define gc getchar_unlocked
#define eps 1e-8
#define ms(s, n) memset(s, n, sizeof(s))
#define bolt ios::sync_with_stdio(false)
const double pie = 2 * acos(0.0);
#define prec(n) fixed << setprecision(n)
#define eof (scanf("%d", &n)) != EOF
#define Unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EraseSpace(s) s.erase(remove(s.begin(), s.end(), ' '), s.end());
#define leftrotate(str, n) rotate(str.begin(), str.begin() + n, str.end());
#define rightrotate(str, n) \
rotate(str.begin(), str.begin() + str.size() - n, str.end());
#define pii pair<int, int>
#define f(i, x, n) for (int i = x; i < n; i++)
#define MP make_pair
#define db(x) cout << #x << " :: " << x << endl;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
gp_hash_table<long long, int, custom_hash> smp;
int main() {
bolt;
cin.tie(NULL);
cout.tie(NULL);
ll n;
cin >> n;
double ar[n];
for (int i = 0; i < n; i++)
cin >> ar[i];
double ans = 0;
sort(ar, ar + n);
double temp = (ar[0] + ar[1]) / 2;
ans = temp;
for (int i = 2; i < n; i++) {
ans = (ans + ar[i]) / 2;
}
cout << ans << endl;
return 0;
} | delete | 131 | 135 | 131 | 131 | 0 | |
p02935 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
long double v[1000];
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n;
cin >> n;
long double ans = 0, val;
for (int i = 0; i < n; ++i) {
cin >> v[i];
}
sort(v, v + n);
do {
val = v[0];
for (int i = 1; i < n; ++i) {
val = (val + v[i]) / 2;
}
ans = max(ans, val);
} while (next_permutation(v, v + n));
cout << ans << '\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long double v[1000];
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n;
cin >> n;
long double ans = 0, val;
for (int i = 0; i < n; ++i) {
cin >> v[i];
}
sort(v, v + n);
val = v[0];
for (int i = 1; i < n; ++i) {
val = (val + v[i]) / 2;
}
ans = max(ans, val);
cout << ans << '\n';
return 0;
} | replace | 18 | 25 | 18 | 23 | TLE | |
p02935 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, tmp;
priority_queue<int, vector<int>, greater<int>> queue;
std::cin >> n;
for (int i = 0; i < n; i++) {
std::cin >> tmp;
queue.push(tmp * 100000);
}
do {
int now = 0;
now += queue.top();
queue.pop();
now += queue.top();
queue.pop();
queue.push(now / 2);
} while (queue.empty() != 1);
printf("%5f\n", (double)queue.top() / 100000);
return 0;
}
| #include <algorithm>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, tmp;
priority_queue<int, vector<int>, greater<int>> queue;
std::cin >> n;
for (int i = 0; i < n; i++) {
std::cin >> tmp;
queue.push(tmp * 100000);
}
do {
int now = 0;
now += queue.top();
queue.pop();
now += queue.top();
queue.pop();
queue.push(now / 2);
} while (queue.size() != 1);
printf("%5f\n", (double)queue.top() / 100000);
return 0;
}
| replace | 25 | 26 | 25 | 26 | -6 | double free or corruption (out)
|
p02935 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, ans = 0;
cin >> N;
vector<float> v(N);
for (int i = 0; i < N; ++i)
cin >> v[i];
sort(v.begin(), v.end());
for (int i = 0; i < N; ++i) {
v[i + 1] = (v[i + 1] + v[i]) / 2;
}
cout << v[N - 1] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, ans = 0;
cin >> N;
vector<float> v(N);
for (int i = 0; i < N; ++i)
cin >> v[i];
sort(v.begin(), v.end());
for (int i = 0; i < N - 1; ++i) {
v[i + 1] = (v[i + 1] + v[i]) / 2;
}
cout << v[N - 1] << endl;
}
| replace | 13 | 14 | 13 | 14 | 0 | |
p02935 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rg register long long
#define inf 21474899993647
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define ll long long
#define maxn 100005
#define endl "\n"
#define N 6000
const double eps = 1e-8;
using namespace std;
inline ll read() {
char ch = getchar();
ll s = 0, w = 1;
while (ch < 48 || ch > 57) {
if (ch == '-')
w = -1;
ch = getchar();
}
while (ch >= 48 && ch <= 57) {
s = (s << 1) + (s << 3) + (ch ^ 48);
ch = getchar();
}
return s * w;
}
inline void write(ll x) {
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
write(x / 10);
putchar(x % 10 + 48);
}
priority_queue<double, vector<double>, greater<double>> q;
int main() {
ll n = read();
for (rg i = 1; i <= n; i++) {
double x = read();
q.push(x);
}
double ans = 0;
while (!q.empty()) {
double a = q.top();
q.pop();
double b = q.top();
q.pop();
q.push((a + b) / 2.0);
ans = (a + b) / 2;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rg register long long
#define inf 21474899993647
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define ll long long
#define maxn 100005
#define endl "\n"
#define N 6000
const double eps = 1e-8;
using namespace std;
inline ll read() {
char ch = getchar();
ll s = 0, w = 1;
while (ch < 48 || ch > 57) {
if (ch == '-')
w = -1;
ch = getchar();
}
while (ch >= 48 && ch <= 57) {
s = (s << 1) + (s << 3) + (ch ^ 48);
ch = getchar();
}
return s * w;
}
inline void write(ll x) {
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
write(x / 10);
putchar(x % 10 + 48);
}
priority_queue<double, vector<double>, greater<double>> q;
int main() {
ll n = read();
for (rg i = 1; i <= n; i++) {
double x = read();
q.push(x);
}
double ans = 0;
while (!q.empty()) {
double a = q.top();
q.pop();
if (!q.empty()) {
double b = q.top();
q.pop();
q.push((a + b) / 2.0);
ans = (a + b) / 2.0;
}
}
cout << ans << endl;
return 0;
}
| replace | 43 | 47 | 43 | 49 | -6 | double free or corruption (out)
|
p02935 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = (int)(a); i >= (int)(b); --i)
#define fore(i, a) for (auto &i : a)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define isin(i, a, b) ((a) <= (i) && (i) <= (b))
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define fi first
#define se second
#define pb push_back
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using unit = unsigned;
using vl = vector<ll>;
using ull = unsigned long long;
using vvi = vector<vi>;
using P = pair<int, int>;
using vvl = vector<vl>;
using vp = vector<P>;
void _main();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
_main();
}
template <class T> string join(const v(T) & v) {
stringstream s;
rep(i, 0, sz(v)) s << ' ' << v[i];
return s.str().substr(1);
}
template <class T> istream &operator>>(istream &i, v(T) & v) {
fore(x, v) { i >> v; }
return i;
}
template <class T> ostream &operator<<(ostream &o, const v(T) & v) {
o << "[";
fore(x, v) o << x << ",";
o << "]";
return o;
}
template <class T> ostream &operator<<(ostream &o, const deque<T> &v) {
o << "deq[";
fore(x, v) o << x << ",";
o << "]";
return o;
}
template <class T> ostream &operator<<(ostream &o, const set<T> &v) {
o << "{";
fore(x, v) o << x << ",";
o << "}";
return o;
}
template <class T> ostream &operator<<(ostream &o, const unordered_set<T> &v) {
o << "{";
fore(x, v) o << x << ",";
o << "}";
return o;
}
template <class T> ostream &operator<<(ostream &o, const multiset<T> &v) {
o << "{";
fore(x, v) o << x << ",";
o << "}";
return o;
}
template <class T>
ostream &operator<<(ostream &o, const unordered_multiset<T> &v) {
o << "{";
fore(x, v) o << x << ",";
o << "}";
return o;
}
template <class T1, class T2>
ostream &operator<<(ostream &o, const pair<T1, T2> &p) {
o << "(" << p.fi << "," << p.se << ")";
return o;
}
template <class TK, class TV>
ostream &operator<<(ostream &o, const map<TK, TV> &m) {
o << "{";
fore(x, m) o << x.fi << "=>" << x.se << ",";
o << "}";
return o;
}
template <class TK, class TV>
ostream &operator<<(ostream &o, const unordered_map<TK, TV> &m) {
o << "{";
fore(x, m) o << x.fi << "=>" << x.se << ",";
o << "}";
return o;
}
template <class T> void YES(T c) {
if (c)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
template <class T> void Yes(T c) {
if (c)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
template <class T> void POSS(T c) {
if (c)
cout << "POSSIBLE" << endl;
else
cout << "IMPOSSIBLE" << endl;
}
template <class T> void Poss(T c) {
if (c)
cout << "Possible" << endl;
else
cout << "Impossible" << endl;
}
template <class T> void chmax(T &a, const T &b) {
if (a < b)
a = b;
}
template <class T> void chmin(T &a, const T &b) {
if (b < a)
a = b;
}
template <class T> T gcd(T a, T b) { return (b == 0) ? a : gcd(b, a % b); }
template <class T> T lcm(T a, T b) { return a * (b / gcd(a, b)); }
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const ll INFL = 1LL << 60;
const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, 1, 0, -1, -1, 1, -1, 1};
void _main() {
int N;
cin >> N;
v(double) V(N);
fore(x, V) cin >> x;
vi idx(N);
iota(all(idx), 0);
double ans = 0;
do {
double tmp = (V[idx[0]] + V[idx[1]]) / 2.0;
rep(i, 2, N) { tmp = (tmp + V[idx[i]]) / 2.0; }
chmax(ans, tmp);
} while (next_permutation(all(idx)));
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = (int)(a); i >= (int)(b); --i)
#define fore(i, a) for (auto &i : a)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define isin(i, a, b) ((a) <= (i) && (i) <= (b))
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define fi first
#define se second
#define pb push_back
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using unit = unsigned;
using vl = vector<ll>;
using ull = unsigned long long;
using vvi = vector<vi>;
using P = pair<int, int>;
using vvl = vector<vl>;
using vp = vector<P>;
void _main();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
_main();
}
template <class T> string join(const v(T) & v) {
stringstream s;
rep(i, 0, sz(v)) s << ' ' << v[i];
return s.str().substr(1);
}
template <class T> istream &operator>>(istream &i, v(T) & v) {
fore(x, v) { i >> v; }
return i;
}
template <class T> ostream &operator<<(ostream &o, const v(T) & v) {
o << "[";
fore(x, v) o << x << ",";
o << "]";
return o;
}
template <class T> ostream &operator<<(ostream &o, const deque<T> &v) {
o << "deq[";
fore(x, v) o << x << ",";
o << "]";
return o;
}
template <class T> ostream &operator<<(ostream &o, const set<T> &v) {
o << "{";
fore(x, v) o << x << ",";
o << "}";
return o;
}
template <class T> ostream &operator<<(ostream &o, const unordered_set<T> &v) {
o << "{";
fore(x, v) o << x << ",";
o << "}";
return o;
}
template <class T> ostream &operator<<(ostream &o, const multiset<T> &v) {
o << "{";
fore(x, v) o << x << ",";
o << "}";
return o;
}
template <class T>
ostream &operator<<(ostream &o, const unordered_multiset<T> &v) {
o << "{";
fore(x, v) o << x << ",";
o << "}";
return o;
}
template <class T1, class T2>
ostream &operator<<(ostream &o, const pair<T1, T2> &p) {
o << "(" << p.fi << "," << p.se << ")";
return o;
}
template <class TK, class TV>
ostream &operator<<(ostream &o, const map<TK, TV> &m) {
o << "{";
fore(x, m) o << x.fi << "=>" << x.se << ",";
o << "}";
return o;
}
template <class TK, class TV>
ostream &operator<<(ostream &o, const unordered_map<TK, TV> &m) {
o << "{";
fore(x, m) o << x.fi << "=>" << x.se << ",";
o << "}";
return o;
}
template <class T> void YES(T c) {
if (c)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
template <class T> void Yes(T c) {
if (c)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
template <class T> void POSS(T c) {
if (c)
cout << "POSSIBLE" << endl;
else
cout << "IMPOSSIBLE" << endl;
}
template <class T> void Poss(T c) {
if (c)
cout << "Possible" << endl;
else
cout << "Impossible" << endl;
}
template <class T> void chmax(T &a, const T &b) {
if (a < b)
a = b;
}
template <class T> void chmin(T &a, const T &b) {
if (b < a)
a = b;
}
template <class T> T gcd(T a, T b) { return (b == 0) ? a : gcd(b, a % b); }
template <class T> T lcm(T a, T b) { return a * (b / gcd(a, b)); }
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const ll INFL = 1LL << 60;
const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, 1, 0, -1, -1, 1, -1, 1};
void _main() {
int N;
cin >> N;
v(double) V(N);
fore(x, V) cin >> x;
sort(all(V));
double ans = (V[0] + V[1]) / 2.0;
rep(i, 2, N) { ans = (ans + V[i]) / 2.0; }
cout << ans << endl;
} | replace | 141 | 151 | 141 | 144 | TLE | |
p02935 | C++ | Runtime Error | #define ll long long
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define T \
long long t; \
cin >> t; \
while (t--)
#define foe(i) for (int i = 1; i <= n; i++)
#define fo(i) for (int i = 0; i < n; i++)
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n;
cin >> n;
ll a[55];
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
a[1] += a[0];
long double ans = 0;
int j = 1;
for (int i = 1; i <= pow(2, n - 2); i = i * 2) {
ans += i * a[j];
j++;
}
ans = ans / pow(2, n - 1);
cout << ans;
} | #define ll long long
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define T \
long long t; \
cin >> t; \
while (t--)
#define foe(i) for (int i = 1; i <= n; i++)
#define fo(i) for (int i = 0; i < n; i++)
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n;
cin >> n;
ll a[55];
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
a[1] += a[0];
long double ans = 0;
int j = 1;
for (ll i = 1; i <= pow(2, n - 2); i = i * 2) {
ans += i * a[j];
j++;
}
ans = ans / pow(2, n - 1);
cout << ans;
} | replace | 27 | 28 | 27 | 28 | 0 | |
p02935 | Python | Runtime Error | N = int(input())
V = [float(v) for v in input().split()]
V.sort(revese=True)
for i in range(N):
if len(V) == 1:
print(V[0])
exit()
v1 = V.pop()
v2 = V.pop()
V.append((v1 + v2) / 2)
| N = int(input())
V = [float(v) for v in input().split()]
V.sort(reverse=True)
for i in range(N):
if len(V) == 1:
print(V[0])
exit()
v1 = V.pop()
v2 = V.pop()
V.append((v1 + v2) / 2)
| replace | 2 | 3 | 2 | 3 | TypeError: 'revese' is an invalid keyword argument for sort() | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02935/Python/s155796698.py", line 3, in <module>
V.sort(revese=True)
TypeError: 'revese' is an invalid keyword argument for sort()
|
p02935 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<float> v(N);
for (int i = 0; i < N; ++i)
cin >> v[i];
sort(v.begin(), v.end());
for (int j = 0; j < N; ++j) {
v[j + 1] = (v[j] + v[j + 1]) / 2;
}
cout << v[N - 1] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<float> v(N);
for (int i = 0; i < N; ++i)
cin >> v[i];
sort(v.begin(), v.end());
for (int j = 0; j < N - 1; ++j) {
v[j + 1] = (v[j] + v[j + 1]) / 2;
}
cout << v[N - 1] << endl;
return 0;
} | replace | 12 | 13 | 12 | 13 | 0 | |
p02935 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
sort(arr, arr + n);
double max = 0;
do {
double temp = arr[0];
for (int i = 1; i < n; i++) {
temp += arr[i];
temp /= 2;
}
if (temp > max) {
max = temp;
}
} while (std::next_permutation(arr, arr + n));
cout << max;
return 0;
}
| #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
sort(arr, arr + n);
double temp = arr[0];
for (int i = 1; i < n; i++) {
temp += arr[i];
temp /= 2;
}
cout << temp;
return 0;
}
| replace | 12 | 24 | 12 | 20 | TLE | |
p02935 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n;
cin >> n;
vector<double> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
double max_v = 0;
sort(v.begin(), v.end());
do {
double value = v[0];
for (int i = 1; i < n; i++) {
value = (value + v[i]) / 2.0;
}
max_v = max(max_v, value);
} while (next_permutation(v.begin(), v.end()));
printf("%.7f\n", max_v);
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n;
cin >> n;
vector<double> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
double max_v = 0;
sort(v.begin(), v.end());
// do {
double value = v[0];
for (int i = 1; i < n; i++) {
value = (value + v[i]) / 2.0;
}
max_v = max(max_v, value);
// }while(next_permutation(v.begin(),v.end()));
printf("%.7f\n", max_v);
}
| replace | 14 | 21 | 14 | 21 | TLE | |
p02935 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
priority_queue<double, vector<double>, greater<double>> pt;
double a, b, sum = 0;
for (int i = 0; i < n; i++) {
scanf("%lf", &a);
pt.push(a);
}
while (!pt.empty()) {
a = pt.top();
pt.pop();
b = pt.top();
pt.pop();
sum = (a + b) / 2.0;
pt.push(sum);
}
printf("%lf\n", sum);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
priority_queue<double, vector<double>, greater<double>> pt;
double a, b, sum = 0;
for (int i = 0; i < n; i++) {
scanf("%lf", &a);
pt.push(a);
}
while (pt.size() > 1) {
a = pt.top();
pt.pop();
b = pt.top();
pt.pop();
sum = (a + b) / 2.0;
pt.push(sum);
}
printf("%lf\n", sum);
return 0;
} | replace | 11 | 12 | 11 | 12 | -6 | double free or corruption (out)
|
p02935 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i >= 0; i++)
#define REP(i, m, n) for (int i = m; i < n; i++)
#define SORT(v) sort((v).begin(), (v).end())
#define REV(v) sort((v).begin(), (v).end(), greater<int>())
#define INF 1000000007
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; };
int lcm(int a, int b) { return a * b / gcd(a, b); };
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
};
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<double> v(n);
rep(i, n) cin >> v[i];
sort(all(v));
rep(i, n) { v[i + 1] = (v[i] + v[i + 1]) / 2; }
cout << fixed << v[n - 1] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i >= 0; i++)
#define REP(i, m, n) for (int i = m; i < n; i++)
#define SORT(v) sort((v).begin(), (v).end())
#define REV(v) sort((v).begin(), (v).end(), greater<int>())
#define INF 1000000007
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; };
int lcm(int a, int b) { return a * b / gcd(a, b); };
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
};
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<double> v(n);
rep(i, n) cin >> v[i];
sort(all(v));
rep(i, n - 1) { v[i + 1] = (v[i] + v[i + 1]) / 2; }
cout << fixed << v[n - 1] << endl;
return 0;
}
| replace | 30 | 31 | 30 | 31 | 0 | |
p02935 | C++ | Runtime Error | #pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/rope"
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second
template <class T>
using Tree =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
ll n;
vector<ld> v;
int main() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
v.assign(n, 0);
F0R(i, n) cin >> v[i];
priority_queue<ld, vector<ld>, greater<ld>> pq;
F0R(i, n) pq.push(v[i]);
ld res = 0;
while (!pq.empty()) {
res = pq.top();
pq.pop();
// cout << res << "\n";
ld a;
if (!pq.empty()) {
a = pq.top();
pq.pop();
pq.push((res + a) / 2);
} else
break;
}
cout << res;
return 0;
} | #pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/rope"
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second
template <class T>
using Tree =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
ll n;
vector<ld> v;
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
v.assign(n, 0);
F0R(i, n) cin >> v[i];
priority_queue<ld, vector<ld>, greater<ld>> pq;
F0R(i, n) pq.push(v[i]);
ld res = 0;
while (!pq.empty()) {
res = pq.top();
pq.pop();
// cout << res << "\n";
ld a;
if (!pq.empty()) {
a = pq.top();
pq.pop();
pq.push((res + a) / 2);
} else
break;
}
cout << res;
return 0;
} | replace | 44 | 46 | 44 | 46 | 0 | |
p02935 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int a[55];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
double max = 0, s;
do {
s = a[0];
for (int i = 0; i < n; i++)
s = (s + a[i]) * 1.0 / (2 * 1.0);
if (s > max)
max = s;
} while (next_permutation(a, a + n));
cout << max;
} | #include <bits/stdc++.h>
using namespace std;
int a[55];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
double s;
s = a[0];
for (int i = 0; i < n; i++)
s = (s + a[i]) * 1.0 / (2 * 1.0);
cout << s;
} | replace | 9 | 18 | 9 | 14 | TLE | |
p02935 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<double> vec(3);
for (int i = 0; i < n; i++) {
double v;
cin >> v;
vec.at(i) = v;
}
for (int i = 0; i < n - 1; i++) {
sort(vec.begin(), vec.end());
reverse(vec.begin(), vec.end());
double num;
// 末尾2つを足して2で割る
num = (vec.at(vec.size() - 1) + vec.at(vec.size() - 2)) / 2;
// 末尾2つを消す
vec.pop_back();
vec.pop_back();
// 末尾にnumを追加
vec.push_back(num);
}
cout << vec.at(0) << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<double> vec(n);
for (int i = 0; i < n; i++) {
double v;
cin >> v;
vec.at(i) = v;
}
for (int i = 0; i < n - 1; i++) {
sort(vec.begin(), vec.end());
reverse(vec.begin(), vec.end());
double num;
// 末尾2つを足して2で割る
num = (vec.at(vec.size() - 1) + vec.at(vec.size() - 2)) / 2;
// 末尾2つを消す
vec.pop_back();
vec.pop_back();
// 末尾にnumを追加
vec.push_back(num);
}
cout << vec.at(0) << endl;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p02935 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
#include <bits/stdc++.h>
void test_data(int N, vector<double> v) {
N = 2;
v = {3, 4};
cout << v[0] << endl;
}
int input_data(int N, vector<double> v) {
cin >> N;
for (int i = 0; i < N; i++) {
int x;
cin >> x;
v.push_back(x);
};
}
double nabe(double x, double y) {
double ans = (x + y) / 2;
return ans;
}
int main() {
// int N = 3;
// vector<double> v = {3, 4, 5};
int N;
vector<double> v;
cin >> N;
for (int i = 0; i < N; i++) {
int x;
cin >> x;
// v.push_back(x);
};
for (int i = 0; i < v.size(); i++) {
// cout << v.at(i) << endl;
}
// vector<double> v_s;
sort(v.begin(), v.end());
for (int i = 0; i < v.size(); i++) {
// cout << v.at(i) << endl;
}
// double test_ans = nabe(x, y);
double x = nabe(v.at(0), v.at(1));
if (N >= 3) {
for (int i = 2; i < v.size(); i++) {
// cout << x << "+" << v.at(i) << endl;
x = nabe(v.at(i), x);
// cout << i << endl;
}
cout << x << endl;
return 0;
} else if (N <= 2) {
cout << x << endl;
return 0;
}
// ans.push_back(nabe(v.at(0), v.at(1)));
// cout << "ans" << endl;
// cout << x << endl;
// ans.push_back( nabe(v.at(1), v.at(2)));
// cout << test_ans << endl;
} | #include <iostream>
#include <vector>
using namespace std;
#include <bits/stdc++.h>
void test_data(int N, vector<double> v) {
N = 2;
v = {3, 4};
cout << v[0] << endl;
}
int input_data(int N, vector<double> v) {
cin >> N;
for (int i = 0; i < N; i++) {
int x;
cin >> x;
v.push_back(x);
};
}
double nabe(double x, double y) {
double ans = (x + y) / 2;
return ans;
}
int main() {
// int N = 3;
// vector<double> v = {3, 4, 5};
int N;
vector<double> v;
cin >> N;
for (int i = 0; i < N; i++) {
int x;
cin >> x;
v.push_back(x);
};
for (int i = 0; i < v.size(); i++) {
// cout << v.at(i) << endl;
}
// vector<double> v_s;
sort(v.begin(), v.end());
for (int i = 0; i < v.size(); i++) {
// cout << v.at(i) << endl;
}
// double test_ans = nabe(x, y);
double x = nabe(v.at(0), v.at(1));
if (N >= 3) {
for (int i = 2; i < v.size(); i++) {
// cout << x << "+" << v.at(i) << endl;
x = nabe(v.at(i), x);
// cout << i << endl;
}
cout << x << endl;
return 0;
} else if (N <= 2) {
cout << x << endl;
return 0;
}
// ans.push_back(nabe(v.at(0), v.at(1)));
// cout << "ans" << endl;
// cout << x << endl;
// ans.push_back( nabe(v.at(1), v.at(2)));
// cout << test_ans << endl;
} | replace | 38 | 39 | 38 | 39 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 1) >= this->size() (which is 0)
|
p02935 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, x) for (int i = 1; i <= (int)(x); i++)
#define all(x) (x).begin(), (x).end()
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> list(N);
rep(i, N) cin >> list.at(i);
sort(all(list));
double ans = list.at(0);
reps(i, N) { ans = (ans + list.at(i)) / 2; }
cout << ans << endl;
}
| #include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, x) for (int i = 1; i <= (int)(x); i++)
#define all(x) (x).begin(), (x).end()
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> list(N);
rep(i, N) cin >> list.at(i);
sort(all(list));
double ans = list.at(0);
for (int i = 1; i < N; i++) {
ans = (ans + list.at(i)) / 2;
}
cout << ans << endl;
}
| replace | 20 | 21 | 20 | 23 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 2) >= this->size() (which is 2)
|
p02935 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
int array[N];
for (int i = 0; i < N; i++) {
cin >> array[i];
}
double d = 0.0;
sort(array, array + N);
d = array[0];
for (int i = 1; i < N; i++) {
d = (d + array[i]) / 2;
}
return d;
} | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
int array[N];
for (int i = 0; i < N; i++) {
cin >> array[i];
}
double d = 0.0;
sort(array, array + N);
d = array[0];
for (int i = 1; i < N; i++) {
d = (d + array[i]) / 2;
}
cout << d << endl;
} | replace | 18 | 19 | 18 | 19 | 3 | |
p02935 | Python | Runtime Error | def solve(string):
n, *v = map(int, string.split())
v = sorted(v, reverse=True)
return str(
sum(_v / 2**i for i, _v in enumerate(v[:-1], start=1)) + v[-1] / 2 ** (n - 1)
)
if __name__ == "__main__":
print(solve(input()))
| def solve(string):
n, *v = map(int, string.split())
v = sorted(v, reverse=True)
return str(
sum(_v / 2**i for i, _v in enumerate(v[:-1], start=1)) + v[-1] / 2 ** (n - 1)
)
if __name__ == "__main__":
print(solve("\n".join([input(), input()])))
| replace | 9 | 10 | 9 | 10 | IndexError: list index out of range | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02935/Python/s824355619.py", line 8, in <module>
print(solve(input()))
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02935/Python/s824355619.py", line 4, in solve
return str(sum(_v / 2**i for i, _v in enumerate(v[:-1], start=1)) + v[-1] / 2**(n - 1))
IndexError: list index out of range
|
p02935 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
double a[50 + 5];
int main() {
int n;
double sum = 0;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n - 1; i++) {
a[i + 1] = (a[i] + a[i + 1]) / 2;
if (i == n - 2)
break;
sort(a + i + 1, a + n - i - 1);
}
printf("%.1lf", a[n - 1]);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
double a[50 + 5];
int main() {
int n;
double sum = 0;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
sum = (a[0] + a[1]) / 2;
for (int i = 2; i < n; i++)
sum = (sum + a[i]) / 2;
cout << sum << endl;
return 0;
} | replace | 11 | 18 | 11 | 15 | 0 | |
p02936 | C++ | Runtime Error | /*
Vivek Rathi
CSE 2nd Year
MNNIT
*/
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long int
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define debug1(x) cout << #x << " " << x << endl;
#define debug2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl;
#define debug3(x, y, z) \
cout << #x << " " << x << " " << #y << " " << y << " " << #z << " " << z \
<< endl;
#define present(c, x) ((c).find(x) != (c).end())
#define null NULL
#define mp make_pair
#define fi first
#define se second
#define boost \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define inf 1e18
#define flush fflush(stdout);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set \
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
ll modpower(ll a, ll b, ll c) {
ll res = 1;
while (b) {
if (b & 1LL)
res = (res * a) % c;
a = (a * a) % c;
b >>= 1;
}
return res;
}
//-------------------------------Template--Above------------------------------------------------
vector<ll> v[100001];
ll ar[100001];
void dfs(ll ver, ll p, ll ch) {
ar[ver] += ch;
// debug2(ver,ch);
for (ll i = 0; i < v[ver].size(); i++) {
if (v[ver][i] != p) {
dfs(v[ver][i], ver, ar[ver]);
}
}
}
int main() {
boost ll n, q;
cin >> n >> q;
for (ll i = 0; i < n - 1; i++) {
ll a, b;
cin >> a >> b;
v[a].pb(b);
v[b].pb(a);
}
while (q--) {
ll ver, x;
cin >> ver >> x;
ar[ver] += x;
}
dfs(1, -1, 0);
for (ll i = 1; i <= n; i++) {
cout << ar[i] << " ";
}
return 0;
}
| /*
Vivek Rathi
CSE 2nd Year
MNNIT
*/
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long int
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define debug1(x) cout << #x << " " << x << endl;
#define debug2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl;
#define debug3(x, y, z) \
cout << #x << " " << x << " " << #y << " " << y << " " << #z << " " << z \
<< endl;
#define present(c, x) ((c).find(x) != (c).end())
#define null NULL
#define mp make_pair
#define fi first
#define se second
#define boost \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define inf 1e18
#define flush fflush(stdout);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set \
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
ll modpower(ll a, ll b, ll c) {
ll res = 1;
while (b) {
if (b & 1LL)
res = (res * a) % c;
a = (a * a) % c;
b >>= 1;
}
return res;
}
//-------------------------------Template--Above------------------------------------------------
vector<ll> v[200001];
ll ar[200001];
void dfs(ll ver, ll p, ll ch) {
ar[ver] += ch;
// debug2(ver,ch);
for (ll i = 0; i < v[ver].size(); i++) {
if (v[ver][i] != p) {
dfs(v[ver][i], ver, ar[ver]);
}
}
}
int main() {
boost ll n, q;
cin >> n >> q;
for (ll i = 0; i < n - 1; i++) {
ll a, b;
cin >> a >> b;
v[a].pb(b);
v[b].pb(a);
}
while (q--) {
ll ver, x;
cin >> ver >> x;
ar[ver] += x;
}
dfs(1, -1, 0);
for (ll i = 1; i <= n; i++) {
cout << ar[i] << " ";
}
return 0;
}
| replace | 44 | 46 | 44 | 46 | 0 | |
p02936 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define per(i, n) for (ll i = n - 1; i >= 0; i--)
#define perl(i, r, l) for (ll i = r - 1; i >= l; i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x, vector<x>, greater<x>>
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
#define vtpl(x, y, z) vector<tuple<x, y, z>>
#define at(x, i) get<i>(x);
#define rev(x) reverse(x);
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
using vpl = vector<pl>;
using vvpl = vector<vpl>;
const ll MOD = 1000000007;
const ll MOD9 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const ll dy[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const ll dx[8] = {0, -1, 0, 1, 1, -1, 1, -1};
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;
}
void solve(int v, const vector<vector<int>> G, vector<bool> &seen,
vector<int> &cost) {
seen[v] = true;
for (auto nv : G[v]) {
if (seen[nv])
continue;
cost[nv] += cost[v];
solve(nv, G, seen, cost);
}
}
int main() {
int N, Q;
cin >> N >> Q;
vector<vector<int>> G(N);
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);
}
vector<int> cost(N, 0);
for (int i = 0; i < Q; i++) {
int a, b;
cin >> a >> b;
a--;
cost[a] += b;
}
vector<bool> seen(N, false);
solve(0, G, seen, cost);
for (int i = 0; i < N; i++) {
if (i)
cout << " ";
cout << cost[i];
}
cout << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define per(i, n) for (ll i = n - 1; i >= 0; i--)
#define perl(i, r, l) for (ll i = r - 1; i >= l; i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x, vector<x>, greater<x>>
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
#define vtpl(x, y, z) vector<tuple<x, y, z>>
#define at(x, i) get<i>(x);
#define rev(x) reverse(x);
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
using vpl = vector<pl>;
using vvpl = vector<vpl>;
const ll MOD = 1000000007;
const ll MOD9 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const ll dy[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const ll dx[8] = {0, -1, 0, 1, 1, -1, 1, -1};
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;
}
void solve(int v, const vector<vector<int>> &G, vector<bool> &seen,
vector<int> &cost) {
seen[v] = true;
for (auto nv : G[v]) {
if (seen[nv])
continue;
cost[nv] += cost[v];
solve(nv, G, seen, cost);
}
}
int main() {
int N, Q;
cin >> N >> Q;
vector<vector<int>> G(N);
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);
}
vector<int> cost(N, 0);
for (int i = 0; i < Q; i++) {
int a, b;
cin >> a >> b;
a--;
cost[a] += b;
}
vector<bool> seen(N, false);
solve(0, G, seen, cost);
for (int i = 0; i < N; i++) {
if (i)
cout << " ";
cout << cost[i];
}
cout << endl;
return 0;
}
| replace | 43 | 44 | 43 | 44 | TLE | |
p02936 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;
#define mk make_pair
#define mkt make_tuple
using namespace std;
int const N = 100000;
int add[N];
bool was[N];
vector<vector<int>> v;
void dfs(int u) {
was[u] = true;
for (int i : v[u])
if (!was[i]) {
add[i] += add[u];
dfs(i);
}
}
int main() {
ll n, q;
cin >> n >> q;
for (int i = 0; i < n; i++)
v.push_back(vector<int>());
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
v[a].push_back(b);
v[b].push_back(a);
}
for (int i = 0; i < q; i++) {
int p, x;
cin >> p >> x;
p--;
add[p] += x;
}
dfs(0);
for (int i = 0; i < n; i++)
cout << add[i] << ' ';
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;
#define mk make_pair
#define mkt make_tuple
using namespace std;
int const N = 200005;
int add[N];
bool was[N];
vector<vector<int>> v;
void dfs(int u) {
was[u] = true;
for (int i : v[u])
if (!was[i]) {
add[i] += add[u];
dfs(i);
}
}
int main() {
ll n, q;
cin >> n >> q;
for (int i = 0; i < n; i++)
v.push_back(vector<int>());
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
v[a].push_back(b);
v[b].push_back(a);
}
for (int i = 0; i < q; i++) {
int p, x;
cin >> p >> x;
p--;
add[p] += x;
}
dfs(0);
for (int i = 0; i < n; i++)
cout << add[i] << ' ';
}
| replace | 21 | 22 | 21 | 22 | 0 | |
p02936 | 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;
vector<int> to[20000];
vector<int> ans;
void dfs(int v, int p = -1) {
for (int u : to[v]) {
if (u == p)
continue;
ans[u] += ans[v];
dfs(u, v);
}
}
int main() {
int n, q;
cin >> n >> q;
rep(i, n - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
to[a].push_back(b);
to[b].push_back(a);
}
ans.resize(n);
rep(i, q) {
int p, x;
cin >> p >> x;
p--;
ans[p] += x;
}
dfs(0);
rep(i, n) { 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;
vector<int> to[200005];
vector<int> ans;
void dfs(int v, int p = -1) {
for (int u : to[v]) {
if (u == p)
continue;
ans[u] += ans[v];
dfs(u, v);
}
}
int main() {
int n, q;
cin >> n >> q;
rep(i, n - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
to[a].push_back(b);
to[b].push_back(a);
}
ans.resize(n);
rep(i, q) {
int p, x;
cin >> p >> x;
p--;
ans[p] += x;
}
dfs(0);
rep(i, n) { cout << ans[i] << endl; }
return 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02936 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
// #include <deque>
// #include <queue>
// #include <array>
// #include <ctime>
// #include <list>
#include <map>
#include <set>
// #include <cassert>
// #include <complex>
// #include <sstream>
// #include <forward_list>
// #include <unordered_set>
// #include <unordered_map>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set \
tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, \
tree_order_statistics_node_update>
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define scani(n) scanf("%d", &n);
#define EPS 1e-9
#define FOR(i, n) for (int i = 0; i < n; i++)
#define X first
#define Y second
#define arrinput \
for (int i = 0; i < n; i++) \
cin >> arr[i];
#define sumarr \
for (int i = 0; i < n; i++) \
sum += arr[i];
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define forr(i, n) for (int i = n - 1; i >= 0; i--)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
const int MOD = 1e9 + 7;
const int n_ = 1e5 + 1000;
const long double PI = acos(-1.0);
ll gcd(ll a, ll b) { return (a ? gcd(b % a, a) : b); }
ll power(ll a, ll n) {
ll p = 1;
while (n > 0) {
if (n % 2) {
p = p * a;
}
n >>= 1;
a *= a;
}
return p;
}
ll power(ll a, ll n, ll mod) {
ll p = 1;
while (n > 0) {
if (n % 2) {
p = p * a;
p %= mod;
}
n >>= 1;
a *= a;
a %= mod;
}
return p % mod;
}
bool vowel(char ch) {
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
return true;
else
return false;
}
// Union-Find Disjoint Sets Library written in OOP manner, using both path
// compression and union by rank heuristics
class UnionFind { // OOP style
private:
vi p, rank, setSize; // remember: vi is vector<int>
int numSets;
public:
UnionFind(int N) {
setSize.assign(N, 1);
numSets = N;
rank.assign(N, 0);
p.assign(N, 0);
for (int i = 0; i < N; i++)
p[i] = i;
}
int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
void unionSet(int i, int j) {
if (!isSameSet(i, j)) {
numSets--;
int x = findSet(i), y = findSet(j);
// rank is used to keep the tree short
if (rank[x] > rank[y]) {
p[y] = x;
setSize[x] += setSize[y];
} else {
p[x] = y;
setSize[y] += setSize[x];
if (rank[x] == rank[y])
rank[y]++;
}
}
}
int numDisjointSets() { return numSets; }
int sizeOfSet(int i) { return setSize[findSet(i)]; }
};
int prefix_function(string s) {
int n = (int)s.length();
vector<int> pi(n);
for (int i = 1; i < n; i++) {
int j = pi[i - 1];
while (j > 0 && s[i] != s[j])
j = pi[j - 1];
if (s[i] == s[j])
j++;
pi[i] = j;
}
return pi[n - 1];
}
vi v[100005];
vi ans(100005, 0);
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, q;
cin >> n >> q;
int a, b;
for0(i, n - 1) {
cin >> a >> b;
v[a].push_back(b);
// v[b].push_back(a);
}
for0(i, q) {
cin >> a >> b;
ans[a] += b;
}
for1(i, n) {
for (int e : v[i]) {
ans[e] += ans[i];
}
}
for1(i, n) cout << ans[i] << " ";
return 0;
} | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
// #include <deque>
// #include <queue>
// #include <array>
// #include <ctime>
// #include <list>
#include <map>
#include <set>
// #include <cassert>
// #include <complex>
// #include <sstream>
// #include <forward_list>
// #include <unordered_set>
// #include <unordered_map>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set \
tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, \
tree_order_statistics_node_update>
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define scani(n) scanf("%d", &n);
#define EPS 1e-9
#define FOR(i, n) for (int i = 0; i < n; i++)
#define X first
#define Y second
#define arrinput \
for (int i = 0; i < n; i++) \
cin >> arr[i];
#define sumarr \
for (int i = 0; i < n; i++) \
sum += arr[i];
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define forr(i, n) for (int i = n - 1; i >= 0; i--)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
const int MOD = 1e9 + 7;
const int n_ = 1e5 + 1000;
const long double PI = acos(-1.0);
ll gcd(ll a, ll b) { return (a ? gcd(b % a, a) : b); }
ll power(ll a, ll n) {
ll p = 1;
while (n > 0) {
if (n % 2) {
p = p * a;
}
n >>= 1;
a *= a;
}
return p;
}
ll power(ll a, ll n, ll mod) {
ll p = 1;
while (n > 0) {
if (n % 2) {
p = p * a;
p %= mod;
}
n >>= 1;
a *= a;
a %= mod;
}
return p % mod;
}
bool vowel(char ch) {
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
return true;
else
return false;
}
// Union-Find Disjoint Sets Library written in OOP manner, using both path
// compression and union by rank heuristics
class UnionFind { // OOP style
private:
vi p, rank, setSize; // remember: vi is vector<int>
int numSets;
public:
UnionFind(int N) {
setSize.assign(N, 1);
numSets = N;
rank.assign(N, 0);
p.assign(N, 0);
for (int i = 0; i < N; i++)
p[i] = i;
}
int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
void unionSet(int i, int j) {
if (!isSameSet(i, j)) {
numSets--;
int x = findSet(i), y = findSet(j);
// rank is used to keep the tree short
if (rank[x] > rank[y]) {
p[y] = x;
setSize[x] += setSize[y];
} else {
p[x] = y;
setSize[y] += setSize[x];
if (rank[x] == rank[y])
rank[y]++;
}
}
}
int numDisjointSets() { return numSets; }
int sizeOfSet(int i) { return setSize[findSet(i)]; }
};
int prefix_function(string s) {
int n = (int)s.length();
vector<int> pi(n);
for (int i = 1; i < n; i++) {
int j = pi[i - 1];
while (j > 0 && s[i] != s[j])
j = pi[j - 1];
if (s[i] == s[j])
j++;
pi[i] = j;
}
return pi[n - 1];
}
vi v[200005];
vi ans(200005, 0);
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, q;
cin >> n >> q;
int a, b;
for0(i, n - 1) {
cin >> a >> b;
v[a].push_back(b);
// v[b].push_back(a);
}
for0(i, q) {
cin >> a >> b;
ans[a] += b;
}
for1(i, n) {
for (int e : v[i]) {
ans[e] += ans[i];
}
}
for1(i, n) cout << ans[i] << " ";
return 0;
} | replace | 150 | 152 | 150 | 152 | 0 | |
p02936 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 100010;
vector<int> G[N];
vector<int> Count(N);
int n, q;
void dfs(int now, int pre) {
for (int i = 0; i < G[now].size(); i++) {
int to = G[now][i];
if (to == pre)
continue;
Count[to] += Count[now];
dfs(to, now);
}
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin >> n >> q;
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);
}
for (int i = 0; i < q; i++) {
int p, x;
cin >> p >> x;
p--;
Count[p] += x;
}
dfs(0, -1);
for (int i = 0; i < n; i++) {
cout << Count[i] << ' ';
}
cout << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 200010;
vector<int> G[N];
vector<int> Count(N);
int n, q;
void dfs(int now, int pre) {
for (int i = 0; i < G[now].size(); i++) {
int to = G[now][i];
if (to == pre)
continue;
Count[to] += Count[now];
dfs(to, now);
}
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin >> n >> q;
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);
}
for (int i = 0; i < q; i++) {
int p, x;
cin >> p >> x;
p--;
Count[p] += x;
}
dfs(0, -1);
for (int i = 0; i < n; i++) {
cout << Count[i] << ' ';
}
cout << endl;
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02936 | C++ | Runtime Error | #include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
// #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 50;
const int inf = 0x3f3f3f3f;
int n, k;
vector<ll> a(20050, 0);
bool vis[20050];
vector<int> g[200050];
void dfs(int t, ll val) {
vis[t] = 1;
a[t] += val;
for (int i = 0; i < g[t].size(); i++) {
int v = g[t][i];
if (!vis[v]) {
dfs(v, a[t]);
}
}
}
int main() {
// freopen("/Users/zilongzhang/Desktop//l.txt","r",stdin);
scanf("%d %d", &n, &k);
for (int i = 1; i <= n - 1; i++) {
int x, y;
scanf("%d %d", &x, &y);
x--;
y--;
g[x].push_back(y);
g[y].push_back(x);
}
while (k--) {
int l, b;
scanf("%d %d", &l, &b);
l--;
a[l] += b;
}
dfs(0, 0);
for (int i = 0; i < n; i++)
printf("%lld ", a[i]);
return 0;
}
| #include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
// #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 50;
const int inf = 0x3f3f3f3f;
int n, k;
ll a[200050];
bool vis[200050];
vector<int> g[200050];
void dfs(int t, ll val) {
vis[t] = 1;
a[t] += val;
for (int i = 0; i < g[t].size(); i++) {
int v = g[t][i];
if (!vis[v]) {
dfs(v, a[t]);
}
}
}
int main() {
// freopen("/Users/zilongzhang/Desktop//l.txt","r",stdin);
scanf("%d %d", &n, &k);
for (int i = 1; i <= n - 1; i++) {
int x, y;
scanf("%d %d", &x, &y);
x--;
y--;
g[x].push_back(y);
g[y].push_back(x);
}
while (k--) {
int l, b;
scanf("%d %d", &l, &b);
l--;
a[l] += b;
}
dfs(0, 0);
for (int i = 0; i < n; i++)
printf("%lld ", a[i]);
return 0;
}
| replace | 17 | 19 | 17 | 19 | 0 | |
p02936 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
vector<int> to[20005];
vector<int> ans;
void dfs(int v, int p = -1) {
for (int u : to[v]) {
if (u == p)
continue;
ans[u] += ans[v];
dfs(u, v);
}
}
int main() {
int n, q;
cin >> n >> q;
int a, b;
for (int i = 0; i < n - 1; i++) {
cin >> a >> b;
--a;
--b;
to[a].push_back(b);
to[b].push_back(a);
}
ans.resize(n);
int p, x;
for (int i = 0; i < q; i++) {
cin >> p >> x;
--p;
ans[p] += x;
}
dfs(0);
for (int i = 0; i < n; i++) {
cout << ans[i] << endl;
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
vector<int> to[200005];
vector<int> ans;
void dfs(int v, int p = -1) {
for (int u : to[v]) {
if (u == p)
continue;
ans[u] += ans[v];
dfs(u, v);
}
}
int main() {
int n, q;
cin >> n >> q;
int a, b;
for (int i = 0; i < n - 1; i++) {
cin >> a >> b;
--a;
--b;
to[a].push_back(b);
to[b].push_back(a);
}
ans.resize(n);
int p, x;
for (int i = 0; i < q; i++) {
cin >> p >> x;
--p;
ans[p] += x;
}
dfs(0);
for (int i = 0; i < n; i++) {
cout << ans[i] << endl;
}
return 0;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p02936 | C++ | Runtime Error | #include <algorithm> // sort
#include <bits/stdc++.h>
#include <ctype.h>
#include <iomanip>
#include <iostream>
#include <map> // pair
#include <math.h>
#include <numeric>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define nin(n) \
int n; \
cin >> n;
#define kin(k) \
int k; \
cin >> k;
vector<int> to[20005];
vector<int> ans;
void dfs(int v, int p = -1) {
for (int u : to[v]) {
if (u == p)
continue;
ans[u] += ans[v];
dfs(u, v);
}
}
const int INF = 1001001001;
int main() {
int n, q;
cin >> n >> q;
ans.resize(n);
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
to[a].push_back(b);
to[b].push_back(a);
ans.at(i) = 0;
}
for (int i = 0; i < q; i++) {
int p, x;
cin >> p >> x;
p--;
ans[p] += x;
}
dfs(0);
for (int i = 0; i < n; i++) {
cout << ans[i] << endl;
}
} | #include <algorithm> // sort
#include <bits/stdc++.h>
#include <ctype.h>
#include <iomanip>
#include <iostream>
#include <map> // pair
#include <math.h>
#include <numeric>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define nin(n) \
int n; \
cin >> n;
#define kin(k) \
int k; \
cin >> k;
vector<int> to[200005];
vector<int> ans;
void dfs(int v, int p = -1) {
for (int u : to[v]) {
if (u == p)
continue;
ans[u] += ans[v];
dfs(u, v);
}
}
const int INF = 1001001001;
int main() {
int n, q;
cin >> n >> q;
ans.resize(n);
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
to[a].push_back(b);
to[b].push_back(a);
ans.at(i) = 0;
}
for (int i = 0; i < q; i++) {
int p, x;
cin >> p >> x;
p--;
ans[p] += x;
}
dfs(0);
for (int i = 0; i < n; i++) {
cout << ans[i] << endl;
}
} | replace | 18 | 19 | 18 | 19 | 0 | |
p02936 | C++ | Runtime Error | #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <bitset>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (auto i = a; i < b; i++)
#define rep2(i, a) for (auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) {
ll a = 1;
while (p > 0) {
if (p % 2 == 0) {
x *= x;
p /= 2;
} else {
a *= x;
p--;
}
}
return a;
}
ll mpower(ll x, ll p) {
ll a = 1;
while (p > 0) {
if (p % 2 == 0) {
x = x * x % mod;
p /= 2;
} else {
a = a * x % mod;
p--;
}
}
return a;
}
ll co(ll n, ll k) {
ll a = 1;
rep(i, 1ll, k) {
a *= n - i + 1;
a /= i;
}
return a;
}
ll mc(ll n, ll m) {
ll k = 1, l = 1;
rep(i, n - m + 1, n + 1) k = k * i % mod;
rep(i, 1, m + 1) l = l * i % mod;
l = mpower(l, mod - 2);
return k * l % mod;
}
vector<vector<int>> G;
vector<ll> c;
vector<int> f;
void dfs(int v, ll x) {
f[v] = 1;
c[v] += x;
rep2(nv, G[v]) { dfs(nv, c[v]); }
}
int main(void) {
int n, q;
cin >> n >> q;
G.resize(n);
c.resize(n);
f.resize(n);
rep(i, 0, n - 1) {
int a, b;
cin >> a >> b;
a--, b--;
G[a].push_back(b);
G[b].push_back(a);
}
rep(i, 0, q) {
int p, x;
cin >> p >> x;
c[p - 1] += (ll)x;
}
rep(i, 0, n) if (f[i] == 0) dfs(i, 0ll);
rep(i, 0, n) { printf(i == n - 1 ? "%lld\n" : "%lld ", c[i]); }
return 0;
}
| #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <bitset>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (auto i = a; i < b; i++)
#define rep2(i, a) for (auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) {
ll a = 1;
while (p > 0) {
if (p % 2 == 0) {
x *= x;
p /= 2;
} else {
a *= x;
p--;
}
}
return a;
}
ll mpower(ll x, ll p) {
ll a = 1;
while (p > 0) {
if (p % 2 == 0) {
x = x * x % mod;
p /= 2;
} else {
a = a * x % mod;
p--;
}
}
return a;
}
ll co(ll n, ll k) {
ll a = 1;
rep(i, 1ll, k) {
a *= n - i + 1;
a /= i;
}
return a;
}
ll mc(ll n, ll m) {
ll k = 1, l = 1;
rep(i, n - m + 1, n + 1) k = k * i % mod;
rep(i, 1, m + 1) l = l * i % mod;
l = mpower(l, mod - 2);
return k * l % mod;
}
vector<vector<int>> G;
vector<ll> c;
vector<int> f;
void dfs(int v, ll x) {
f[v] = 1;
c[v] += x;
rep2(nv, G[v]) {
if (f[nv] == 0)
dfs(nv, c[v]);
}
}
int main(void) {
int n, q;
cin >> n >> q;
G.resize(n);
c.resize(n);
f.resize(n);
rep(i, 0, n - 1) {
int a, b;
cin >> a >> b;
a--, b--;
G[a].push_back(b);
G[b].push_back(a);
}
rep(i, 0, q) {
int p, x;
cin >> p >> x;
c[p - 1] += (ll)x;
}
rep(i, 0, n) if (f[i] == 0) dfs(i, 0ll);
rep(i, 0, n) { printf(i == n - 1 ? "%lld\n" : "%lld ", c[i]); }
return 0;
}
| replace | 77 | 78 | 77 | 81 | -11 | |
p02936 | C++ | Runtime Error | // #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
vector<vector<int>> to(100100);
vector<int> x(100100);
vector<bool> seen(100100, false);
void dfs(int v) {
seen[v] = true;
for (auto nv : to[v]) {
if (seen[nv])
continue;
x[nv] += x[v];
dfs(nv);
}
}
int main() {
int n, q;
cin >> n >> q;
rep(i, n - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
to[a].push_back(b);
to[b].push_back(a);
}
rep(i, q) {
int p;
cin >> p;
p--;
int a;
cin >> a;
x[p] += a;
}
dfs(0);
rep(i, n) printf("%d ", x[i]);
cout << endl;
return 0;
} | // #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
const int M = 212345;
vector<vector<int>> to(M);
vector<int> x(M);
vector<bool> seen(M, false);
void dfs(int v) {
seen[v] = true;
for (auto nv : to[v]) {
if (seen[nv])
continue;
x[nv] += x[v];
dfs(nv);
}
}
int main() {
int n, q;
cin >> n >> q;
rep(i, n - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
to[a].push_back(b);
to[b].push_back(a);
}
rep(i, q) {
int p;
cin >> p;
p--;
int a;
cin >> a;
x[p] += a;
}
dfs(0);
rep(i, n) printf("%d ", x[i]);
cout << endl;
return 0;
} | replace | 8 | 11 | 8 | 13 | 0 | |
p02936 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define INF 2e9
#define ll long long
ll n, q;
ll ans[200001];
queue<ll> que[200001];
ll ad[200001];
void add(ll p, ll x) {
ans[p] += x;
int que_s = que[p].size();
for (int k = 0; k < que_s; k++) {
int s = que[p].front();
que[p].pop();
que[p].push(s);
add(s, x);
}
}
int main() {
cin >> n >> q;
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
que[a].push(b);
}
for (int i = 0; i < q; i++) {
int p, x;
cin >> p >> x;
ad[p] += x;
}
for (int i = 1; i <= n; i++) {
if (ad[i] > 0) {
add(i, ad[i]);
}
}
for (int i = 1; i <= n; i++) {
cout << ans[i] << " ";
}
cout << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define INF 2e9
#define ll long long
ll n, q;
ll ans[200001];
queue<ll> que[200001];
ll ad[200001];
void add(ll p, ll x) {
ans[p] += x;
int que_s = que[p].size();
for (int k = 0; k < que_s; k++) {
int s = que[p].front();
que[p].pop();
que[p].push(s);
ad[s] += x;
}
}
int main() {
cin >> n >> q;
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
que[a].push(b);
}
for (int i = 0; i < q; i++) {
int p, x;
cin >> p >> x;
ad[p] += x;
}
for (int i = 1; i <= n; i++) {
if (ad[i] > 0) {
add(i, ad[i]);
}
}
for (int i = 1; i <= n; i++) {
cout << ans[i] << " ";
}
cout << endl;
return 0;
} | replace | 17 | 18 | 17 | 18 | TLE | |
p02936 | 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;
vector<vector<int>> to;
vector<int> ans;
void dfs(int v, int p = -1) {
rep(i, to[v].size()) {
int u = to[v][i];
if (u == p)
continue;
ans[u] += ans[v];
dfs(u, v);
}
}
int main() {
int n, q;
cin >> n >> q;
int a, b;
rep(i, n - 1) {
cin >> a >> b;
--a;
--b;
to[a].push_back(b);
to[b].push_back(a);
}
ans.resize(n);
int p, x;
rep(i, q) {
cin >> p >> x;
--p;
ans[p] += x;
}
dfs(0);
rep(i, n) 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;
vector<vector<int>> to;
vector<int> ans;
void dfs(int v, int p = -1) {
rep(i, to[v].size()) {
int u = to[v][i];
if (u == p)
continue;
ans[u] += ans[v];
dfs(u, v);
}
}
int main() {
int n, q;
cin >> n >> q;
to.resize(n);
int a, b;
rep(i, n - 1) {
cin >> a >> b;
--a;
--b;
to[a].push_back(b);
to[b].push_back(a);
}
ans.resize(n);
int p, x;
rep(i, q) {
cin >> p >> x;
--p;
ans[p] += x;
}
dfs(0);
rep(i, n) cout << ans[i] << endl;
return 0;
} | insert | 20 | 20 | 20 | 21 | -11 | |
p02936 | C++ | Runtime Error | #include <bits/stdc++.h>
#define M_PI 3.14159265358979323846
using namespace std;
// conversion
//------------------------------------------
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
inline int readInt() {
int x;
scanf("%d", &x);
return x;
}
// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a) * (a))
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
// repetition
//------------------------------------------
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
struct Edge {
int to, from;
ll cost;
Edge(int from, int to, ll cost) : from(from), to(to), cost(cost) {}
};
typedef vector<vector<Edge>> AdjList;
AdjList graph;
vector<vector<int>> G(200010);
ll ans[200010];
ll plusl[200010];
void dfs(int v, ll x, int prev) {
ans[v] = x;
for (int i = 0; i < G[v].size(); ++i) {
int u = G[v][i];
if (u == prev)
continue;
dfs(u, x + plusl[u], u);
}
}
int main() {
// cin.tie(0);
// ios::sync_with_stdio(false);
// cout << fixed << setprecision(10);
int N, Q;
cin >> N >> Q;
REP(i, N - 1) {
ll a, b;
cin >> a >> b;
a--;
b--;
G[a].push_back(b);
G[b].push_back(a);
}
set<ll> st;
REP(i, Q) {
ll p, x;
cin >> p >> x;
p--;
st.insert(p);
plusl[p] += x;
}
dfs(0, plusl[0], -1);
REP(i, N) {
if (i)
cout << " ";
cout << ans[i];
}
cout << endl;
return 0;
} | #include <bits/stdc++.h>
#define M_PI 3.14159265358979323846
using namespace std;
// conversion
//------------------------------------------
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
inline int readInt() {
int x;
scanf("%d", &x);
return x;
}
// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a) * (a))
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
// repetition
//------------------------------------------
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
struct Edge {
int to, from;
ll cost;
Edge(int from, int to, ll cost) : from(from), to(to), cost(cost) {}
};
typedef vector<vector<Edge>> AdjList;
AdjList graph;
vector<vector<int>> G(200010);
ll ans[200010];
ll plusl[200010];
void dfs(int v, ll x, int prev) {
ans[v] = x;
for (int i = 0; i < G[v].size(); ++i) {
int u = G[v][i];
if (u == prev)
continue;
dfs(u, x + plusl[u], v);
}
}
int main() {
// cin.tie(0);
// ios::sync_with_stdio(false);
// cout << fixed << setprecision(10);
int N, Q;
cin >> N >> Q;
REP(i, N - 1) {
ll a, b;
cin >> a >> b;
a--;
b--;
G[a].push_back(b);
G[b].push_back(a);
}
set<ll> st;
REP(i, Q) {
ll p, x;
cin >> p >> x;
p--;
st.insert(p);
plusl[p] += x;
}
dfs(0, plusl[0], -1);
REP(i, N) {
if (i)
cout << " ";
cout << ans[i];
}
cout << endl;
return 0;
}
| replace | 89 | 90 | 89 | 90 | -11 | |
p02936 | C++ | Time Limit Exceeded | #include <cmath>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
using namespace std;
typedef long long ll;
vector<int> to[200005]; // vector の配列
vector<int> ans;
void dfs(int v, int p = -1) { // デフォルト因数
for (int u : to[v]) {
if (u == p)
continue;
ans[u] += ans[v];
dfs(u, v);
}
}
int main(void) {
int n, q;
cin >> n >> q;
rep(i, n - 1) {
int a, b;
cin >> a >> b;
--a;
--b;
to[a].push_back(b);
to[b].push_back(a);
}
ans.resize(n);
rep(i, q) {
int p, x;
cin >> p >> x;
--p;
ans[p] += x;
}
dfs(0);
rep(i, n) { cout << ans[i] << endl; }
return 0;
}
| #include <cmath>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
using namespace std;
typedef long long ll;
vector<int> to[200005]; // vector の配列
vector<int> ans;
void dfs(int v, int p = -1) { // デフォルト因数
for (int i = 0; i < to[v].size(); i++) {
int u = to[v][i];
if (u == p)
continue;
ans[u] += ans[v];
dfs(u, v);
}
}
int main(void) {
int n, q;
cin >> n >> q;
rep(i, n - 1) {
int a, b;
cin >> a >> b;
--a;
--b;
to[a].push_back(b);
to[b].push_back(a);
}
ans.resize(n);
rep(i, q) {
int p, x;
cin >> p >> x;
--p;
ans[p] += x;
}
dfs(0);
rep(i, n) { cout << ans[i] << endl; }
return 0;
}
| replace | 17 | 18 | 17 | 19 | TLE | |
p02936 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int maxd = 1e5 + 10;
struct {
int v, net;
} e[maxd << 1];
int f[maxd], eid, v[maxd];
void init() {
eid = 0;
memset(f, -1, sizeof(f));
}
void insert(int x, int y) {
e[eid].v = y;
e[eid].net = f[x];
f[x] = eid++;
}
int vis[maxd], ans[maxd];
void dfs(int x, int sum) {
sum += v[x];
ans[x] = sum;
vis[x] = 1;
for (int i = f[x]; i + 1; i = e[i].net) {
int v = e[i].v;
if (vis[v])
continue;
dfs(v, sum);
}
}
int main() {
// freopen("a.in","r",stdin);
// freopen("k.out","w",stdout);
int n, m;
init();
scanf("%d %d", &n, &m);
for (int i = 1; i < n; i++) {
int x, y;
scanf("%d %d", &x, &y);
insert(x, y);
insert(y, x);
}
for (int i = 1; i <= m; i++) {
int x, y;
scanf("%d %d", &x, &y);
v[x] += y;
}
dfs(1, 0);
for (int i = 1; i <= n; i++)
printf("%d ", ans[i]);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int maxd = 2e5 + 10;
struct {
int v, net;
} e[maxd << 1];
int f[maxd], eid, v[maxd];
void init() {
eid = 0;
memset(f, -1, sizeof(f));
}
void insert(int x, int y) {
e[eid].v = y;
e[eid].net = f[x];
f[x] = eid++;
}
int vis[maxd], ans[maxd];
void dfs(int x, int sum) {
sum += v[x];
ans[x] = sum;
vis[x] = 1;
for (int i = f[x]; i + 1; i = e[i].net) {
int v = e[i].v;
if (vis[v])
continue;
dfs(v, sum);
}
}
int main() {
// freopen("a.in","r",stdin);
// freopen("k.out","w",stdout);
int n, m;
init();
scanf("%d %d", &n, &m);
for (int i = 1; i < n; i++) {
int x, y;
scanf("%d %d", &x, &y);
insert(x, y);
insert(y, x);
}
for (int i = 1; i <= m; i++) {
int x, y;
scanf("%d %d", &x, &y);
v[x] += y;
}
dfs(1, 0);
for (int i = 1; i <= n; i++)
printf("%d ", ans[i]);
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02936 | C++ | Runtime Error | #include <iostream>
#include <queue>
#include <vector>
using namespace std;
vector<int> count(100000, 0);
vector<int> counter(100000, 0);
vector<int> vis(100000, 0);
void dfs(vector<int> v[], int index) {
queue<int> q;
q.push(index);
int sum;
count[0] = counter[0];
while (!q.empty()) {
int t = q.front();
sum = count[t];
q.pop();
vis[t] = 1;
for (int i = 0; i < v[t].size(); i++) {
if (!vis[v[t][i]]) {
vis[v[t][i]] = 1;
count[v[t][i]] = sum + counter[v[t][i]];
q.push(v[t][i]);
}
}
}
}
int main() {
int n, q;
cin >> n >> q;
vector<int> v[n];
int a, b;
for (int i = 0; i < n - 1; i++) {
cin >> a >> b;
a--, b--;
v[a].push_back(b);
v[b].push_back(a);
}
int p, val;
for (int i = 0; i < q; i++) {
cin >> p;
p--;
cin >> val;
counter[p] += val;
}
dfs(v, 0);
for (int i = 0; i < n; i++)
cout << count[i] << " ";
}
| #include <iostream>
#include <queue>
#include <vector>
using namespace std;
vector<int> count(300000, 0);
vector<int> counter(300000, 0);
vector<int> vis(300000, 0);
void dfs(vector<int> v[], int index) {
queue<int> q;
q.push(index);
int sum;
count[0] = counter[0];
while (!q.empty()) {
int t = q.front();
sum = count[t];
q.pop();
vis[t] = 1;
for (int i = 0; i < v[t].size(); i++) {
if (!vis[v[t][i]]) {
vis[v[t][i]] = 1;
count[v[t][i]] = sum + counter[v[t][i]];
q.push(v[t][i]);
}
}
}
}
int main() {
int n, q;
cin >> n >> q;
vector<int> v[n];
int a, b;
for (int i = 0; i < n - 1; i++) {
cin >> a >> b;
a--, b--;
v[a].push_back(b);
v[b].push_back(a);
}
int p, val;
for (int i = 0; i < q; i++) {
cin >> p;
p--;
cin >> val;
counter[p] += val;
}
dfs(v, 0);
for (int i = 0; i < n; i++)
cout << count[i] << " ";
}
| replace | 4 | 7 | 4 | 7 | 0 | |
p02936 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#include <iomanip>
#include <math.h>
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;
}
int N;
vector<int> G[20005];
vector<int> color;
vector<int> ans;
void dfs(int now) {
color[now] = 1;
for (int next : G[now]) {
if (color[next] == 0) {
ans[next] += ans[now];
dfs(next);
}
}
color[now] = 2;
}
int main() {
cin >> N;
int Q;
cin >> Q;
color.resize(N);
ans.resize(N);
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);
}
for (int i = 0; i < Q; i++) {
int p, x;
cin >> p >> x;
p--;
ans[p] += x;
}
dfs(0);
for (int i = 0; i < N; i++) {
cout << ans[i] << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#include <iomanip>
#include <math.h>
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;
}
int N;
vector<int> G[200005];
vector<int> color;
vector<int> ans;
void dfs(int now) {
color[now] = 1;
for (int next : G[now]) {
if (color[next] == 0) {
ans[next] += ans[now];
dfs(next);
}
}
color[now] = 2;
}
int main() {
cin >> N;
int Q;
cin >> Q;
color.resize(N);
ans.resize(N);
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);
}
for (int i = 0; i < Q; i++) {
int p, x;
cin >> p >> x;
p--;
ans[p] += x;
}
dfs(0);
for (int i = 0; i < N; i++) {
cout << ans[i] << endl;
}
return 0;
} | replace | 19 | 20 | 19 | 20 | 0 | |
p02936 | C++ | Runtime Error | #include "bits/stdc++.h"
#define MOD 1000000007
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define DUMP(i, v) \
for (ll i = 0; i < v.size(); i++) \
cout << v[i] << " "
using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
struct Edge {
ll from, to, cost;
};
ll mod(ll a, ll mod) {
ll res = a % mod;
if (res < 0)
res = res + mod;
return res;
}
ll modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
ll modinv(ll a, ll mod) { return modpow(a, mod - 2, mod); }
bool is_prime(ll n) {
ll i = 2;
if (n == 1)
return false;
if (n == 2)
return true;
bool res = true;
while (i * i < n) {
if (n % i == 0) {
res = false;
}
i = i + 1;
}
// if(i==1)res = false;
if (n % i == 0)
res = false;
return res;
}
ll N, Q;
llvec v[20001];
ll c[20001];
ll dfs(ll from, ll to) {
c[to] += c[from];
rep(i, v[to].size()) {
if (v[to][i] != from) {
dfs(to, v[to][i]);
}
}
}
/**************************************
** A main function starts from here **
***************************************/
int main() {
cin >> N >> Q;
rep(i, N - 1) {
ll a, b;
cin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}
llvec count(N + 1, 0);
rep(i, Q) {
ll q, a;
cin >> q >> a;
c[q] += a;
}
dfs(0, 1);
rep(i, N) { cout << c[i + 1] << endl; }
return 0;
}
| #include "bits/stdc++.h"
#define MOD 1000000007
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define DUMP(i, v) \
for (ll i = 0; i < v.size(); i++) \
cout << v[i] << " "
using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
struct Edge {
ll from, to, cost;
};
ll mod(ll a, ll mod) {
ll res = a % mod;
if (res < 0)
res = res + mod;
return res;
}
ll modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
ll modinv(ll a, ll mod) { return modpow(a, mod - 2, mod); }
bool is_prime(ll n) {
ll i = 2;
if (n == 1)
return false;
if (n == 2)
return true;
bool res = true;
while (i * i < n) {
if (n % i == 0) {
res = false;
}
i = i + 1;
}
// if(i==1)res = false;
if (n % i == 0)
res = false;
return res;
}
ll N, Q;
llvec v[200001];
ll c[200001];
ll dfs(ll from, ll to) {
c[to] += c[from];
rep(i, v[to].size()) {
if (v[to][i] != from) {
dfs(to, v[to][i]);
}
}
}
/**************************************
** A main function starts from here **
***************************************/
int main() {
cin >> N >> Q;
rep(i, N - 1) {
ll a, b;
cin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}
llvec count(N + 1, 0);
rep(i, Q) {
ll q, a;
cin >> q >> a;
c[q] += a;
}
dfs(0, 1);
rep(i, N) { cout << c[i + 1] << endl; }
return 0;
}
| replace | 59 | 61 | 59 | 61 | 0 | |
p02936 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = ll;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
const int MAX = 510000;
bool graph[nmax][nmax];
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;
}
}
ll 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;
}
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
struct SegmentTree {
private:
ll n;
vector<ll> node;
public:
SegmentTree(vector<ll> v) {
ll sz = v.size();
n = 1;
while (n < sz) {
n *= 2;
}
node.resize(2 * n - 1, INF);
for (ll i = 0; i < sz; i++) {
node[i + n - 1] = v[i];
}
for (ll i = n - 2; i >= 0; i--) {
node[i] = min(node[2 * i + 1], node[2 * i + 2]);
}
}
void update(ll x, ll val) {
x += (n - 1);
node[x] = val;
while (x > 0) {
x = (x - 1) / 2;
node[x] = min(node[2 * x + 1], node[2 * x + 2]);
}
}
// findは半開区間で考える
ll find(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) {
if (r < 0)
r = n;
if (r <= a || b <= l)
return INF;
if (a <= l && r <= b)
return node[k];
ll vl = find(a, b, 2 * k + 1, l, (l + r) / 2);
ll vr = find(a, b, 2 * k + 2, (l + r) / 2, r);
return min(vl, vr);
}
};
void warshall_floyd(ll n) {
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < n; j++) {
for (size_t k = 0; k < n; k++) {
dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
}
}
}
}
class UnionFind {
public:
vector<ll> Parent;
UnionFind(ll N) { Parent = vector<ll>(N, -1); }
ll find(ll A) {
if (Parent[A] < 0)
return A;
return Parent[A] = find(Parent[A]);
}
ll size(ll A) { return -Parent[find(A)]; }
bool Union(ll A, ll B) {
A = find(A);
B = find(B);
if (A == B) {
return false;
}
if (size(A) < size(B))
swap(A, B);
Parent[A] += Parent[B];
Parent[B] = A;
return true;
}
};
ll gcd(ll a, ll 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;
}
ll mulMod(ll a, ll b) { return (((a % MOD) * (b % MOD)) % MOD); }
ll powMod(ll a, ll p) {
if (p == 0) {
return 1;
} else if (p % 2 == 0) {
ll half = powMod(a, p / 2);
return mulMod(half, half);
} else {
return mulMod(powMod(a, p - 1), a);
}
}
ll ceil(ll a, ll b) { return (a + b - 1) / b; }
vector<ll> tsort(Graph G) {
ll N = G.size();
vector<ll> in(N);
for (auto &&edges : G) {
for (auto &&edge : edges) {
in[edge]++;
}
}
queue<int> que;
for (int i = 0; i < N; i++) {
if (in[i] == 0) {
que.push(i);
}
}
int cnt = 0;
vector<ll> ans;
while (!que.empty()) {
int v = que.front();
que.pop();
ans.push_back(v);
for (auto &&next : G[v]) {
in[next]--;
if (in[next] == 0) {
que.push(next);
}
}
}
return ans;
}
Graph G(100);
void treeDFS(int from, int current, int dist, int &maxDist, int &maxVertex) {
if (dist > maxDist) {
maxDist = dist;
maxVertex = current;
}
for (auto to : G[current]) {
if (to == from)
continue;
treeDFS(current, to, dist + 1, maxDist, maxVertex);
}
}
pair<int, int> getTreeDiameter() {
int start = 0, end = 0, maxDist = 0;
treeDFS(-1, start, 0, maxDist, end);
start = end, end = 0, maxDist = 0;
treeDFS(-1, start, 0, maxDist, end);
return make_pair(start, end);
}
ll ans[200010];
vector<bool> seen;
void dfs(int p, int score, Graph G) {
seen[p] = true;
ans[p] += score;
for (auto &&i : G[p]) {
if (seen[i])
continue;
dfs(i, ans[p], G);
}
return;
}
int main() {
long long N;
scanf("%lld", &N);
long long Q;
scanf("%lld", &Q);
Graph G(N);
seen.assign(N, false);
for (int i = 0; i < N - 1; i++) {
ll a, b;
cin >> a >> b;
--a;
--b;
G[a].push_back(b);
G[b].push_back(a);
}
for (int i = 0; i < Q; i++) {
ll a, b;
cin >> a >> b;
--a;
ans[a] += b;
}
dfs(0, 0, G);
for (int i = 0; i < N; i++) {
cout << ans[i] << " ";
}
cout << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = ll;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
const int MAX = 510000;
bool graph[nmax][nmax];
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;
}
}
ll 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;
}
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
struct SegmentTree {
private:
ll n;
vector<ll> node;
public:
SegmentTree(vector<ll> v) {
ll sz = v.size();
n = 1;
while (n < sz) {
n *= 2;
}
node.resize(2 * n - 1, INF);
for (ll i = 0; i < sz; i++) {
node[i + n - 1] = v[i];
}
for (ll i = n - 2; i >= 0; i--) {
node[i] = min(node[2 * i + 1], node[2 * i + 2]);
}
}
void update(ll x, ll val) {
x += (n - 1);
node[x] = val;
while (x > 0) {
x = (x - 1) / 2;
node[x] = min(node[2 * x + 1], node[2 * x + 2]);
}
}
// findは半開区間で考える
ll find(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) {
if (r < 0)
r = n;
if (r <= a || b <= l)
return INF;
if (a <= l && r <= b)
return node[k];
ll vl = find(a, b, 2 * k + 1, l, (l + r) / 2);
ll vr = find(a, b, 2 * k + 2, (l + r) / 2, r);
return min(vl, vr);
}
};
void warshall_floyd(ll n) {
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < n; j++) {
for (size_t k = 0; k < n; k++) {
dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
}
}
}
}
class UnionFind {
public:
vector<ll> Parent;
UnionFind(ll N) { Parent = vector<ll>(N, -1); }
ll find(ll A) {
if (Parent[A] < 0)
return A;
return Parent[A] = find(Parent[A]);
}
ll size(ll A) { return -Parent[find(A)]; }
bool Union(ll A, ll B) {
A = find(A);
B = find(B);
if (A == B) {
return false;
}
if (size(A) < size(B))
swap(A, B);
Parent[A] += Parent[B];
Parent[B] = A;
return true;
}
};
ll gcd(ll a, ll 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;
}
ll mulMod(ll a, ll b) { return (((a % MOD) * (b % MOD)) % MOD); }
ll powMod(ll a, ll p) {
if (p == 0) {
return 1;
} else if (p % 2 == 0) {
ll half = powMod(a, p / 2);
return mulMod(half, half);
} else {
return mulMod(powMod(a, p - 1), a);
}
}
ll ceil(ll a, ll b) { return (a + b - 1) / b; }
vector<ll> tsort(Graph G) {
ll N = G.size();
vector<ll> in(N);
for (auto &&edges : G) {
for (auto &&edge : edges) {
in[edge]++;
}
}
queue<int> que;
for (int i = 0; i < N; i++) {
if (in[i] == 0) {
que.push(i);
}
}
int cnt = 0;
vector<ll> ans;
while (!que.empty()) {
int v = que.front();
que.pop();
ans.push_back(v);
for (auto &&next : G[v]) {
in[next]--;
if (in[next] == 0) {
que.push(next);
}
}
}
return ans;
}
Graph G(100);
void treeDFS(int from, int current, int dist, int &maxDist, int &maxVertex) {
if (dist > maxDist) {
maxDist = dist;
maxVertex = current;
}
for (auto to : G[current]) {
if (to == from)
continue;
treeDFS(current, to, dist + 1, maxDist, maxVertex);
}
}
pair<int, int> getTreeDiameter() {
int start = 0, end = 0, maxDist = 0;
treeDFS(-1, start, 0, maxDist, end);
start = end, end = 0, maxDist = 0;
treeDFS(-1, start, 0, maxDist, end);
return make_pair(start, end);
}
ll ans[200010];
vector<bool> seen;
void dfs(int p, int score, const Graph &G) {
seen[p] = true;
ans[p] += score;
for (auto &&i : G[p]) {
if (seen[i])
continue;
dfs(i, ans[p], G);
}
return;
}
int main() {
long long N;
scanf("%lld", &N);
long long Q;
scanf("%lld", &Q);
Graph G(N);
seen.assign(N, false);
for (int i = 0; i < N - 1; i++) {
ll a, b;
cin >> a >> b;
--a;
--b;
G[a].push_back(b);
G[b].push_back(a);
}
for (int i = 0; i < Q; i++) {
ll a, b;
cin >> a >> b;
--a;
ans[a] += b;
}
dfs(0, 0, G);
for (int i = 0; i < N; i++) {
cout << ans[i] << " ";
}
cout << endl;
return 0;
}
| replace | 203 | 204 | 203 | 204 | TLE | |
p02936 | C++ | Runtime Error | #include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a) / __gcd((a), (b)) * (b)
#define endl '\n'
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> iP;
typedef pair<P, P> PP;
static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;
const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};
vector<int> Div(int n) {
vector<int> ret;
for (int i = 1; i * i <= n; ++i) {
if (n % i == 0) {
ret.pb(i);
if (i * i != n)
ret.pb(n / i);
}
}
sort(all(ret));
return ret;
}
void makeTree(int pos);
void treeAdd(int pos, int sum);
vector<int> tree[SIZE], graph[SIZE];
int total[SIZE];
int res;
bool visit[SIZE];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
for (int i = 0; i < n - 1; ++i) {
int a, b;
cin >> a >> b;
graph[a].pb(b);
graph[b].pb(a);
}
makeTree(1);
for (int i = 0; i < q; ++i) {
int p, x;
cin >> p >> x;
total[p] += x;
}
treeAdd(1, 0);
cout << total[1];
for (int i = 2; i <= n; ++i) {
cout << " " << total[i];
}
cout << endl;
return 0;
}
void makeTree(int pos) {
visit[pos] = true;
for (int i = 0; i < graph[pos].size(); ++i) {
if (visit[graph[pos][i]])
continue;
tree[pos].pb(graph[pos][i]);
makeTree(graph[pos][i]);
}
return;
}
void treeAdd(int pos, int sum) {
sum += total[pos];
total[pos] = sum;
res += sum;
for (int i = 0; i < tree[pos].size(); ++i) {
treeAdd(tree[pos][i], sum);
}
return;
}
| #include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a) / __gcd((a), (b)) * (b)
#define endl '\n'
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> iP;
typedef pair<P, P> PP;
static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 300005;
const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};
vector<int> Div(int n) {
vector<int> ret;
for (int i = 1; i * i <= n; ++i) {
if (n % i == 0) {
ret.pb(i);
if (i * i != n)
ret.pb(n / i);
}
}
sort(all(ret));
return ret;
}
void makeTree(int pos);
void treeAdd(int pos, int sum);
vector<int> tree[SIZE], graph[SIZE];
int total[SIZE];
int res;
bool visit[SIZE];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
for (int i = 0; i < n - 1; ++i) {
int a, b;
cin >> a >> b;
graph[a].pb(b);
graph[b].pb(a);
}
makeTree(1);
for (int i = 0; i < q; ++i) {
int p, x;
cin >> p >> x;
total[p] += x;
}
treeAdd(1, 0);
cout << total[1];
for (int i = 2; i <= n; ++i) {
cout << " " << total[i];
}
cout << endl;
return 0;
}
void makeTree(int pos) {
visit[pos] = true;
for (int i = 0; i < graph[pos].size(); ++i) {
if (visit[graph[pos][i]])
continue;
tree[pos].pb(graph[pos][i]);
makeTree(graph[pos][i]);
}
return;
}
void treeAdd(int pos, int sum) {
sum += total[pos];
total[pos] = sum;
res += sum;
for (int i = 0; i < tree[pos].size(); ++i) {
treeAdd(tree[pos][i], sum);
}
return;
}
| replace | 72 | 73 | 72 | 73 | 0 | |
p02936 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define print(n) cout << n << endl
#define rep(i, a, n) for (int i = a; i < n; i++)
#define ALL(s) s.begin(), s.end()
#define P pair<ll, ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M = 100111;
const int inf = 1000000007;
const long long INF = 1e18;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
int ddx[8] = {1, -1, 0, 0, 1, -1, -1, 1}, ddy[8] = {0, 0, 1, -1, 1, -1, 1, -1};
/*
vvl comb(int n, int r) {
vvl v(n + 1,vl(n + 1, 0));
for (int i = 0; i < v.size(); i++) {
v[i][0] = 1;
v[i][i] = 1;
}
for (int j = 1; j < v.size(); j++) {
for (int k = 1; k < j; k++) {
v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
}
}
return v;
}
*/
vi v[M];
int n, q, a, b, p, x, c[M] = {};
void dfs(int now, int pre) {
c[now] += c[pre];
for (int next : v[now])
if (next != pre) {
dfs(next, now);
}
}
int main() {
cin >> n >> q;
rep(i, 0, n - 1) {
cin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}
rep(i, 0, q) cin >> p >> x, c[p] += x;
dfs(1, 0);
rep(i, 1, n + 1) {
cout << c[i];
if (i != n)
cout << " ";
}
} | #include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define print(n) cout << n << endl
#define rep(i, a, n) for (int i = a; i < n; i++)
#define ALL(s) s.begin(), s.end()
#define P pair<ll, ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M = 100111;
const int inf = 1000000007;
const long long INF = 1e18;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
int ddx[8] = {1, -1, 0, 0, 1, -1, -1, 1}, ddy[8] = {0, 0, 1, -1, 1, -1, 1, -1};
/*
vvl comb(int n, int r) {
vvl v(n + 1,vl(n + 1, 0));
for (int i = 0; i < v.size(); i++) {
v[i][0] = 1;
v[i][i] = 1;
}
for (int j = 1; j < v.size(); j++) {
for (int k = 1; k < j; k++) {
v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
}
}
return v;
}
*/
vi v[2 * M];
int n, q, a, b, p, x, c[2 * M] = {};
void dfs(int now, int pre) {
c[now] += c[pre];
for (int next : v[now])
if (next != pre) {
dfs(next, now);
}
}
int main() {
cin >> n >> q;
rep(i, 0, n - 1) {
cin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}
rep(i, 0, q) cin >> p >> x, c[p] += x;
dfs(1, 0);
rep(i, 1, n + 1) {
cout << c[i];
if (i != n)
cout << " ";
}
} | replace | 33 | 35 | 33 | 35 | 0 | |
p02936 | Python | Time Limit Exceeded | import sys
sys.setrecursionlimit(10**6)
n, q = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(n - 1):
a, b = map(int, input().split())
a -= 1
b -= 1
edges[a].append(b)
edges[b].append(a)
counter = [0] * n
for _ in range(q):
p, x = map(int, input().split())
p -= 1
counter[p] += x
ans = [0] * n
def f(par, node, count):
count += counter[node]
ans[node] = count
for n in edges[node]:
if n == par:
continue
f(node, n, count)
f(-1, 0, 0)
print(*ans)
| import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
n, q = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(n - 1):
a, b = map(int, input().split())
a -= 1
b -= 1
edges[a].append(b)
edges[b].append(a)
counter = [0] * n
for _ in range(q):
p, x = map(int, input().split())
p -= 1
counter[p] += x
ans = [0] * n
def f(par, node, count):
count += counter[node]
ans[node] = count
for n in edges[node]:
if n == par:
continue
f(node, n, count)
f(-1, 0, 0)
print(*ans)
| insert | 3 | 3 | 3 | 4 | TLE | |
p02936 | Python | Runtime Error | N, Q = map(int, input().split())
tree = [[0] * 1 for i in range(N)]
tree_list = [0] * N
end = [0] * N
for index in range(N - 1):
a, b = map(lambda x: int(x) - 1, input().split())
tree[a].append(b)
tree[b].append(a)
for index in range(Q):
a, b = map(int, input().split())
a -= 1
tree_list[a] += b
def iter(node):
end[node] = -1
child = tree[node]
for c in child:
if end[c] == 0:
tree_list[c] += tree_list[node]
iter(c)
iter(0)
print(*tree_list)
| import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline
N, Q = map(int, input().split())
tree = [[0] * 1 for i in range(N)]
tree_list = [0] * N
end = [0] * N
for index in range(N - 1):
a, b = map(lambda x: int(x) - 1, input().split())
tree[a].append(b)
tree[b].append(a)
for index in range(Q):
a, b = map(int, input().split())
a -= 1
tree_list[a] += b
def iter(node):
end[node] = -1
child = tree[node]
for c in child:
if end[c] == 0:
tree_list[c] += tree_list[node]
iter(c)
iter(0)
print(*tree_list)
| insert | 0 | 0 | 0 | 5 | 0 | |
p02936 | Python | Time Limit Exceeded | from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)
N, Q = map(int, input().split())
e = [[] for _ in range(N + 1)]
for i in range(N - 1):
a, b = map(int, input().split())
e[a].append(b)
q = defaultdict(int)
for i in range(Q):
p, x = map(int, input().split())
q[p] += x
seen = [False] * (N + 1)
ans = [0] * (N + 1)
def dfs(e, v, x):
seen[v] = True
ans[v] += x
for next_v in e[v]:
if seen[next_v]:
continue
else:
dfs(e, next_v, x + q[next_v])
dfs(e, 1, q[1])
print(*ans[1:])
| from collections import defaultdict
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
N, Q = map(int, input().split())
e = [[] for _ in range(N + 1)]
for i in range(N - 1):
a, b = map(int, input().split())
e[a].append(b)
q = defaultdict(int)
for i in range(Q):
p, x = map(int, input().split())
q[p] += x
seen = [False] * (N + 1)
ans = [0] * (N + 1)
def dfs(e, v, x):
seen[v] = True
ans[v] += x
for next_v in e[v]:
if seen[next_v]:
continue
else:
dfs(e, next_v, x + q[next_v])
dfs(e, 1, q[1])
print(*ans[1:])
| insert | 2 | 2 | 2 | 4 | TLE | |
p02936 | Python | Time Limit Exceeded | from collections import defaultdict
import sys
sys.setrecursionlimit(10**9)
N, Q = map(int, input().split())
G = defaultdict(list)
for i in range(N - 1):
a, b = map(int, input().split())
a, b = a - 1, b - 1 # 0-indexed
G[a].append(b)
G[b].append(a)
# print('G', G)
V = [0] * N
for _ in range(Q):
p, x = map(int, input().split())
p = p - 1 # 0-indexed
V[p] += x
def dfs(v, p):
if p != -1:
V[v] += V[p]
for idx in G[v]:
if idx == p:
continue
dfs(idx, v)
dfs(0, -1)
# print('V', V)
print(" ".join(map(str, V)))
| from collections import defaultdict
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
N, Q = map(int, input().split())
G = defaultdict(list)
for i in range(N - 1):
a, b = map(int, input().split())
a, b = a - 1, b - 1 # 0-indexed
G[a].append(b)
G[b].append(a)
# print('G', G)
V = [0] * N
for _ in range(Q):
p, x = map(int, input().split())
p = p - 1 # 0-indexed
V[p] += x
def dfs(v, p):
if p != -1:
V[v] += V[p]
for idx in G[v]:
if idx == p:
continue
dfs(idx, v)
dfs(0, -1)
# print('V', V)
print(" ".join(map(str, V)))
| replace | 3 | 4 | 3 | 5 | TLE | |
p02936 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < N; i++)
#define rep2(i, N) for (int i = 1; i <= N; i++)
using namespace std;
long long INF = 1e18;
long long mod = 1e9 + 7;
// status unsolved
int n, q;
vector<vector<int>> to(100010);
long long weight[100010] = {};
void dfs(int now, int before) {
if (before != -1)
weight[now] += weight[before];
for (auto next : to[now]) {
if (next == before)
continue;
dfs(next, now);
}
return;
}
int main() {
cin >> n >> q;
rep(i, n - 1) {
int a, b;
cin >> a >> b;
a--, b--;
to[a].emplace_back(b);
to[b].emplace_back(a);
}
rep(i, q) {
int p;
long long x;
cin >> p >> x;
p--;
weight[p] += x;
}
dfs(0, n);
rep(i, n) cout << weight[i] << " ";
cout << endl;
return 0;
}
/*
*/
| #include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < N; i++)
#define rep2(i, N) for (int i = 1; i <= N; i++)
using namespace std;
long long INF = 1e18;
long long mod = 1e9 + 7;
// status unsolved
int n, q;
vector<vector<int>> to(200010);
long long weight[200010] = {};
void dfs(int now, int before) {
if (before != -1)
weight[now] += weight[before];
for (auto next : to[now]) {
if (next == before)
continue;
dfs(next, now);
}
return;
}
int main() {
cin >> n >> q;
rep(i, n - 1) {
int a, b;
cin >> a >> b;
a--, b--;
to[a].emplace_back(b);
to[b].emplace_back(a);
}
rep(i, q) {
int p;
long long x;
cin >> p >> x;
p--;
weight[p] += x;
}
dfs(0, n);
rep(i, n) cout << weight[i] << " ";
cout << endl;
return 0;
}
/*
*/
| replace | 10 | 12 | 10 | 12 | 0 | |
p02936 | Python | Time Limit Exceeded | # -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**7)
n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
px = [list(map(int, input().split())) for _ in range(q)]
graph = [[] for _ in range(n + 1)]
for a, b in ab:
graph[a].append(b)
graph[b].append(a)
value = [0] * (n + 1)
for p, x in px:
value[p] += x
def dfs(v, p, add):
value[v] += add
for x in graph[v]:
if x == p:
continue
dfs(x, v, value[v])
dfs(1, 0, 0)
ans = value[1:]
print(*ans)
| # -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
px = [list(map(int, input().split())) for _ in range(q)]
graph = [[] for _ in range(n + 1)]
for a, b in ab:
graph[a].append(b)
graph[b].append(a)
value = [0] * (n + 1)
for p, x in px:
value[p] += x
def dfs(v, p, add):
value[v] += add
for x in graph[v]:
if x == p:
continue
dfs(x, v, value[v])
dfs(1, 0, 0)
ans = value[1:]
print(*ans)
| insert | 4 | 4 | 4 | 5 | TLE | |
p02936 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
queue<pair<int, long>> q;
void wfs(vector<vector<int>> Ed, vector<pair<long, int>> &Ve) {
if (q.empty() == 0) {
pair<int, long> v = q.front();
q.pop();
Ve[v.first].first += v.second;
for (int i = 0; i < Ed[v.first].size(); i++) {
if (Ed[v.first][i] != Ve[v.first].second) {
Ve[Ed[v.first][i]].second = v.first;
q.push(make_pair(Ed[v.first][i], Ve[v.first].first));
}
}
wfs(Ed, Ve);
}
}
int main() {
int N, Q;
cin >> N >> Q;
vector<vector<int>> Ed(N);
for (int i = 0; i < N - 1; i++) {
int a, b;
cin >> a >> b;
Ed[a - 1].push_back(b - 1);
Ed[b - 1].push_back(a - 1);
}
vector<pair<long, int>> Ve(N, make_pair(0, 0));
for (int i = 0; i < Q; i++) {
int p, x;
cin >> p >> x;
Ve[p - 1].first += x;
}
q.push(make_pair(0, 0));
wfs(Ed, Ve);
for (int i = 0; i < N; i++) {
cout << Ve[i].first;
if (i == N - 1)
cout << endl;
else
cout << ' ';
}
} | #include <bits/stdc++.h>
using namespace std;
queue<pair<int, long>> q;
void wfs(vector<vector<int>> &Ed, vector<pair<long, int>> &Ve) {
if (q.empty() == 0) {
pair<int, long> v = q.front();
q.pop();
Ve[v.first].first += v.second;
for (int i = 0; i < Ed[v.first].size(); i++) {
if (Ed[v.first][i] != Ve[v.first].second) {
Ve[Ed[v.first][i]].second = v.first;
q.push(make_pair(Ed[v.first][i], Ve[v.first].first));
}
}
wfs(Ed, Ve);
}
}
int main() {
int N, Q;
cin >> N >> Q;
vector<vector<int>> Ed(N);
for (int i = 0; i < N - 1; i++) {
int a, b;
cin >> a >> b;
Ed[a - 1].push_back(b - 1);
Ed[b - 1].push_back(a - 1);
}
vector<pair<long, int>> Ve(N, make_pair(0, 0));
for (int i = 0; i < Q; i++) {
int p, x;
cin >> p >> x;
Ve[p - 1].first += x;
}
q.push(make_pair(0, 0));
wfs(Ed, Ve);
for (int i = 0; i < N; i++) {
cout << Ve[i].first;
if (i == N - 1)
cout << endl;
else
cout << ' ';
}
} | replace | 5 | 6 | 5 | 6 | TLE | |
p02936 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
struct node {
int ff, num;
} v[20005];
int main() {
int n, q;
cin >> n >> q;
for (int i = 1; i <= n; i++) {
v[i].ff = 0;
v[i].num = 0;
}
for (int i = 1; i <= n - 1; i++) {
int x, y;
cin >> x >> y;
v[y].ff = x;
}
for (int i = 1; i <= q; i++) {
int x, y;
cin >> x;
cin >> y;
v[x].num += y;
}
cout << v[1].num;
for (int i = 2; i <= n; i++) {
v[i].num += v[v[i].ff].num;
cout << " " << v[i].num;
}
cout << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
struct node {
int ff, num;
} v[200005];
int main() {
int n, q;
cin >> n >> q;
for (int i = 1; i <= n; i++) {
v[i].ff = 0;
v[i].num = 0;
}
for (int i = 1; i <= n - 1; i++) {
int x, y;
cin >> x >> y;
v[y].ff = x;
}
for (int i = 1; i <= q; i++) {
int x, y;
cin >> x;
cin >> y;
v[x].num += y;
}
cout << v[1].num;
for (int i = 2; i <= n; i++) {
v[i].num += v[v[i].ff].num;
cout << " " << v[i].num;
}
cout << endl;
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02936 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
// typedef
//------------------------------------------
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(), (c).end())
#define COUT(x) cout << x << endl
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
// constant
//--------------------------------------------
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
const ULL INF = 1e18;
const int dx[]{1, -1, 0, 0}, dy[]{0, 0, 1, -1};
// function
//--------------------------------------------
LL gcd(LL, LL);
bool isEven(LL);
void coutY();
void coutN();
int main() {
LL n, q;
cin >> n >> q;
vector<PLL> ab(n - 1);
REP(i, n - 1) cin >> ab[i].first >> ab[i].second;
vector<PLL> ope(q);
REP(i, q) cin >> ope[i].first >> ope[i].second;
REP(i, n) {
ab[i].first--;
ab[i].second--;
}
REP(i, q) ope[i].first--;
VLL counter(n);
REP(i, q) counter[ope[i].first] += ope[i].second;
SORT(ab);
REP(i, n) { counter[ab[i].second] += counter[ab[i].first]; }
// REP(i,n-1)cout<<ab[i].first<<' '<<ab[i].second<<endl;
REP(i, n) cout << counter[i] << ' ';
}
LL gcd(LL a, LL b) {
if (a == 0 || b == 0)
return 0;
if (a < b)
swap(a, b);
if (a % b == 0)
return b;
else
gcd(b, a % b);
}
bool isEven(LL a) { return !((bool)(a % 2)); }
void coutY() {
cout << "Yes" << endl;
return;
}
void coutN() {
cout << "No" << endl;
return;
} | #include "bits/stdc++.h"
using namespace std;
// typedef
//------------------------------------------
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(), (c).end())
#define COUT(x) cout << x << endl
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
// constant
//--------------------------------------------
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
const ULL INF = 1e18;
const int dx[]{1, -1, 0, 0}, dy[]{0, 0, 1, -1};
// function
//--------------------------------------------
LL gcd(LL, LL);
bool isEven(LL);
void coutY();
void coutN();
int main() {
LL n, q;
cin >> n >> q;
vector<PLL> ab(n - 1);
REP(i, n - 1) cin >> ab[i].first >> ab[i].second;
vector<PLL> ope(q);
REP(i, q) cin >> ope[i].first >> ope[i].second;
REP(i, n) {
ab[i].first--;
ab[i].second--;
}
REP(i, q) ope[i].first--;
VLL counter(n);
REP(i, q) counter[ope[i].first] += ope[i].second;
SORT(ab);
REP(i, n - 1) { counter[ab[i].second] += counter[ab[i].first]; }
// REP(i,n-1)cout<<ab[i].first<<' '<<ab[i].second<<endl;
REP(i, n) cout << counter[i] << ' ';
}
LL gcd(LL a, LL b) {
if (a == 0 || b == 0)
return 0;
if (a < b)
swap(a, b);
if (a % b == 0)
return b;
else
gcd(b, a % b);
}
bool isEven(LL a) { return !((bool)(a % 2)); }
void coutY() {
cout << "Yes" << endl;
return;
}
void coutN() {
cout << "No" << endl;
return;
}
| replace | 54 | 55 | 54 | 55 | 0 | |
p02936 | C++ | Runtime Error | // #include<bits/stdc++.h>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please
// 有向気味でもなぜかよさそうと解説放送で聞いたけど
int N;
int C[200001];
int E[200001];
int next[200001];
int H[100001];
void dfs(int p, int c) {
C[p] = c + C[p];
for (int i = H[p]; i; i = next[i]) {
dfs(E[i], C[p]);
}
}
const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
if (ci - cn == cm) {
fread(cn, 1, cm, stdin);
ci = cn;
}
return *ci++;
}
inline int getint() {
int A = 0;
if (ci - cn + 16 > cm)
while ((ct = getcha()) >= '0')
A = A * 10 + ct - '0';
else
while ((ct = *ci++) >= '0')
A = A * 10 + ct - '0';
return A;
}
const int dm = 1 << 21;
char dn[dm], *di = dn;
inline void putint(int X) {
if (X == 0) {
*di++ = '0';
*di++ = ' ';
return;
}
int keta = 0;
char C[10];
while (X) {
*(C + keta) = '0' + X % 10;
X /= 10;
keta++;
}
for (int i = keta - 1; i >= 0; i--)
*di++ = (*(C + i));
*di++ = ' ';
}
int main() {
// cin.tie(0);
// ios::sync_with_stdio(false);
int N = getint(), Q = getint();
int k = 1;
rep(i, N - 1) {
int a = getint(), b = getint();
E[k] = b;
next[k] = H[a];
H[a] = k++;
}
rep(i, Q) {
int p = getint(), x = getint();
C[p] += x;
}
dfs(1, 0);
rep1(i, N) putint(C[i]);
fwrite(dn, 1, di - dn, stdout);
Would you please return 0;
} | // #include<bits/stdc++.h>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please
// 有向気味でもなぜかよさそうと解説放送で聞いたけど
int N;
int C[200001];
int E[200001];
int next[200001];
int H[200001];
void dfs(int p, int c) {
C[p] = c + C[p];
for (int i = H[p]; i; i = next[i]) {
dfs(E[i], C[p]);
}
}
const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
if (ci - cn == cm) {
fread(cn, 1, cm, stdin);
ci = cn;
}
return *ci++;
}
inline int getint() {
int A = 0;
if (ci - cn + 16 > cm)
while ((ct = getcha()) >= '0')
A = A * 10 + ct - '0';
else
while ((ct = *ci++) >= '0')
A = A * 10 + ct - '0';
return A;
}
const int dm = 1 << 21;
char dn[dm], *di = dn;
inline void putint(int X) {
if (X == 0) {
*di++ = '0';
*di++ = ' ';
return;
}
int keta = 0;
char C[10];
while (X) {
*(C + keta) = '0' + X % 10;
X /= 10;
keta++;
}
for (int i = keta - 1; i >= 0; i--)
*di++ = (*(C + i));
*di++ = ' ';
}
int main() {
// cin.tie(0);
// ios::sync_with_stdio(false);
int N = getint(), Q = getint();
int k = 1;
rep(i, N - 1) {
int a = getint(), b = getint();
E[k] = b;
next[k] = H[a];
H[a] = k++;
}
rep(i, Q) {
int p = getint(), x = getint();
C[p] += x;
}
dfs(1, 0);
rep1(i, N) putint(C[i]);
fwrite(dn, 1, di - dn, stdout);
Would you please return 0;
} | replace | 23 | 24 | 23 | 24 | 0 | |
p02936 | Python | Time Limit Exceeded | import sys
sys.setrecursionlimit(1000000)
def dfs(v, par):
for nv in tree[v]:
if nv == par:
continue
add[nv] += add[v]
dfs(nv, v)
n, q = map(int, input().split())
tree = [[] for i in range(n)]
for i in range(n - 1):
a, b = map(int, input().split())
a -= 1
b -= 1
tree[b].append(a)
tree[a].append(b)
add = [0] * n
for i in range(q):
p, x = map(int, input().split())
p -= 1
add[p] += x
dfs(0, -1)
print(*add)
| import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
def dfs(v, par):
for nv in tree[v]:
if nv == par:
continue
add[nv] += add[v]
dfs(nv, v)
n, q = map(int, input().split())
tree = [[] for i in range(n)]
for i in range(n - 1):
a, b = map(int, input().split())
a -= 1
b -= 1
tree[b].append(a)
tree[a].append(b)
add = [0] * n
for i in range(q):
p, x = map(int, input().split())
p -= 1
add[p] += x
dfs(0, -1)
print(*add)
| insert | 3 | 3 | 3 | 4 | TLE | |
p02936 | C++ | Runtime Error | #include <bits/stdc++.h>
#define sz(x) (int)((x).size())
#define F first
#define S second
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define all(x) x.begin(), x.end()
#define pqueue priority_queue
#define mset multiset
#define umap unordered_map
#define Speed() \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define forn(i, n) for (int i = 1; i <= n; ++i)
#define lr(i, l, r) \
for (int i = l; (l > r ? i >= r : i <= r); (l > r ? --i : ++i))
using namespace std;
template <class T> void umin(T &a, T b) { a = min(a, b); }
template <class T> void umax(T &a, T b) { a = max(a, b); }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int dx[] = {1, 0, -1, 0, -1, -1, 1, 1},
dy[] = {0, 1, 0, -1, -1, 1, -1, 1};
const int mod = 1e9 + 7;
const ll N = 1e5 + 5;
int n, q, ans[N], cnt[N];
vector<int> g[N];
void dfs(int x, int p) {
ans[x] += ans[p];
for (auto i : g[x]) {
if (i ^ p) {
dfs(i, x);
}
}
}
void solve() {
cin >> n >> q;
rep(i, n - 1) {
int u, v;
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
while (q--) {
int a, b;
cin >> a >> b;
cnt[a] += b;
}
for (int i = 1; i <= n; ++i)
ans[i] = cnt[i];
dfs(1, 0);
for (int i = 1; i <= n; ++i)
cout << ans[i] << ' ';
}
int main() {
Speed();
int T = 1;
// cin>>T;
while (T--)
solve();
return 0;
} | #include <bits/stdc++.h>
#define sz(x) (int)((x).size())
#define F first
#define S second
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define all(x) x.begin(), x.end()
#define pqueue priority_queue
#define mset multiset
#define umap unordered_map
#define Speed() \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define forn(i, n) for (int i = 1; i <= n; ++i)
#define lr(i, l, r) \
for (int i = l; (l > r ? i >= r : i <= r); (l > r ? --i : ++i))
using namespace std;
template <class T> void umin(T &a, T b) { a = min(a, b); }
template <class T> void umax(T &a, T b) { a = max(a, b); }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int dx[] = {1, 0, -1, 0, -1, -1, 1, 1},
dy[] = {0, 1, 0, -1, -1, 1, -1, 1};
const int mod = 1e9 + 7;
const ll N = 2e5 + 5;
int n, q, ans[N], cnt[N];
vector<int> g[N];
void dfs(int x, int p) {
ans[x] += ans[p];
for (auto i : g[x]) {
if (i ^ p) {
dfs(i, x);
}
}
}
void solve() {
cin >> n >> q;
rep(i, n - 1) {
int u, v;
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
while (q--) {
int a, b;
cin >> a >> b;
cnt[a] += b;
}
for (int i = 1; i <= n; ++i)
ans[i] = cnt[i];
dfs(1, 0);
for (int i = 1; i <= n; ++i)
cout << ans[i] << ' ';
}
int main() {
Speed();
int T = 1;
// cin>>T;
while (T--)
solve();
return 0;
} | replace | 32 | 33 | 32 | 33 | 0 | |
p02936 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y);
#define chmin(x, y) x = min(x, y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;
vector<int> to[200005];
vector<int> ans;
void dfs(int v, int p = -1) {
int d = ans[v];
for (int u : to[v]) {
if (u == p)
continue;
ans[u] += d;
dfs(u, v);
}
}
int main() {
int n, q;
cin >> n >> q;
rep(i, n) {
int a, b;
cin >> a >> b;
a--;
b--;
to[a].push_back(b);
to[b].push_back(a);
}
ans.resize(n);
rep(i, q) {
int p, x;
cin >> p >> x;
p--;
ans[p] += x;
}
dfs(0);
rep(i, n) 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>;
#define chmax(x, y) x = max(x, y);
#define chmin(x, y) x = min(x, y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;
vector<int> to[200005];
vector<int> ans;
void dfs(int v, int p = -1) {
int d = ans[v];
for (int u : to[v]) {
if (u == p)
continue;
ans[u] += d;
dfs(u, v);
}
}
int main() {
int n, q;
cin >> n >> q;
rep(i, n - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
to[a].push_back(b);
to[b].push_back(a);
}
ans.resize(n);
rep(i, q) {
int p, x;
cin >> p >> x;
p--;
ans[p] += x;
}
dfs(0);
rep(i, n) cout << ans[i] << endl;
return 0;
} | replace | 27 | 28 | 27 | 28 | 0 | |
p02936 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define check(v) \
rep(i, v.size()) cout << v[i] << " "; \
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
// オーバーフローに気をつけろよおおおおおお
// 確認忘れるなよおおおおおお
vector<ll> tree[200010];
vector<ll> ans;
void dfs(int v, int pair) {
for (int i = 0; i < tree[v].size(); i++) {
if (tree[v][i] == pair)
continue;
ans[tree[v][i]] += ans[v];
dfs(tree[v][i], v);
}
}
int main() {
int n, q;
cin >> n >> q;
rep(i, n - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
tree[a].push_back(b);
tree[b].push_back(a);
}
rep(i, q) {
int p, x;
cin >> p >> x;
p--;
ans[p] += x;
}
dfs(0, -1);
rep(i, n) { cout << ans[i] << endl; }
return 0;
} | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define check(v) \
rep(i, v.size()) cout << v[i] << " "; \
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
// オーバーフローに気をつけろよおおおおおお
// 確認忘れるなよおおおおおお
vector<ll> tree[200010];
vector<ll> ans;
void dfs(int v, int pair) {
for (int i = 0; i < tree[v].size(); i++) {
if (tree[v][i] == pair)
continue;
ans[tree[v][i]] += ans[v];
dfs(tree[v][i], v);
}
}
int main() {
int n, q;
cin >> n >> q;
rep(i, n - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
tree[a].push_back(b);
tree[b].push_back(a);
}
ans.resize(n);
rep(i, q) {
int p, x;
cin >> p >> x;
p--;
ans[p] += x;
}
dfs(0, -1);
rep(i, n) { cout << ans[i] << endl; }
return 0;
} | insert | 45 | 45 | 45 | 46 | -11 | |
p02936 | C++ | Runtime Error | #define C
#ifdef C
#include <stdio.h>
#define abs(a) ((a) < 0 ? -(a) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define isdigit(a) ((a) >= '0' && (a) <= '9' ? true : false)
#endif
#ifdef Cpp
#include <bits/stdc++.h>
using namespace std;
#endif
#define freopen(x) \
freopen(x ".in", "r", stdin); \
freopen(x ".out", "w", stdout)
#define repl(i, t) for (int i = fi[t]; i; i = ne[i])
#define rep(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define per(i, a, b) for (int i = (int)a; i >= (int)b; --i)
#define _r read()
#define readtype long long
typedef long long var;
const int INF = 0x3f3f3f3f;
const int N = 2e5;
int top, fi[N], ne[N], to[N];
int have[N], res[N];
readtype read();
void add(int u, int v);
void DFS(int t, int s = 0, int f = 0);
int main() {
int n = _r, q = _r;
rep(i, 2, n) add(_r, _r);
rep(i, 1, q) {
int u = _r, v = _r;
have[u] += v;
}
DFS(1);
rep(i, 1, n - 1) printf("%d ", res[i]);
printf("%d\n", res[n]);
return 0;
}
readtype read() {
readtype a = 0, c = getchar(), s = 0;
while (!isdigit(c))
s |= c == '-', c = getchar();
while (isdigit(c))
a = a * 10 + c - 48, c = getchar();
return s ? -a : a;
}
void add(int u, int v) {
ne[++top] = fi[u], fi[u] = top, to[top] = v;
ne[++top] = fi[v], fi[v] = top, to[top] = u;
}
void DFS(int t, int s, int f) {
res[t] = s + have[t];
repl(i, t) {
if (to[i] == f)
continue;
DFS(to[i], res[t], t);
}
}
| #define C
#ifdef C
#include <stdio.h>
#define abs(a) ((a) < 0 ? -(a) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define isdigit(a) ((a) >= '0' && (a) <= '9' ? true : false)
#endif
#ifdef Cpp
#include <bits/stdc++.h>
using namespace std;
#endif
#define freopen(x) \
freopen(x ".in", "r", stdin); \
freopen(x ".out", "w", stdout)
#define repl(i, t) for (int i = fi[t]; i; i = ne[i])
#define rep(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define per(i, a, b) for (int i = (int)a; i >= (int)b; --i)
#define _r read()
#define readtype long long
typedef long long var;
const int INF = 0x3f3f3f3f;
const int N = 1e6 + 1;
int top, fi[N], ne[N], to[N];
int have[N], res[N];
readtype read();
void add(int u, int v);
void DFS(int t, int s = 0, int f = 0);
int main() {
int n = _r, q = _r;
rep(i, 2, n) add(_r, _r);
rep(i, 1, q) {
int u = _r, v = _r;
have[u] += v;
}
DFS(1);
rep(i, 1, n - 1) printf("%d ", res[i]);
printf("%d\n", res[n]);
return 0;
}
readtype read() {
readtype a = 0, c = getchar(), s = 0;
while (!isdigit(c))
s |= c == '-', c = getchar();
while (isdigit(c))
a = a * 10 + c - 48, c = getchar();
return s ? -a : a;
}
void add(int u, int v) {
ne[++top] = fi[u], fi[u] = top, to[top] = v;
ne[++top] = fi[v], fi[v] = top, to[top] = u;
}
void DFS(int t, int s, int f) {
res[t] = s + have[t];
repl(i, t) {
if (to[i] == f)
continue;
DFS(to[i], res[t], t);
}
}
| replace | 26 | 27 | 26 | 27 | 0 | |
p02936 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
typedef struct _TREE {
vector<int> connect;
long long startCnt;
long long totalCnt;
} TREE;
TREE trees[100001];
void addCounters(int beforeTree, int thisTree, long long addCounter) {
trees[thisTree].totalCnt = trees[thisTree].startCnt + addCounter;
for (unsigned int i = 0; i < trees[thisTree].connect.size(); i++) {
int connectedTree = trees[thisTree].connect[i];
if (connectedTree == beforeTree)
continue;
addCounters(thisTree, connectedTree, trees[thisTree].totalCnt);
}
}
int main(void) {
int N, Q;
cin >> N >> Q;
// initialization
for (int i = 1; i <= N; i++) {
trees[i].connect.clear();
trees[i].startCnt = 0;
trees[i].totalCnt = 0;
}
// edge
for (int i = 1; i <= N - 1; i++) {
int a, b;
cin >> a >> b;
trees[a].connect.push_back(b);
trees[b].connect.push_back(a);
}
// counter
for (int i = 1; i <= Q; i++) {
int p, x;
cin >> p >> x;
trees[p].startCnt += x;
}
// calc
addCounters(0, 1, 0);
// answer
for (int i = 1; i < N; i++) {
cout << trees[i].totalCnt << " ";
}
cout << trees[N].totalCnt << endl;
return 0;
}
| #include <iostream>
#include <vector>
using namespace std;
typedef struct _TREE {
vector<int> connect;
long long startCnt;
long long totalCnt;
} TREE;
TREE trees[200001];
void addCounters(int beforeTree, int thisTree, long long addCounter) {
trees[thisTree].totalCnt = trees[thisTree].startCnt + addCounter;
for (unsigned int i = 0; i < trees[thisTree].connect.size(); i++) {
int connectedTree = trees[thisTree].connect[i];
if (connectedTree == beforeTree)
continue;
addCounters(thisTree, connectedTree, trees[thisTree].totalCnt);
}
}
int main(void) {
int N, Q;
cin >> N >> Q;
// initialization
for (int i = 1; i <= N; i++) {
trees[i].connect.clear();
trees[i].startCnt = 0;
trees[i].totalCnt = 0;
}
// edge
for (int i = 1; i <= N - 1; i++) {
int a, b;
cin >> a >> b;
trees[a].connect.push_back(b);
trees[b].connect.push_back(a);
}
// counter
for (int i = 1; i <= Q; i++) {
int p, x;
cin >> p >> x;
trees[p].startCnt += x;
}
// calc
addCounters(0, 1, 0);
// answer
for (int i = 1; i < N; i++) {
cout << trees[i].totalCnt << " ";
}
cout << trees[N].totalCnt << endl;
return 0;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p02936 | C++ | Runtime Error | #include <cstdio>
#include <stack>
#include <vector>
using namespace std;
using i64 = long long;
#define REP(i, stop) for (int i = 0, i##_len = stop; i < i##_len; ++i)
const int is = 1 << 17;
char ib[is], *ip = ib + is, it;
inline char getc() {
if (ip == ib + is) {
fread_unlocked(ib, 1, is, stdin);
ip = ib;
}
return *ip++;
}
inline int read() {
int r = 0;
if (ip + 16 > ib + is)
while ((it = getc()) & 16)
r = r * 10 + it - '0';
else
while ((it = *ip++) & 16)
r = r * 10 + it - '0';
return r;
}
const int os = 1 << 17;
char ob[os], *op = ob, ot;
inline void putc(const char c) {
*op++ = c;
if (op == ob + os) {
fwrite_unlocked(ob, 1, os, stdout);
op = ob;
}
}
// x shoud be greater than or equal to zero
inline void write(int x) {
char d[6];
int i = 0;
while (true) {
d[i] = x % 10 + 48;
x /= 10;
++i;
if (x <= 0)
break;
}
while (i--) {
putc(d[i]);
}
putc(' ');
}
using P = pair<i64, i64>;
signed main() {
i64 N = read(), Q = read();
vector<vector<i64>> G(N);
REP(_, N - 1) {
i64 a = read(), b = read();
a -= 1;
b -= 1;
G[a].push_back(b);
G[b].push_back(a);
}
vector<i64> cnt(N);
REP(_, Q) {
i64 p = read(), x = read();
p -= 1;
cnt[p] += x;
}
vector<i64> ans(N);
vector<bool> used(N, false);
stack<P> st;
st.push({0, 0});
while (st.size()) {
P a = st.top();
st.pop();
i64 v = cnt[a.first] + a.second;
ans[a.first] = v;
used[a.first] = true;
for (i64 b : G[a.first]) {
if (!used[b]) {
st.push({b, v});
}
}
}
REP(i, N) { write(ans[i]); }
fwrite_unlocked(ob, 1, op - ob, stdout);
}
| #include <cstdio>
#include <stack>
#include <vector>
using namespace std;
using i64 = long long;
#define REP(i, stop) for (int i = 0, i##_len = stop; i < i##_len; ++i)
const int is = 1 << 17;
char ib[is], *ip = ib + is, it;
inline char getc() {
if (ip == ib + is) {
fread_unlocked(ib, 1, is, stdin);
ip = ib;
}
return *ip++;
}
inline int read() {
int r = 0;
if (ip + 16 > ib + is)
while ((it = getc()) & 16)
r = r * 10 + it - '0';
else
while ((it = *ip++) & 16)
r = r * 10 + it - '0';
return r;
}
const int os = 1 << 17;
char ob[os], *op = ob, ot;
inline void putc(const char c) {
*op++ = c;
if (op == ob + os) {
fwrite_unlocked(ob, 1, os, stdout);
op = ob;
}
}
// x shoud be greater than or equal to zero
inline void write(int x) {
char d[6];
int i = 0;
while (true) {
d[i] = x % 10 + 48;
x /= 10;
++i;
if (x <= 0)
break;
}
while (i--) {
putc(d[i]);
}
putc(' ');
}
using P = pair<i64, i64>;
signed main() {
i64 N = read(), Q = read();
vector<vector<i64>> G(N);
REP(_, N - 1) {
i64 a = read(), b = read();
a -= 1;
b -= 1;
G[a].push_back(b);
G[b].push_back(a);
}
vector<i64> cnt(N);
REP(_, Q) {
i64 p = read(), x = read();
p -= 1;
cnt[p] += x;
}
vector<i64> ans(N);
vector<bool> used(N, false);
stack<P> st;
st.push({0, 0});
while (st.size()) {
P a = st.top();
st.pop();
i64 v = cnt[a.first] + a.second;
ans[a.first] = v;
used[a.first] = true;
for (i64 b : G[a.first]) {
if (!used[b]) {
st.push({b, v});
}
}
}
REP(i, N) {
printf("%d ", ans[i]);
// write(ans[i]);
}
// fwrite_unlocked(ob, 1, op - ob, stdout);
}
| replace | 88 | 90 | 88 | 93 | 0 | |
p02936 | C++ | Runtime Error | /**
* author: malviyanshiv
* created: 18 August 2019 17:46:30
**/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = a - 1; i >= b; i--)
#define FORE(a) for (auto ele : a)
#define ALL(a) begin(a), end(a)
#define RPB(i, begin, end) \
for (__typeof(end) i = (begin) - ((begin) > (end)); \
i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define PB push_back
#define MP make_pair
#define MOD 1000000007
#define INF 0x7fffffff
#define LINF 2000000000000000007
#define F first
#define S second
#define TC \
int t; \
cin >> t; \
while (t--)
#define SET(a, b) memset(a, b, sizeof(a))
#define TRACE
#ifdef TRACE
#define trace1(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) \
cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z) \
cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl;
#define trace4(a, b, c, d) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \
<< #f << ": " << f << endl;
#else
#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)
#endif
typedef long long ll;
typedef pair<int, int> PII;
void optimizeIO() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
#define MAX 100005
vector<int> adj[MAX];
vector<int> value(MAX, 0);
vector<int> final(MAX, 0);
vector<bool> vis(MAX, false);
void dfs(int n, int val) {
final[n] = val;
vis[n] = true;
for (int nei : adj[n]) {
if (!vis[nei]) {
dfs(nei, val + value[nei]);
}
}
}
int main() {
optimizeIO();
int n, q, a, b;
cin >> n >> q;
REP(i, 0, n - 1) {
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
while (q--) {
cin >> a >> b;
value[a] += b;
}
dfs(1, value[1]);
final[1] = value[1];
for (int i = 1; i <= n; i++)
cout << final[i] << " ";
cout << endl;
return 0;
} | /**
* author: malviyanshiv
* created: 18 August 2019 17:46:30
**/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = a - 1; i >= b; i--)
#define FORE(a) for (auto ele : a)
#define ALL(a) begin(a), end(a)
#define RPB(i, begin, end) \
for (__typeof(end) i = (begin) - ((begin) > (end)); \
i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define PB push_back
#define MP make_pair
#define MOD 1000000007
#define INF 0x7fffffff
#define LINF 2000000000000000007
#define F first
#define S second
#define TC \
int t; \
cin >> t; \
while (t--)
#define SET(a, b) memset(a, b, sizeof(a))
#define TRACE
#ifdef TRACE
#define trace1(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) \
cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z) \
cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl;
#define trace4(a, b, c, d) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \
<< #f << ": " << f << endl;
#else
#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)
#endif
typedef long long ll;
typedef pair<int, int> PII;
void optimizeIO() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
#define MAX 200005
vector<int> adj[MAX];
vector<int> value(MAX, 0);
vector<int> final(MAX, 0);
vector<bool> vis(MAX, false);
void dfs(int n, int val) {
final[n] = val;
vis[n] = true;
for (int nei : adj[n]) {
if (!vis[nei]) {
dfs(nei, val + value[nei]);
}
}
}
int main() {
optimizeIO();
int n, q, a, b;
cin >> n >> q;
REP(i, 0, n - 1) {
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
while (q--) {
cin >> a >> b;
value[a] += b;
}
dfs(1, value[1]);
final[1] = value[1];
for (int i = 1; i <= n; i++)
cout << final[i] << " ";
cout << endl;
return 0;
} | replace | 69 | 70 | 69 | 70 | 0 | |
p02936 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using Int = long long int;
template <typename T> void swap(T *t1, T *t2) {
T *tmp = t1;
t1 = t2;
t2 = tmp;
}
vector<Int> m[100002];
Int stts[100002];
Int arr[100002];
void dfs(Int u, Int val) {
stts[u] = 1;
arr[u] += val;
for (Int i = 0; i < m[u].size(); i++) {
if (stts[m[u][i]] == 0) {
dfs(m[u][i], arr[u]);
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
Int n, q, a, b;
cin >> n >> q;
Int p, x;
// init
for (Int i = 0; i < n; i++) {
arr[i] = 0;
stts[i] = 0;
}
for (Int i = 0; i < n - 1; i++) {
cin >> a >> b;
m[a - 1].push_back(b - 1);
m[b - 1].push_back(a - 1);
}
for (Int i = 0; i < q; i++) {
cin >> p >> x;
arr[p - 1] += x;
}
dfs(0, 0);
for (Int i = 0; i < n; i++) {
cout << arr[i] << " ";
}
cout << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using Int = long long int;
template <typename T> void swap(T *t1, T *t2) {
T *tmp = t1;
t1 = t2;
t2 = tmp;
}
vector<Int> m[300002];
Int stts[300002];
Int arr[300002];
void dfs(Int u, Int val) {
stts[u] = 1;
arr[u] += val;
for (Int i = 0; i < m[u].size(); i++) {
if (stts[m[u][i]] == 0) {
dfs(m[u][i], arr[u]);
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
Int n, q, a, b;
cin >> n >> q;
Int p, x;
// init
for (Int i = 0; i < n; i++) {
arr[i] = 0;
stts[i] = 0;
}
for (Int i = 0; i < n - 1; i++) {
cin >> a >> b;
m[a - 1].push_back(b - 1);
m[b - 1].push_back(a - 1);
}
for (Int i = 0; i < q; i++) {
cin >> p >> x;
arr[p - 1] += x;
}
dfs(0, 0);
for (Int i = 0; i < n; i++) {
cout << arr[i] << " ";
}
cout << endl;
return 0;
} | replace | 9 | 12 | 9 | 12 | 0 | |
p02936 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<vector<int>> to(20005);
vector<int> ans;
void dfs(int c, int p = -1) {
for (int u : to.at(c)) {
if (u == p) {
continue;
}
ans.at(u) += ans.at(c);
dfs(u, c);
}
}
int main() {
int n, q;
cin >> n >> q;
// v.resize(N);
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
to.at(a).push_back(b);
to.at(b).push_back(a);
}
ans.resize(n);
for (int i = 0; i < q; i++) {
int p, x;
cin >> p >> x;
p--;
ans.at(p) += x;
}
dfs(0);
for (int i = 0; i < n; i++) {
cout << ans.at(i) << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<vector<int>> to(200005);
vector<int> ans;
void dfs(int c, int p = -1) {
for (int u : to.at(c)) {
if (u == p) {
continue;
}
ans.at(u) += ans.at(c);
dfs(u, c);
}
}
int main() {
int n, q;
cin >> n >> q;
// v.resize(N);
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
to.at(a).push_back(b);
to.at(b).push_back(a);
}
ans.resize(n);
for (int i = 0; i < q; i++) {
int p, x;
cin >> p >> x;
p--;
ans.at(p) += x;
}
dfs(0);
for (int i = 0; i < n; i++) {
cout << ans.at(i) << endl;
}
return 0;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p02936 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MAXDATA 100
vector<vector<int>> to(MAXDATA);
vector<bool> seen(MAXDATA, false);
vector<int> ans(MAXDATA, 0);
void dfs(const vector<vector<int>> &G, int v) {
seen[v] = true;
for (auto next_v : G[v]) {
if (seen[next_v])
continue;
ans[next_v] += ans[v];
dfs(G, next_v);
}
}
int main() {
int n, q;
cin >> n >> q;
rep(i, n - 1) {
int a, b;
cin >> a >> b;
to[a - 1].push_back(b - 1);
to[b - 1].push_back(a - 1);
}
rep(i, q) {
int p, x;
cin >> p >> x;
ans[p - 1] += x;
}
dfs(to, 0);
rep(i, n) cout << ans[i] << " ";
cout << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MAXDATA 200100
vector<vector<int>> to(MAXDATA);
vector<bool> seen(MAXDATA, false);
vector<int> ans(MAXDATA, 0);
void dfs(const vector<vector<int>> &G, int v) {
seen[v] = true;
for (auto next_v : G[v]) {
if (seen[next_v])
continue;
ans[next_v] += ans[v];
dfs(G, next_v);
}
}
int main() {
int n, q;
cin >> n >> q;
rep(i, n - 1) {
int a, b;
cin >> a >> b;
to[a - 1].push_back(b - 1);
to[b - 1].push_back(a - 1);
}
rep(i, q) {
int p, x;
cin >> p >> x;
ans[p - 1] += x;
}
dfs(to, 0);
rep(i, n) cout << ans[i] << " ";
cout << endl;
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02936 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define mp make_pair
#define fi first
#define se second
typedef pair<int, int> pint;
#define All(s) s.begin(), s.end()
#define rAll(s) s.rbegin(), s.rend()
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define sz(x) int(x.size())
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
vi to[20005];
vi ans;
void dfs(int v, int p = -1) {
for (int u : to[v]) {
if (u == p)
continue;
ans[u] += ans[v];
dfs(u, v);
}
}
int main() {
int n, q;
cin >> n >> q;
rep(i, n - 1) {
int a, b;
cin >> a >> b;
--a;
--b;
to[a].pb(b);
to[b].pb(a);
}
ans.resize(n);
rep(i, q) {
int p, x;
cin >> p >> x;
--p;
ans[p] += x;
}
dfs(0);
rep(i, n) { cout << ans[i] << endl; }
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define mp make_pair
#define fi first
#define se second
typedef pair<int, int> pint;
#define All(s) s.begin(), s.end()
#define rAll(s) s.rbegin(), s.rend()
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define sz(x) int(x.size())
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
vi to[200005];
vi ans;
void dfs(int v, int p = -1) {
for (int u : to[v]) {
if (u == p)
continue;
ans[u] += ans[v];
dfs(u, v);
}
}
int main() {
int n, q;
cin >> n >> q;
rep(i, n - 1) {
int a, b;
cin >> a >> b;
--a;
--b;
to[a].pb(b);
to[b].pb(a);
}
ans.resize(n);
rep(i, q) {
int p, x;
cin >> p >> x;
--p;
ans[p] += x;
}
dfs(0);
rep(i, n) { cout << ans[i] << endl; }
return 0;
}
| replace | 28 | 29 | 28 | 29 | 0 | |
p02936 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, j, k) for (int i = (int)j; i <= (int)k; i++)
#define per(i, j, k) for (int i = (int)j; i >= (int)k; i--)
#define F(i, k) for (int i = (int)0; i < (int)k; i++)
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long long ll;
const int maxn = 1e5 + 5;
using namespace std;
ll m, n, k;
vector<int> E[maxn];
ll mk[maxn], sc[maxn];
int vis[maxn];
void dfs(int x, ll now) {
vis[x] = 1;
sc[x] = mk[x] + now;
for (auto t : E[x]) {
if (vis[t])
continue;
dfs(t, now + mk[x]);
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n >> m;
rep(i, 1, n - 1) {
int x, y;
cin >> x >> y;
E[x].push_back(y);
E[y].push_back(x);
}
rep(i, 1, m) {
int x, y;
cin >> x >> y;
mk[x] += y;
}
dfs(1, 0);
rep(i, 1, n) cout << sc[i] << ' ';
double ans = 0;
cin >> n;
}
/*
*/ | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, j, k) for (int i = (int)j; i <= (int)k; i++)
#define per(i, j, k) for (int i = (int)j; i >= (int)k; i--)
#define F(i, k) for (int i = (int)0; i < (int)k; i++)
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long long ll;
const int maxn = 2e5 + 5;
using namespace std;
ll m, n, k;
vector<int> E[maxn];
ll mk[maxn], sc[maxn];
int vis[maxn];
void dfs(int x, ll now) {
vis[x] = 1;
sc[x] = mk[x] + now;
for (auto t : E[x]) {
if (vis[t])
continue;
dfs(t, now + mk[x]);
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n >> m;
rep(i, 1, n - 1) {
int x, y;
cin >> x >> y;
E[x].push_back(y);
E[y].push_back(x);
}
rep(i, 1, m) {
int x, y;
cin >> x >> y;
mk[x] += y;
}
dfs(1, 0);
rep(i, 1, n) cout << sc[i] << ' ';
double ans = 0;
cin >> n;
}
/*
*/ | replace | 14 | 15 | 14 | 15 | 0 | |
p02936 | C++ | Runtime Error | /* ****devACE**** */
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define endl '\n'
#define pii pair<ll int, ll int>
#define vi vector<ll int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define sz(x) (ll int)x.size()
#define hell 1000000007
#define rep(i, a, b) for (ll int i = a; i < b; i++)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define mp make_pair
using namespace std;
#define N 100005
vector<int> adj[N];
int dp[N];
void dfs(int node, int par) {
dp[node] += dp[par];
for (auto i : adj[node])
if (i != par) {
dfs(i, node);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int TESTS = 1;
// cin>>TESTS;
while (TESTS--) {
int n, m, i, j, k;
cin >> n >> m;
for (i = 0; i < n - 1; i++) {
int x, y;
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
while (m--) {
int x, w;
cin >> x >> w;
dp[x] += w;
}
dfs(1, 0);
for (i = 1; i <= n; i++)
cout << dp[i] << " ";
}
return 0;
} | /* ****devACE**** */
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define endl '\n'
#define pii pair<ll int, ll int>
#define vi vector<ll int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define sz(x) (ll int)x.size()
#define hell 1000000007
#define rep(i, a, b) for (ll int i = a; i < b; i++)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define mp make_pair
using namespace std;
#define N 200005
vector<int> adj[N];
int dp[N];
void dfs(int node, int par) {
dp[node] += dp[par];
for (auto i : adj[node])
if (i != par) {
dfs(i, node);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int TESTS = 1;
// cin>>TESTS;
while (TESTS--) {
int n, m, i, j, k;
cin >> n >> m;
for (i = 0; i < n - 1; i++) {
int x, y;
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
while (m--) {
int x, w;
cin >> x >> w;
dp[x] += w;
}
dfs(1, 0);
for (i = 1; i <= n; i++)
cout << dp[i] << " ";
}
return 0;
} | replace | 20 | 21 | 20 | 21 | 0 | |
p02936 | C++ | Runtime Error | #include <bits/stdc++.h>
#define PI acos(-1)
#define eq(x, y) (fabs((x) - (y)) < eps)
#define debug(x) cerr << x << endl;
#define endl "\n"
#define pb push_back
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 1e9 + 7;
const int nmax = 1e5 + 10;
const int eps = 1e-8;
vector<int> adj[nmax];
int sum[nmax];
bool vis[nmax];
void dfs(int now, int from) {
if (vis[now])
return;
vis[now] = true;
sum[now] += sum[from];
for (auto to : adj[now])
dfs(to, now);
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;
// cout.tie(NULL);
int n, q;
cin >> n >> q;
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
while (q--) {
int v, x;
cin >> v >> x;
sum[v] += x;
}
dfs(1, 0);
for (int i = 1; i <= n; i++)
cout << sum[i] << " ";
cout << endl;
return 0;
}
| #include <bits/stdc++.h>
#define PI acos(-1)
#define eq(x, y) (fabs((x) - (y)) < eps)
#define debug(x) cerr << x << endl;
#define endl "\n"
#define pb push_back
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 1e9 + 7;
const int nmax = 1e5 + 10;
const int eps = 1e-8;
vector<int> adj[2 * nmax];
int sum[2 * nmax];
bool vis[2 * nmax];
void dfs(int now, int from) {
if (vis[now])
return;
vis[now] = true;
sum[now] += sum[from];
for (auto to : adj[now])
dfs(to, now);
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;
// cout.tie(NULL);
int n, q;
cin >> n >> q;
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
while (q--) {
int v, x;
cin >> v >> x;
sum[v] += x;
}
dfs(1, 0);
for (int i = 1; i <= n; i++)
cout << sum[i] << " ";
cout << endl;
return 0;
}
| replace | 16 | 19 | 16 | 19 | 0 | |
p02936 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
vector<vector<int>> T(100000);
vector<int> Count(100000, 0);
void solve(int a) {
for (int i : T[a]) {
Count[i] += Count[a];
solve(i);
}
return;
}
int main() {
int N, Q, a, b, p, x;
cin >> N >> Q;
for (int i = 0; i < N - 1; i++) {
cin >> a >> b;
a--;
b--;
T[a].push_back(b);
}
for (int i = 0; i < Q; i++) {
cin >> p >> x;
p--;
Count[p] += x;
}
solve(0);
for (int i = 0; i < N; i++) {
cout << Count[i] << " ";
}
}
| #include <bits/stdc++.h>
using namespace std;
vector<vector<int>> T(200000);
vector<int> Count(200000, 0);
void solve(int a) {
for (int i : T[a]) {
Count[i] += Count[a];
solve(i);
}
return;
}
int main() {
int N, Q, a, b, p, x;
cin >> N >> Q;
for (int i = 0; i < N - 1; i++) {
cin >> a >> b;
a--;
b--;
T[a].push_back(b);
}
for (int i = 0; i < Q; i++) {
cin >> p >> x;
p--;
Count[p] += x;
}
solve(0);
for (int i = 0; i < N; i++) {
cout << Count[i] << " ";
}
}
| replace | 3 | 5 | 3 | 5 | 0 | |
p02936 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long int;
const int MAX_N = 1e5 + 10;
vector<int> cost(MAX_N, 0);
vector<int> ans(MAX_N, -1);
vector<vector<int>> edge(MAX_N, vector<int>{});
int dfs(int frm, int n) {
if (ans[n] != -1) {
return 0;
}
if (frm == -1) {
ans[n] = cost[n];
} else {
ans[n] = ans[frm] + cost[n];
}
for (auto &v : edge[n]) {
dfs(n, v);
}
return 0;
}
int main() {
int n, q;
cin >> n >> q;
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
edge[a].push_back(b);
edge[b].push_back(a);
}
for (int i = 0; i < q; i++) {
int p, x;
cin >> p >> x;
p--;
cost[p] += x;
}
dfs(-1, 0);
for (int i = 0; i < n; i++) {
cout << ans[i] << endl;
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long int;
const int MAX_N = 3 * 1e5;
vector<int> cost(MAX_N, 0);
vector<int> ans(MAX_N, -1);
vector<vector<int>> edge(MAX_N, vector<int>{});
int dfs(int frm, int n) {
if (ans[n] != -1) {
return 0;
}
if (frm == -1) {
ans[n] = cost[n];
} else {
ans[n] = ans[frm] + cost[n];
}
for (auto &v : edge[n]) {
dfs(n, v);
}
return 0;
}
int main() {
int n, q;
cin >> n >> q;
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
edge[a].push_back(b);
edge[b].push_back(a);
}
for (int i = 0; i < q; i++) {
int p, x;
cin >> p >> x;
p--;
cost[p] += x;
}
dfs(-1, 0);
for (int i = 0; i < n; i++) {
cout << ans[i] << endl;
}
return 0;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02936 | C++ | Runtime Error | #include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
vector<int> ki[20005];
vector<int> ans;
void dfs(int u, int p = -1) {
// 範囲for
for (int v : ki[u]) {
if (v == p)
continue;
ans[v] += ans[u];
dfs(v, u);
}
}
int main() {
int n, q;
cin >> n >> q;
rep(i, n - 1) {
int a, b;
cin >> a >> b;
--a; // 0ori
--b;
ki[a].push_back(b);
ki[b].push_back(a);
}
ans.resize(n);
rep(i, q) {
int p, x;
cin >> p >> x;
--p;
ans[p] += x; // 0ori
}
dfs(0);
rep(i, n) { cout << ans[i] << endl; }
}
| #include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
vector<int> ki[200005];
vector<int> ans;
void dfs(int u, int p = -1) {
// 範囲for
for (int v : ki[u]) {
if (v == p)
continue;
ans[v] += ans[u];
dfs(v, u);
}
}
int main() {
int n, q;
cin >> n >> q;
rep(i, n - 1) {
int a, b;
cin >> a >> b;
--a; // 0ori
--b;
ki[a].push_back(b);
ki[b].push_back(a);
}
ans.resize(n);
rep(i, q) {
int p, x;
cin >> p >> x;
--p;
ans[p] += x; // 0ori
}
dfs(0);
rep(i, n) { cout << ans[i] << endl; }
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p02936 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long int
#define hell 1000000007
#define vi vector<ll>
#define pb push_back
#define pii pair<ll, ll>
#define vii vector<pii>
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define sep(i, a, b) for (ll i = a - 1; i >= b; i--)
#define inf (ll)(1e16)
using namespace std;
vi adj[100005];
vector<bool> visited(100005, false);
vi a(100005, 0);
void dfs(ll s, ll pv) {
visited[s] = true;
a[s] += pv;
for (auto ch : adj[s]) {
if (!visited[ch])
dfs(ch, a[s]);
}
}
void solve() {
ll n, u, v, q;
cin >> n >> q;
rep(i, 1, n) {
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
rep(i, 0, q) {
cin >> u >> v;
a[u] += v;
}
dfs(1, 0);
rep(i, 1, n + 1) cout << a[i] << " ";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t = 1;
// cin>>t;
while (t--)
solve();
return 0;
}
| #include <bits/stdc++.h>
#define ll long long int
#define hell 1000000007
#define vi vector<ll>
#define pb push_back
#define pii pair<ll, ll>
#define vii vector<pii>
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define sep(i, a, b) for (ll i = a - 1; i >= b; i--)
#define inf (ll)(1e16)
using namespace std;
vi adj[300005];
vector<bool> visited(300005, false);
vi a(300005, 0);
void dfs(ll s, ll pv) {
visited[s] = true;
a[s] += pv;
for (auto ch : adj[s]) {
if (!visited[ch])
dfs(ch, a[s]);
}
}
void solve() {
ll n, u, v, q;
cin >> n >> q;
rep(i, 1, n) {
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
rep(i, 0, q) {
cin >> u >> v;
a[u] += v;
}
dfs(1, 0);
rep(i, 1, n + 1) cout << a[i] << " ";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t = 1;
// cin>>t;
while (t--)
solve();
return 0;
}
| replace | 14 | 17 | 14 | 17 | 0 | |
p02936 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> adjl(200000);
vector<int> res(20000, 0);
void dfs(int t, int prev, int dsum) {
dsum += res[t];
res[t] = dsum;
for (int i = 0; i < adjl[t].size(); i++)
if (adjl[t][i] != prev)
dfs(adjl[t][i], t, dsum);
}
int main() {
int n, q;
cin >> n >> q;
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
adjl[a - 1].push_back(b - 1);
adjl[b - 1].push_back(a - 1);
}
for (int i = 0; i < q; i++) {
int a, b;
cin >> a >> b;
res[a - 1] += b;
}
dfs(0, -1, 0);
for (int i = 0; i < n; i++)
cout << res[i] << " ";
} | #include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> adjl(200000);
vector<int> res(200000, 0);
void dfs(int t, int prev, int dsum) {
dsum += res[t];
res[t] = dsum;
for (int i = 0; i < adjl[t].size(); i++)
if (adjl[t][i] != prev)
dfs(adjl[t][i], t, dsum);
}
int main() {
int n, q;
cin >> n >> q;
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
adjl[a - 1].push_back(b - 1);
adjl[b - 1].push_back(a - 1);
}
for (int i = 0; i < q; i++) {
int a, b;
cin >> a >> b;
res[a - 1] += b;
}
dfs(0, -1, 0);
for (int i = 0; i < n; i++)
cout << res[i] << " ";
} | replace | 6 | 7 | 6 | 7 | 0 | |
p02936 | C++ | Runtime Error | // aarsh01rsh@gmail.com
// Aarsh Sharma
#include <bits/stdc++.h>
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(char ch) {
string s(1, ch);
return '\'' + s + '\'';
}
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A> string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define f(i, x, n) for (int i = x; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define fast_io() \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
typedef long long int ll;
#define int ll
typedef pair<ll, ll> pll;
typedef vector<vector<ll>> matrix;
typedef vector<ll> vll;
const ll mod = 1e9 + 7;
const ll inf = LLONG_MAX;
const ll N = 1e5 + 10;
vll adj[N], counter(N);
int bfs(int s) {
queue<int> q;
vector<bool> used(N);
vector<int> d(N), p(N);
q.push(s);
used[s] = true;
p[s] = -1;
while (!q.empty()) {
int v = q.front();
q.pop();
for (int u : adj[v]) {
if (!used[u]) {
counter[u] += counter[v];
used[u] = true;
q.push(u);
d[u] = d[v] + 1;
p[u] = v;
}
}
}
}
int32_t main() {
fast_io();
int n, q;
cin >> n >> q;
f(i, 0, n - 1) {
int u, v;
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
while (q--) {
int p, x;
cin >> p >> x;
counter[p] += x;
}
bfs(1);
f(i, 1, n + 1) { cout << counter[i] << " "; }
return 0;
} | // aarsh01rsh@gmail.com
// Aarsh Sharma
#include <bits/stdc++.h>
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(char ch) {
string s(1, ch);
return '\'' + s + '\'';
}
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A> string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define f(i, x, n) for (int i = x; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define fast_io() \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
typedef long long int ll;
#define int ll
typedef pair<ll, ll> pll;
typedef vector<vector<ll>> matrix;
typedef vector<ll> vll;
const ll mod = 1e9 + 7;
const ll inf = LLONG_MAX;
const ll N = 2e5 + 10;
vll adj[N], counter(N);
int bfs(int s) {
queue<int> q;
vector<bool> used(N);
vector<int> d(N), p(N);
q.push(s);
used[s] = true;
p[s] = -1;
while (!q.empty()) {
int v = q.front();
q.pop();
for (int u : adj[v]) {
if (!used[u]) {
counter[u] += counter[v];
used[u] = true;
q.push(u);
d[u] = d[v] + 1;
p[u] = v;
}
}
}
}
int32_t main() {
fast_io();
int n, q;
cin >> n >> q;
f(i, 0, n - 1) {
int u, v;
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
while (q--) {
int p, x;
cin >> p >> x;
counter[p] += x;
}
bfs(1);
f(i, 1, n + 1) { cout << counter[i] << " "; }
return 0;
} | replace | 61 | 62 | 61 | 62 | 0 | |
p02936 | C++ | Runtime Error | //
// main.cpp
// Test
//
// Created by momoc on 2019/8/18.
// Copyright © 2019年 momoc. All rights reserved.
//
#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>
typedef long long ll;
using namespace std;
const int N = 10 * 5 + 1;
int a[N] = {0};
vector<int> dege[N];
void bfs() {
queue<int> q;
q.push(1);
while (!q.empty()) {
int v = q.front();
q.pop();
int add = a[v];
// printf("%d\n",add);
for (int i = 0; i < dege[v].size(); i++) {
a[dege[v][i]] += add;
q.push(dege[v][i]);
}
}
}
int main(int argc, const char *argv[]) {
// insert code here...
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n - 1; i++) {
int p, q;
scanf("%d %d", &p, &q);
dege[p].push_back(q);
// cout<<sum<<endl;
}
for (int i = 0; i < m; i++) {
int p, q;
scanf("%d %d", &p, &q);
a[p] += q;
}
bfs();
for (int i = 1; i <= n; i++) {
printf("%d ", a[i]);
}
return 0;
}
| //
// main.cpp
// Test
//
// Created by momoc on 2019/8/18.
// Copyright © 2019年 momoc. All rights reserved.
//
#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>
typedef long long ll;
using namespace std;
const int N = 200000 + 1;
int a[N] = {0};
vector<int> dege[N];
void bfs() {
queue<int> q;
q.push(1);
while (!q.empty()) {
int v = q.front();
q.pop();
int add = a[v];
// printf("%d\n",add);
for (int i = 0; i < dege[v].size(); i++) {
a[dege[v][i]] += add;
q.push(dege[v][i]);
}
}
}
int main(int argc, const char *argv[]) {
// insert code here...
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n - 1; i++) {
int p, q;
scanf("%d %d", &p, &q);
dege[p].push_back(q);
// cout<<sum<<endl;
}
for (int i = 0; i < m; i++) {
int p, q;
scanf("%d %d", &p, &q);
a[p] += q;
}
bfs();
for (int i = 1; i <= n; i++) {
printf("%d ", a[i]);
}
return 0;
}
| replace | 14 | 15 | 14 | 15 | 0 | |
p02936 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// counterの値を親から子に伝搬させる
void dfs(int vertex, int parent, vector<vector<int>> &Tree,
vector<int> &counter) {
// 親のカウンターの値を足し合わせる
counter[vertex] += counter[parent];
// 子に伝播させる
for (const int &nxtv : Tree[vertex]) {
if (nxtv == parent)
continue;
dfs(nxtv, vertex, Tree, counter);
}
}
// 方針:親から子にカウンターの値を伝播させていくことで実現
int main(void) {
// 入力
int N, Q;
cin >> N >> Q;
// 木
vector<vector<int>> Tree(N);
// 頂点のカウンター
vector<int> counter(N + 1, 0);
// 木の構築
for (int i = 0; i < N - 1; ++i) {
int a, b;
cin >> a >> b;
Tree[a].push_back(b);
Tree[b].push_back(a);
}
// カウンターの加算
for (int j = 0; j < Q; ++j) {
int p, x;
cin >> p >> x;
counter[p] += x;
}
// カウンターの伝搬
dfs(1, 0, Tree, counter);
// 出力
for (int i = 1; i <= N; ++i) {
cout << counter[i] << " ";
}
cout << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
// counterの値を親から子に伝搬させる
void dfs(int vertex, int parent, vector<vector<int>> &Tree,
vector<int> &counter) {
// 親のカウンターの値を足し合わせる
counter[vertex] += counter[parent];
// 子に伝播させる
for (const int &nxtv : Tree[vertex]) {
if (nxtv == parent)
continue;
dfs(nxtv, vertex, Tree, counter);
}
}
// 方針:親から子にカウンターの値を伝播させていくことで実現
int main(void) {
// 入力
int N, Q;
cin >> N >> Q;
// 木
vector<vector<int>> Tree(N + 1);
// 頂点のカウンター
vector<int> counter(N + 1, 0);
// 木の構築
for (int i = 0; i < N - 1; ++i) {
int a, b;
cin >> a >> b;
Tree[a].push_back(b);
Tree[b].push_back(a);
}
// カウンターの加算
for (int j = 0; j < Q; ++j) {
int p, x;
cin >> p >> x;
counter[p] += x;
}
// カウンターの伝搬
dfs(1, 0, Tree, counter);
// 出力
for (int i = 1; i <= N; ++i) {
cout << counter[i] << " ";
}
cout << endl;
return 0;
}
| replace | 24 | 25 | 24 | 25 | -11 | |
p02936 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
void seq(vector<vector<ll>> next, vector<ll> &cnt, ll from, ll ff) {
for (ll i = 0; i < next.at(from).size(); i++) {
if (from != 0 && next.at(from).at(i) - 1 == ff)
continue;
cnt.at(next.at(from).at(i) - 1) += cnt.at(from);
seq(next, cnt, next.at(from).at(i) - 1, from);
}
return;
}
int main() {
ll n, q, a, b;
cin >> n >> q;
vector<vector<ll>> next(n, vector<ll>(0));
for (ll i = 0; i < n - 1; i++) {
cin >> a >> b;
next.at(a - 1).push_back(b);
next.at(b - 1).push_back(a);
}
vector<ll> p(q), x(q), cnt(n, 0);
for (int i = 0; i < q; i++) {
cin >> p.at(i) >> x.at(i);
cnt.at(p.at(i) - 1) += x.at(i);
}
seq(next, cnt, 0, 0);
for (ll i = 0; i < n - 1; i++)
cout << cnt.at(i) << " ";
cout << cnt.at(n - 1) << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
void seq(vector<vector<ll>> &next, vector<ll> &cnt, ll from, ll ff) {
for (ll i = 0; i < next.at(from).size(); i++) {
if (from != 0 && next.at(from).at(i) - 1 == ff)
continue;
cnt.at(next.at(from).at(i) - 1) += cnt.at(from);
seq(next, cnt, next.at(from).at(i) - 1, from);
}
return;
}
int main() {
ll n, q, a, b;
cin >> n >> q;
vector<vector<ll>> next(n, vector<ll>(0));
for (ll i = 0; i < n - 1; i++) {
cin >> a >> b;
next.at(a - 1).push_back(b);
next.at(b - 1).push_back(a);
}
vector<ll> p(q), x(q), cnt(n, 0);
for (int i = 0; i < q; i++) {
cin >> p.at(i) >> x.at(i);
cnt.at(p.at(i) - 1) += x.at(i);
}
seq(next, cnt, 0, 0);
for (ll i = 0; i < n - 1; i++)
cout << cnt.at(i) << " ";
cout << cnt.at(n - 1) << endl;
} | replace | 5 | 6 | 5 | 6 | TLE | |
p02936 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < n; i++)
vector<int> edges[100010];
long long ans[100010];
long long bucket[100010];
void dfs(int node, int prev, long long val = 0) {
val += bucket[node];
ans[node] = val;
for (auto &x : edges[node]) {
if (prev - x) {
dfs(x, node, val);
}
}
}
int main() {
int n, q;
int a, b;
cin >> n >> q;
forn(i, n - 1) {
cin >> a >> b;
edges[a].push_back(b);
edges[b].push_back(a);
}
forn(i, q) {
cin >> a >> b;
bucket[a] += b;
}
dfs(1, -1);
forn(i, n) { cout << ans[i + 1] << " "; }
cout << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < n; i++)
vector<int> edges[200010];
long long ans[200010];
long long bucket[200010];
void dfs(int node, int prev, long long val = 0) {
val += bucket[node];
ans[node] = val;
for (auto &x : edges[node]) {
if (prev - x) {
dfs(x, node, val);
}
}
}
int main() {
int n, q;
int a, b;
cin >> n >> q;
forn(i, n - 1) {
cin >> a >> b;
edges[a].push_back(b);
edges[b].push_back(a);
}
forn(i, q) {
cin >> a >> b;
bucket[a] += b;
}
dfs(1, -1);
forn(i, n) { cout << ans[i + 1] << " "; }
cout << endl;
return 0;
}
| replace | 4 | 7 | 4 | 7 | 0 | |
p02936 | C++ | Runtime Error | #include <bits/stdc++.h>
#define pb push_back
using namespace std;
vector<long long> g[100005];
bool vis[100005];
long long lazy[100005];
long long cnt[100005];
void dfs(int i) {
if (vis[i])
return;
vis[i] = 1;
cnt[i] += lazy[i];
for (int j = 0; j < g[i].size(); j++) {
if (!vis[g[i][j]]) {
cnt[g[i][j]] += cnt[i];
dfs(g[i][j]);
}
}
}
int main() {
long long n, q;
cin >> n >> q;
for (long long i = 1; i < n; i++) {
long long a, b;
cin >> a >> b;
g[a].pb(b);
g[b].pb(a);
}
while (q--) {
long long x, p;
cin >> x >> p;
lazy[x] += p;
}
dfs(1);
for (long long i = 1; i <= n; i++)
cout << cnt[i] << ' ';
return 0;
}
| #include <bits/stdc++.h>
#define pb push_back
using namespace std;
vector<long long> g[200005];
bool vis[200005];
long long lazy[200005];
long long cnt[200005];
void dfs(int i) {
if (vis[i])
return;
vis[i] = 1;
cnt[i] += lazy[i];
for (int j = 0; j < g[i].size(); j++) {
if (!vis[g[i][j]]) {
cnt[g[i][j]] += cnt[i];
dfs(g[i][j]);
}
}
}
int main() {
long long n, q;
cin >> n >> q;
for (long long i = 1; i < n; i++) {
long long a, b;
cin >> a >> b;
g[a].pb(b);
g[b].pb(a);
}
while (q--) {
long long x, p;
cin >> x >> p;
lazy[x] += p;
}
dfs(1);
for (long long i = 1; i <= n; i++)
cout << cnt[i] << ' ';
return 0;
}
| replace | 3 | 7 | 3 | 7 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.