Datasets:

problem_id
stringlengths
6
6
buggy_code
stringlengths
8
526k
fixed_code
stringlengths
12
526k
labels
listlengths
0
15
buggy_submission_id
int64
1
1.54M
fixed_submission_id
int64
2
1.54M
user_id
stringlengths
10
10
language
stringclasses
9 values
p02952
#define _USE_MATH_DEFINES #include <algorithm> #include <bitset> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef tuple<ll, ll, ll> tl3; const int BIG_NUM = 1e9; const ll INF = 1000000000000000000; const ll MOD = 1e9 + 7; // const ll MOD = 998244353; int main() { int n; cin >> n; int ans = 0; for (int i = 1; i <= n; i++) { int cnt = 0; int num = i; while (num > 0) { cnt++; num /= 10; } if (num % 2 == 1) { ans++; } } cout << ans << endl; }
#define _USE_MATH_DEFINES #include <algorithm> #include <bitset> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef tuple<ll, ll, ll> tl3; const int BIG_NUM = 1e9; const ll INF = 1000000000000000000; const ll MOD = 1e9 + 7; // const ll MOD = 998244353; int main() { int n; cin >> n; int ans = 0; for (int i = 1; i <= n; i++) { int cnt = 0; int num = i; while (num > 0) { cnt++; num /= 10; } if (cnt % 2 == 1) { ans++; } } cout << ans << endl; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
753,395
753,396
u156778176
cpp
p02952
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0), ios::sync_with_stdio(false); int n; cin >> n; int ans = n; for (int i = 90, j = 100; j < n; i *= 100, j *= 100) ans -= i; int size = to_string(n).size(); if (size % 2 == 0) { int p = 1; while (size > 1) p *= 10, --size; ans -= n - p + 1; } cout << ans << "\n"s; }
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0), ios::sync_with_stdio(false); int n; cin >> n; int ans = n; for (int i = 90, j = 100; j <= n; i *= 100, j *= 100) ans -= i; int size = to_string(n).size(); if (size % 2 == 0) { int p = 1; while (size > 1) p *= 10, --size; ans -= n - p + 1; } cout << ans << "\n"s; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
753,397
753,398
u104613587
cpp
p02952
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; string str; int ans = 0; for (int i = 1; i < N; i++) { str = to_string(i); if (str.size() % 2 == 1) ans++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; string str; int ans = 0; for (int i = 1; i < N + 1; i++) { str = to_string(i); if (str.size() % 2 == 1) ans++; } cout << ans << endl; }
[ "control_flow.loop.for.condition.change", "misc.off_by_one" ]
753,421
753,422
u171046846
cpp
p02952
#include <bits/stdc++.h> using namespace std; using ll = long long; #define all(v) v.begin(), v.end() int main() { ll N; cin >> N; ll ans = 0; if (N > 9) { ans += 9; } else { cout << N << endl; return 0; } if (N > 99) { if (N > 999) { ans += 900; } else { ans += N - 99; } } if (ans > 9999) { if (ans > 99999) { ans += 90000; } else { ans += N - 9999; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define all(v) v.begin(), v.end() int main() { ll N; cin >> N; ll ans = 0; if (N > 9) { ans += 9; } else { cout << N << endl; return 0; } if (N > 99) { if (N > 999) { ans += 900; } else { ans += N - 99; } } if (N > 9999) { if (N > 99999) { ans += 90000; } else { ans += N - 9999; } } cout << ans << endl; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
753,431
753,432
u072293789
cpp
p02952
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ans; string s; for (int i = 1; i <= n; i++) { s = to_string(i); if (s.size() % 2 == 1) { ans++; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ans = 0; string s; for (int i = 1; i <= n; i++) { s = to_string(i); if (s.size() % 2 == 1) { ans++; } } cout << ans << endl; return 0; }
[ "variable_declaration.value.change", "control_flow.return.add", "control_flow.return.0.add" ]
753,439
753,440
u113731459
cpp
p02952
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; int main() { int n; cin >> n; int res = 0; for (int i = 1; i < n; i *= 100) { res += min(n, i * 10 - 1) - i + 1; } cout << res << endl; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; int main() { int n; cin >> n; int res = 0; for (int i = 1; i <= n; i *= 100) { res += min(n, i * 10 - 1) - i + 1; } cout << res << endl; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
753,441
753,442
u495704746
cpp
p02952
#include <bits/stdc++.h> using namespace std; #define ll long long #define lvector vector<ll> #define cvector vector<char> #define svector vector<string> #define lque queue<ll> #define lpque priority_queue<ll> #define dlpque priority_queue<ll, lvector, greater<ll>> #define P pair<ll, ll> #define ALL(a) a.begin(), a.end() #define RALL(a) a.rbegin(), a.rend() #define rep(i, n) for (ll i = 0; i < n; ++i) #define print(a) cout << (a) << endl int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, ans = 0; cin >> n; for (ll i = 1; i <= n; ++i) { if (1 <= i && i < 10) ans++; if (100 <= i && i < 1000) ans++; if (10000 <= i && i < 1000000) ans++; } print(ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define lvector vector<ll> #define cvector vector<char> #define svector vector<string> #define lque queue<ll> #define lpque priority_queue<ll> #define dlpque priority_queue<ll, lvector, greater<ll>> #define P pair<ll, ll> #define ALL(a) a.begin(), a.end() #define RALL(a) a.rbegin(), a.rend() #define rep(i, n) for (ll i = 0; i < n; ++i) #define print(a) cout << (a) << endl int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, ans = 0; cin >> n; for (ll i = 1; i <= n; ++i) { if (1 <= i && i < 10) ans++; if (100 <= i && i < 1000) ans++; if (10000 <= i && i < 100000) ans++; } print(ans); return 0; }
[ "literal.number.change", "control_flow.branch.if.condition.change" ]
753,451
753,452
u894339989
cpp
p02952
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, a, b) for (int i = (a); i < (b); ++i) #define all(a) (a).begin(), (a).end() #define all2(a, b) (a).begin(), (a).begin() + (b) #define debug(vari) cerr << #vari << " = " << (vari) << endl; int main() { int N; cin >> N; int ans = 0; rep2(i, 1, N + 1) { int cnt = 0; int tmp = i; while (tmp) { cnt += tmp % 10; tmp /= 10; } if (cnt % 2 == 1) { ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, a, b) for (int i = (a); i < (b); ++i) #define all(a) (a).begin(), (a).end() #define all2(a, b) (a).begin(), (a).begin() + (b) #define debug(vari) cerr << #vari << " = " << (vari) << endl; int main() { int N; cin >> N; int ans = 0; rep2(i, 1, N + 1) { int cnt = 0; int tmp = i; while (tmp) { cnt++; tmp /= 10; } if (cnt % 2 == 1) { ans++; } } cout << ans << endl; return 0; }
[ "expression.operation.binary.remove" ]
753,453
753,454
u709144111
cpp
p02952
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <cmath> #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <deque> // deque #include <iostream> // cout, endl, cin #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <string> // string, to_string, stoi #include <tuple> // tuple, make_tuple #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <utility> // pair, make_pair #include <vector> // vector using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, a, b) for (int i = (a); i < (b); ++i) #define all(a) (a).begin(), (a).end() #define all2(a, b) (a).begin(), (a).begin() + (b) int count(int N) { int ans = 0; while (N) { ans++; N /= 10; } return ans; } int main() { int S; cin >> S; int ans = 0; for (int i = 1; i <= S; i++) { int cnt = count(i); if (cnt % 2 == 0) ans++; } cout << ans << endl; return 0; }
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <cmath> #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <deque> // deque #include <iostream> // cout, endl, cin #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <string> // string, to_string, stoi #include <tuple> // tuple, make_tuple #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <utility> // pair, make_pair #include <vector> // vector using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, a, b) for (int i = (a); i < (b); ++i) #define all(a) (a).begin(), (a).end() #define all2(a, b) (a).begin(), (a).begin() + (b) int count(int N) { int ans = 0; while (N) { ans++; N /= 10; } return ans; } int main() { int S; cin >> S; int ans = 0; for (int i = 1; i <= S; i++) { int cnt = count(i); if (cnt % 2 == 1) ans++; } cout << ans << endl; return 0; }
[ "literal.number.change", "control_flow.branch.if.condition.change" ]
753,455
753,456
u709144111
cpp
p02952
// Author: Fuadul Hasan(fuadul202@gmail.com) // BSMRSTU,Gopalganj #include <bits/stdc++.h> using namespace std; int tc = 1; #define happy ios::sync_with_stdio(false); #define coding cin.tie(0); #define F first #define S second #define mp make_pair #define ll long long #define Pi atan(1) * 4 #define pb push_back #define vpr vector<pr> #define pr pair<int, int> #define vi std::vector<int> #define vll std::vector<ll> #define YES printf("YES\n"); #define NO printf("NO\n"); #define Yes printf("Yes\n"); #define No printf("No\n"); #define all(n) n.begin(), n.end() #define point(x) setprecision(x) #define Test printf("Case %d: ", tc++); #define Unique(c) (c).resize(unique(all(c)) - (c).begin()) #define vout(v) \ for (auto z : v) \ cout << z << " "; \ cout << endl; #define error(args...) \ { \ vector<string> _v = split(#args, ','); \ err(_v.begin(), args); \ cout << endl; \ } vector<string> split(const string &s, char c) { vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.emplace_back(x); return move(v); } void err(vector<string>::iterator it) {} template <typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args) { cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...); } const int M = 1e9 + 7; const ll Inf = (ll)2e18 + 5; const int N = 2e5 + 5; ll vis[N], res[N]; int solve() { // happy coding int n; cin >> n; int sum = 0; if (n >= 10) { sum += 9; } if (n >= 1000) { sum += 900; } if (n >= 100000) { sum += 90000; } if (n < 10) { sum += (n % 10) + 1; } if (n >= 100 && n <= 1000) { sum += 100 * ((n / 100) - 1); sum += (n % 100) + 1; } if (n >= 10000 && n <= 100000) { sum += 10000 * ((n / 10000) - 1); sum += (n % 10000) + 1; } cout << sum << endl; return 0; } int main() { int test = 1; // scanf("%d", &test); while (test--) solve(); return 0; }
// Author: Fuadul Hasan(fuadul202@gmail.com) // BSMRSTU,Gopalganj #include <bits/stdc++.h> using namespace std; int tc = 1; #define happy ios::sync_with_stdio(false); #define coding cin.tie(0); #define F first #define S second #define mp make_pair #define ll long long #define Pi atan(1) * 4 #define pb push_back #define vpr vector<pr> #define pr pair<int, int> #define vi std::vector<int> #define vll std::vector<ll> #define YES printf("YES\n"); #define NO printf("NO\n"); #define Yes printf("Yes\n"); #define No printf("No\n"); #define all(n) n.begin(), n.end() #define point(x) setprecision(x) #define Test printf("Case %d: ", tc++); #define Unique(c) (c).resize(unique(all(c)) - (c).begin()) #define vout(v) \ for (auto z : v) \ cout << z << " "; \ cout << endl; #define error(args...) \ { \ vector<string> _v = split(#args, ','); \ err(_v.begin(), args); \ cout << endl; \ } vector<string> split(const string &s, char c) { vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.emplace_back(x); return move(v); } void err(vector<string>::iterator it) {} template <typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args) { cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...); } const int M = 1e9 + 7; const ll Inf = (ll)2e18 + 5; const int N = 2e5 + 5; ll vis[N], res[N]; int solve() { // happy coding int n; cin >> n; int sum = 0; if (n >= 10) { sum += 9; } if (n >= 1000) { sum += 900; } if (n >= 100000) { sum += 90000; } if (n < 10) { sum += (n % 10); } if (n >= 100 && n < 1000) { sum += 100 * ((n / 100) - 1); sum += (n % 100) + 1; } if (n >= 10000 && n < 100000) { sum += 10000 * ((n / 10000) - 1); sum += (n % 10000) + 1; } cout << sum << endl; return 0; } int main() { int test = 1; // scanf("%d", &test); while (test--) solve(); return 0; }
[ "expression.operation.binary.remove", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
753,467
753,468
u526278960
cpp
p02952
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int ans = 0; for (int i = 0; i <= N; i++) { if (i >= 0 && i < 10) { ans += 1; } else if (i > 99 && i < 1000) { ans += 1; } else if (i > 9999 && i < 100000) { ans += 1; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int ans = 0; for (int i = 0; i <= N; i++) { if (i > 0 && i < 10) { ans += 1; } else if (i > 99 && i < 1000) { ans += 1; } else if (i > 9999 && i < 100000) { ans += 1; } } cout << ans << endl; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
753,469
753,470
u335151353
cpp
p02952
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define adrep(i, s, n) for (int i = (s); i < (n); i++) using namespace std; typedef long long ll; int main() { ll N; cin >> N; int count = 0; rep(i, N) { if (i == 0) continue; string s = to_string(i); if (s.length() % 2 == 1) count++; } cout << count << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define adrep(i, s, n) for (int i = (s); i < (n); i++) using namespace std; typedef long long ll; int main() { ll N; cin >> N; int count = 0; rep(i, N + 1) { if (i == 0) continue; string s = to_string(i); if (s.length() % 2 == 1) count++; } cout << count << endl; }
[ "expression.operation.binary.add" ]
753,475
753,476
u978535698
cpp
p02952
#include <algorithm> #include <cstdlib> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int n; cin >> n; int keta = 0; if (n < 10) { cout << n; return 0; } for (int i = 10;; i *= 10) { if (i > n) { keta = i / 10; break; } } if (keta == 10) cout << "9"; if (keta == 100) cout << (n + 9) - keta + 1; if (keta == 1000) cout << "909"; if (keta == 10000) cout << n - keta + 1 + 909; if (keta > 10000) cout << "90999"; return 0; }
#include <algorithm> #include <cstdlib> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int n; cin >> n; int keta = 0; if (n < 10) { cout << n; return 0; } for (int i = 10;; i *= 10) { if (i > n) { keta = i / 10; break; } } if (keta == 10) cout << "9"; if (keta == 100) cout << (n + 9) - keta + 1; if (keta == 1000) cout << "909"; if (keta == 10000) cout << n - keta + 1 + 909; if (keta > 10000) cout << "90909"; return 0; }
[ "literal.string.change", "io.output.change" ]
753,479
753,480
u047572420
cpp
p02952
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int ans = 0; for (int i = 1; i < N; i++) { int n = i; int sum = 0; while (n > 0) { n /= 10; sum++; } if (sum % 2 == 1) ans++; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int ans = 0; for (int i = 1; i <= N; i++) { int n = i; int sum = 0; while (n > 0) { n /= 10; sum++; } if (sum % 2 == 1) ans++; } cout << ans; return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
753,485
753,486
u109191542
cpp
p02952
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int ans = 0; for (int i = 0; i < N; i++) { int n = i; int sum = 0; while (n > 0) { n /= 10; sum++; } if (sum % 2 == 1) ans++; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int ans = 0; for (int i = 1; i <= N; i++) { int n = i; int sum = 0; while (n > 0) { n /= 10; sum++; } if (sum % 2 == 1) ans++; } cout << ans; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
753,487
753,486
u109191542
cpp
p02952
#include <bits/stdc++.h> using namespace std; int main() { int n, ans = 0, ten = 10; cin >> n; for (;;) { if (n >= ten) { ans += ten - 1; } else if (n >= ten / 10) { cout << ans + (n / (ten / 10) - 1) * (ten / 10) + n % (ten / 10) + 1 << endl; break; } else { cout << ans << endl; break; } ten *= 100; } return (0); }
#include <bits/stdc++.h> using namespace std; int main() { int n, ans = 0, ten = 10; cin >> n; for (;;) { if (n >= ten) { ans += ten - ten / 10; } else if (n >= ten / 10) { cout << ans + (n / (ten / 10) - 1) * (ten / 10) + n % (ten / 10) + 1 << endl; break; } else { cout << ans << endl; break; } ten *= 100; } return (0); }
[ "assignment.value.change", "identifier.replace.add", "literal.replace.remove", "expression.operation.binary.change", "assignment.change" ]
753,488
753,489
u490965711
cpp
p02952
#include <algorithm> #include <chrono> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <stdio.h> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { int n; int ans = 0, tmp = 1, tmp2, p = 100; cin >> n; rep(i, n + 1) { if (i > 0 && i < 10) ans++; if (i > 99 && i < 1000) ans++; if (i > 9999 && i < 10000) ans++; } cout << ans; }
#include <algorithm> #include <chrono> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <stdio.h> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { int n; int ans = 0, tmp = 1, tmp2, p = 100; cin >> n; rep(i, n + 1) { if (i > 0 && i < 10) ans++; if (i > 99 && i < 1000) ans++; if (i > 9999 && i < 100000) ans++; } cout << ans; }
[ "literal.number.change", "control_flow.branch.if.condition.change" ]
753,490
753,491
u928591554
cpp
p02952
#include <algorithm> #include <chrono> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <stdio.h> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { int n; int ans = 0, tmp = 1, tmp2, p = 100; cin >> n; rep(i, n + 1) { if (i > 0 && i < 9) ans++; if (i > 99 && i < 1000) ans++; if (i > 9999 && i < 10000) ans++; } cout << ans; }
#include <algorithm> #include <chrono> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <stdio.h> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { int n; int ans = 0, tmp = 1, tmp2, p = 100; cin >> n; rep(i, n + 1) { if (i > 0 && i < 10) ans++; if (i > 99 && i < 1000) ans++; if (i > 9999 && i < 100000) ans++; } cout << ans; }
[ "literal.number.change", "control_flow.branch.if.condition.change" ]
753,492
753,491
u928591554
cpp
p02952
#include "bits/stdc++.h" #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) using namespace std; const long long INF = 1LL << 61; int main() { int N; cin >> N; int ans = 0; rep(i, N) { if (to_string(i + 1).size() % 2 == 0) ++ans; } cout << ans; }
#include "bits/stdc++.h" #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) using namespace std; const long long INF = 1LL << 61; int main() { int N; cin >> N; int ans = 0; rep(i, N) { if (to_string(i + 1).size() % 2 != 0) ++ans; } cout << ans; }
[ "misc.opposites", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
753,524
753,525
u289578952
cpp
p02952
#include <bits/stdc++.h> #define FOR(i, n) for (ll i = 0; i < n; i++) #define FORR(i, n) for (ll i = n; i >= 0; i--) #define FORS(i, m, n) for (int i = m; i < n; i++) #define ALL(v) accumulate(v.begin(), v.end(), 0) #define SORT(v) sort(v.begin(), v.end()) #define OUT(n) (cout << n << endl) #define IN1(a) (cin >> a) #define IN2(a, b) (cin >> a >> b) #define IN3(a, b, c) (cin >> a >> b >> c) #define IN4(a, b, c, d) (cin >> a >> b >> c >> d) using namespace std; typedef long long ll; int main() { ll n, ans; string ss; IN1(n); FORS(i, 1, n + 1) { ss = to_string(i); if ((ss.size()) % 2 == 1) { ans++; } } OUT(ans); }
#include <bits/stdc++.h> #define FOR(i, n) for (ll i = 0; i < n; i++) #define FORR(i, n) for (ll i = n; i >= 0; i--) #define FORS(i, m, n) for (int i = m; i < n; i++) #define ALL(v) accumulate(v.begin(), v.end(), 0) #define SORT(v) sort(v.begin(), v.end()) #define OUT(n) (cout << n << endl) #define IN1(a) (cin >> a) #define IN2(a, b) (cin >> a >> b) #define IN3(a, b, c) (cin >> a >> b >> c) #define IN4(a, b, c, d) (cin >> a >> b >> c >> d) using namespace std; typedef long long ll; int main() { ll n, ans = 0; string ss; IN1(n); FORS(i, 1, n + 1) { ss = to_string(i); if ((ss.size()) % 2 == 1) { ans++; } } OUT(ans); }
[ "variable_declaration.value.change" ]
753,558
753,559
u312666261
cpp
p02952
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int N; cin >> N; int ans = 0; for (int i = 1; i < N; i++) { if (i >= 1 && i <= 9) ans++; if (i >= 100 && i <= 999) ans++; if (i >= 10000 && i <= 99999) ans++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int N; cin >> N; int ans = 0; for (int i = 1; i <= N; i++) { if (i >= 1 && i <= 9) ans++; if (i >= 100 && i <= 999) ans++; if (i >= 10000 && i <= 99999) ans++; } cout << ans << endl; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
753,589
753,590
u763377272
cpp
p02952
#include <stdio.h> int main(void) { int i, n, ans = 0; scanf("%d", &n); for (i = 1; i < 10; ++i) if (i <= n) ++ans; for (i = 100; i < 1000; ++i) if (i <= n) ++ans; for (i = 10000; i < 100000; ++i) if (i <= n) +ans; printf("%lld", ans); return 0; }
#include <stdio.h> int main(void) { int i, n, ans = 0; scanf("%d", &n); for (i = 1; i < 10; ++i) if (i <= n) ++ans; for (i = 100; i < 1000; ++i) if (i <= n) ++ans; for (i = 10000; i < 100000; ++i) if (i <= n) ++ans; printf("%lld", ans); return 0; }
[]
753,593
753,594
u440920318
cpp
p02952
#include <stdio.h> int main(void) { int i, n, ans = 0; scanf("%d", &n); for (i = 1; i < 10; ++i) if (i < n) ++ans; for (i = 100; i < 1000; ++i) if (i < n) ++ans; for (i = 10000; i < 100000; ++i) if (i < n) +ans; printf("%lld", ans); return 0; }
#include <stdio.h> int main(void) { int i, n, ans = 0; scanf("%d", &n); for (i = 1; i < 10; ++i) if (i <= n) ++ans; for (i = 100; i < 1000; ++i) if (i <= n) ++ans; for (i = 10000; i < 100000; ++i) if (i <= n) ++ans; printf("%lld", ans); return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
753,595
753,594
u440920318
cpp
p02952
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < n; i++) int num(int m) { int res = 9; REP(i, m) { res *= 10; } res /= 10; return res; } int main() { int n; cin >> n; int d = n; int count = 0; while (d > 0) { d /= 10; count++; } int res = 0; if (count % 2 == 0) { for (int i = 1; i < count; i += 2) { res += num(i); } } else { for (int i = 1; i <= count; i += 2) { res += num(i); } res -= pow(10, count) - n + 1; } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < n; i++) int num(int m) { int res = 9; REP(i, m) { res *= 10; } res /= 10; return res; } int main() { int n; cin >> n; int d = n; int count = 0; while (d > 0) { d /= 10; count++; } int res = 0; if (count % 2 == 0) { for (int i = 1; i < count; i += 2) { res += num(i); } } else { for (int i = 1; i <= count; i += 2) { res += num(i); } res -= pow(10, count) - n - 1; } cout << res << endl; }
[ "misc.opposites", "expression.operator.arithmetic.change", "assignment.value.change", "expression.operation.binary.change" ]
753,603
753,604
u231354686
cpp
p02952
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < n; i++) int num(int m) { int res = 9; REP(i, m) { res *= 10; } res /= 10; return res; } int main() { int n; cin >> n; int d = n; int count = 0; while (d > 0) { d /= 10; count++; } int res = 0; if (count % 2 == 0) { for (int i = 1; i < count; i += 2) { res += num(i); } } else { for (int i = 1; i <= count; i += 2) { res += num(i); } res -= 10 * count - n + 1; } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < n; i++) int num(int m) { int res = 9; REP(i, m) { res *= 10; } res /= 10; return res; } int main() { int n; cin >> n; int d = n; int count = 0; while (d > 0) { d /= 10; count++; } int res = 0; if (count % 2 == 0) { for (int i = 1; i < count; i += 2) { res += num(i); } } else { for (int i = 1; i <= count; i += 2) { res += num(i); } res -= pow(10, count) - n - 1; } cout << res << endl; }
[ "call.add", "assignment.value.change", "expression.operation.binary.change", "call.arguments.change", "misc.opposites", "expression.operator.arithmetic.change" ]
753,605
753,604
u231354686
cpp
p02952
#include <iostream> using namespace std; int GetDigit(int num) { int digit = 0; while (num != 0) { num /= 10; digit++; } return digit; } int main() { int n; cin >> n; int count = 0; for (int i = 0; i < n; i++) { if (GetDigit(i) % 2 != 0) count++; } cout << count << endl; }
#include <iostream> using namespace std; int GetDigit(int num) { int digit = 0; while (num != 0) { num /= 10; digit++; } return digit; } int main() { int n; cin >> n; int count = 0; for (int i = 1; i < n + 1; i++) { if (GetDigit(i) % 2 != 0) count++; } cout << count << endl; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "control_flow.loop.for.condition.change", "misc.off_by_one" ]
753,610
753,611
u878454346
cpp
p02952
#include <bits/stdc++.h> using namespace std; bool f(int x) { int keta = 0; while (x) { keta++; x /= 10; } return keta % 2 == 1; } int main() { int n; cin >> n; int ans = 0; for (int i = 0; i < n; i++) { if (f(i)) ans++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; bool f(int x) { int keta = 0; while (x) { keta++; x /= 10; } return keta % 2 == 1; } int main() { int n; cin >> n; int ans = 0; for (int i = 1; i <= n; i++) { if (f(i)) ans++; } cout << ans << endl; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
753,612
753,613
u576472702
cpp
p02952
/*dismint|jjc*/ #include <bits/stdc++.h> using namespace std; #define forl(V, S, E) for (int V = S; V < E; V++) #define ford(V, S, E) for (int V = S; V >= E; V--) #define fore(E, X) for (auto &E : X) #define println(X) cout << X << endl #define printe(X) \ for (auto &E : X) \ cout << E << " "; \ cout << endl typedef unordered_map<int, unordered_set<int>> graph; typedef long long ll; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, ans = 0; cin >> n; forl(i, 1, n) { string s = to_string(i); ans += ((int)s.length()) % 2; } println(ans); }
/*dismint|jjc*/ #include <bits/stdc++.h> using namespace std; #define forl(V, S, E) for (int V = S; V < E; V++) #define ford(V, S, E) for (int V = S; V >= E; V--) #define fore(E, X) for (auto &E : X) #define println(X) cout << X << endl #define printe(X) \ for (auto &E : X) \ cout << E << " "; \ cout << endl typedef unordered_map<int, unordered_set<int>> graph; typedef long long ll; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, ans = 0; cin >> n; forl(i, 1, n + 1) { string s = to_string(i); ans += ((int)s.length()) % 2; } println(ans); }
[ "expression.operation.binary.add" ]
753,614
753,615
u602301110
cpp
p02952
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int count = 0; for (int i = 0; i < N; i++) { if (1 <= i && i <= 9) { count++; } else if (100 <= i && i <= 999) { count++; } else if (10000 <= i && i <= 99999) { count++; } } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int count = 0; for (int i = 1; i <= N; i++) { if (1 <= i && i <= 9) { count++; } else if (100 <= i && i <= 999) { count++; } else if (10000 <= i && i <= 99999) { count++; } } cout << count << endl; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
753,616
753,617
u262451272
cpp
p02952
#include <bits/stdc++.h> #if ONLINE_JUDGE #define DEBUG false #else #define DEBUG true #endif #define fastcin() \ cin.tie(0); \ ios::sync_with_stdio(false) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++) #define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--) #define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--) #define foreach(i, vec) for (auto &&i : vec) #define all(x) (x).begin(), (x).end() #define SORT(x) sort(all(x)) #define REV(x) reverse(all(x)) #define MAX(x) *max_element(all(x)) #define MIN(x) *min_element(all(x)) #define LOWitr(x, n) lower_bound(all(x), n) #define UPRitr(x, n) upper_bound(all(x), n) #define cii(x) \ int x; \ cin >> x #define cill(x) \ LL x; \ cin >> x #define cis(x) \ string x; \ cin >> x #define co(x) cout << x << endl #define pb push_back #define mp make_pair #define F first #define S second #define truecheck assert #define dump(x) cerr << #x << ": " << (x) << endl using namespace std; typedef long long LL; typedef long long int64; typedef std::vector<int> VI; typedef std::vector<VI> VVI; typedef std::vector<LL> VL; typedef std::vector<VL> VVL; typedef std::vector<string> VS; typedef std::pair<int, int> PII; typedef std::pair<int64, int64> PLL; typedef std::queue<int> QI; typedef std::priority_queue<int> PQI; template <class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template <class T, class U> inline bool chmin(T &a, const U &b) { if (b < a) { a = b; return true; } return false; } template <class T, class U> inline void vcin(T &v, U n) { rep(i, n) { typename T::value_type a; cin >> a; v.pb(a); } } const int INF = 1e9, MOD = 1e9 + 7; const LL LLINF = 1e16; // M_PI 3.1415... int main() { fastcin(); cout << fixed << setprecision(10); cill(n); LL ans = 0; rep(i, n) { if (to_string(i).length() % 2 == 1) ans++; } co(ans); return 0; }
#include <bits/stdc++.h> #if ONLINE_JUDGE #define DEBUG false #else #define DEBUG true #endif #define fastcin() \ cin.tie(0); \ ios::sync_with_stdio(false) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++) #define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--) #define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--) #define foreach(i, vec) for (auto &&i : vec) #define all(x) (x).begin(), (x).end() #define SORT(x) sort(all(x)) #define REV(x) reverse(all(x)) #define MAX(x) *max_element(all(x)) #define MIN(x) *min_element(all(x)) #define LOWitr(x, n) lower_bound(all(x), n) #define UPRitr(x, n) upper_bound(all(x), n) #define cii(x) \ int x; \ cin >> x #define cill(x) \ LL x; \ cin >> x #define cis(x) \ string x; \ cin >> x #define co(x) cout << x << endl #define pb push_back #define mp make_pair #define F first #define S second #define truecheck assert #define dump(x) cerr << #x << ": " << (x) << endl using namespace std; typedef long long LL; typedef long long int64; typedef std::vector<int> VI; typedef std::vector<VI> VVI; typedef std::vector<LL> VL; typedef std::vector<VL> VVL; typedef std::vector<string> VS; typedef std::pair<int, int> PII; typedef std::pair<int64, int64> PLL; typedef std::queue<int> QI; typedef std::priority_queue<int> PQI; template <class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template <class T, class U> inline bool chmin(T &a, const U &b) { if (b < a) { a = b; return true; } return false; } template <class T, class U> inline void vcin(T &v, U n) { rep(i, n) { typename T::value_type a; cin >> a; v.pb(a); } } const int INF = 1e9, MOD = 1e9 + 7; const LL LLINF = 1e16; // M_PI 3.1415... int main() { fastcin(); cout << fixed << setprecision(10); cill(n); LL ans = 0; REP(i, 1, n + 1) { if (to_string(i).length() % 2 == 1) ans++; } co(ans); return 0; }
[ "call.arguments.add" ]
753,620
753,621
u428830428
cpp
p02952
#include <bits/stdc++.h> using namespace std; int check_digits(int n) { int res = 0; while (n > 0) { res++; n /= 10; } return res; } int main() { int N; cin >> N; int ans = 0; for (int i = 0; i < N; i++) { if (check_digits(i) % 2) ans++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int check_digits(int n) { int res = 0; while (n > 0) { res++; n /= 10; } return res; } int main() { int N; cin >> N; int ans = 0; for (int i = 0; i <= N; i++) { if (check_digits(i) % 2) ans++; } cout << ans << endl; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
753,622
753,623
u538808095
cpp
p02952
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int count = 0; for (int i = 1; i < N; i++) { string s = to_string(i); if (s.size() % 2 == 1) count++; } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int count = 0; for (int i = 1; i <= N; i++) { string s = to_string(i); if (s.size() % 2 == 1) count++; } cout << count << endl; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
753,626
753,627
u760748346
cpp
p02952
#include <bits/stdc++.h> using namespace std; int main() { int n; int ans = 0; cin >> n; for (int i = 1; i <= n; i++) { if (n >= 1 && n <= 9 || n >= 100 && n <= 999 || n >= 10000 && n <= 99999) ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; int ans = 0; cin >> n; for (int i = 1; i <= n; i++) { if (i >= 1 && i <= 9 || i >= 100 && i <= 999 || i >= 10000 && i <= 99999) ans++; } cout << ans << endl; return 0; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
753,634
753,635
u578969098
cpp
p02952
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long using namespace std; int main() { int N; cin >> N; int ans = 0; for (int ii = 1; ii <= N; ++ii) { int digit = 0; int tmp = ii; while (tmp > 0) { digit++; tmp = tmp >> 1; } if (digit % 2 == 1) { ans++; } } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long using namespace std; int main() { int N; cin >> N; int ans = 0; for (int ii = 1; ii <= N; ++ii) { int digit = 0; int tmp = ii; while (tmp > 0) { digit++; tmp /= 10; } if (digit % 2 == 1) { ans++; } } cout << ans << "\n"; return 0; }
[ "assignment.change" ]
753,657
753,658
u762158020
cpp
p02952
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int count = 0; for (int i = 0; i < N + 1; i++) { string str = std::to_string(i); int n = str.size(); if (n % 2 == 1) { count++; } } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int count = 0; for (int i = 1; i < N + 1; i++) { string s = to_string(i); int n = s.size(); if (n % 2 == 1) { count++; } } cout << count << endl; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "variable_declaration.name.change", "identifier.change" ]
753,659
753,660
u896053584
cpp
p02952
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int ans = 0; for (int i = 0; i < N; i++) { if (to_string(i).length() % 2 == 1) ans++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int ans = 0; for (int i = 1; i <= N; i++) { if (to_string(i).length() % 2 == 1) ans++; } cout << ans << endl; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
753,666
753,667
u085235341
cpp
p02952
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, j, n) for (int i = (j); i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) using ll = long long; int main() { int ans = 0; int n; FOR(i, 1, n + 1) { if (to_string(i).length() % 2 == 1) { ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, j, n) for (int i = (j); i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) using ll = long long; int main() { int ans = 0; int n; cin >> n; FOR(i, 1, n + 1) { if (to_string(i).length() % 2 == 1) { ans++; } } cout << ans << endl; return 0; }
[]
753,673
753,674
u103365231
cpp
p02952
#include <stdio.h> int main() { int a; scanf("%d", &a); if (a < 10) printf("%d", a); else if (a < 100) printf("10"); else if (a < 1000) printf("%d", a - 90); else if (a < 10000) printf("910"); else if (a < 100000) printf("%d", a - 9090); else printf("90909"); return 0; }
#include <stdio.h> int main() { int a; scanf("%d", &a); if (a < 10) printf("%d", a); else if (a < 100) printf("9"); else if (a < 1000) printf("%d", a - 90); else if (a < 10000) printf("909"); else if (a < 100000) printf("%d", a - 9090); else printf("90909"); return 0; }
[ "literal.string.change", "call.arguments.change", "io.output.change" ]
753,679
753,678
u054782559
cpp
p02952
#include <algorithm> #include <cassert> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n; cin >> n; int ans = 0; int d = 1; while (d < n) { if (n >= d * 10) { ans += 9 * d; } else { ans += n - d + 1; } d *= 100; } cout << ans << endl; }
#include <algorithm> #include <cassert> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n; cin >> n; int ans = 0; int d = 1; while (d <= n) { if (n >= d * 10) { ans += 9 * d; } else { ans += n - (d - 1); } d *= 100; } cout << ans << endl; }
[ "expression.operator.compare.change", "control_flow.loop.condition.change", "misc.opposites", "expression.operator.arithmetic.change", "assignment.value.change", "expression.operation.binary.change" ]
753,693
753,694
u519759783
cpp
p02952
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int cnt = 0; for (int i = 1; i < n; i++) { string tmp = to_string(i); if ((int)tmp.size() % 2 == 1) { cnt++; } } cout << cnt << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int cnt = 0; for (int i = 1; i <= n; i++) { string tmp = to_string(i); if ((int)tmp.size() % 2 == 1) { cnt++; } } cout << cnt << endl; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
753,706
753,707
u515131769
cpp
p02952
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout) using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); int n; int main() { // IO("input.txt", "output.txt"); ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; int sum = 0; for (int i = 1; i <= n; i++) { string str = to_string(n); if ((int)str.length() % 2) sum++; } cout << sum << "\n"; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout) using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); int n; int main() { // IO("input.txt", "output.txt"); ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; int sum = 0; for (int i = 1; i <= n; i++) { string str = to_string(i); if ((int)str.length() % 2) sum++; } cout << sum << "\n"; return 0; }
[ "identifier.change", "call.arguments.change" ]
753,708
753,709
u027479217
cpp
p02952
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; int main() { int n; cin >> n; int res = 0; rep(i, n + 1) { string s = to_string(i); if (s.size() != 0) res++; } cout << res << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 1; i <= (n); i++) using namespace std; int main() { int n; cin >> n; int res = 0; rep(i, n) { string s = to_string(i); if (s.size() % 2 != 0) res++; } cout << res << endl; }
[ "preprocessor.define.value.change", "literal.integer.change", "expression.operator.compare.change", "expression.operation.binary.remove", "control_flow.branch.if.condition.change" ]
753,722
753,723
u816145694
cpp
p02952
#include <iostream> using namespace std; int digNum(int n) { int digit = 1; for (;;) { if (n / 10 >= 1) digit++; else return digit; n /= 10; } } int main() { unsigned int N; cin >> N; int ans = 0; for (int i = 0; i <= N; i++) { if (digNum(i) % 2 == 1) ans++; } cout << ans << endl; return 0; }
#include <iostream> using namespace std; int digNum(int n) { int digit = 1; for (;;) { if (n / 10 >= 1) digit++; else return digit; n /= 10; } } int main() { unsigned int N; cin >> N; int ans = 0; for (int i = 0; i <= N; i++) { if (digNum(i) % 2 == 1) ans++; } cout << --ans << endl; return 0; }
[]
753,727
753,728
u483747145
cpp
p02952
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MM = 1000000000; const int MOD = MM + 7; const int MAX = 510000; #define rep(i, n) for (ll i = 0; i < n; i++) #define Rep(i, j, n) for (ll i = j; i < n; i++) #define all(vec) vec.begin(), vec.end() template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } const ll INF = 1LL << 60; int main() { int n, cnt; cin >> n; Rep(i, 1, n + 1) { if (to_string(i).size() % 2 == 1) cnt++; } cout << cnt << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MM = 1000000000; const int MOD = MM + 7; const int MAX = 510000; #define rep(i, n) for (ll i = 0; i < n; i++) #define Rep(i, j, n) for (ll i = j; i < n; i++) #define all(vec) vec.begin(), vec.end() template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } const ll INF = 1LL << 60; int main() { int n, cnt = 0; cin >> n; Rep(i, 1, n + 1) { if (to_string(i).size() % 2 == 1) cnt++; } cout << cnt << endl; }
[ "variable_declaration.value.change" ]
753,729
753,730
u560381579
cpp
p02952
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; using ll = long long; int main() { int n, cnt = 0, num = 0; cin >> n; for (int i = 0; i < n; i++) { int n = i; num = 0; while (n) { n /= 10; num++; } if (num % 2 == 1) cnt++; } cout << cnt << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; using ll = long long; int main() { int n, cnt = 0, num = 0; cin >> n; for (int i = 1; i <= n; i++) { int n = i; num = 0; while (n) { n /= 10; num++; } if (num % 2 == 1) cnt++; } cout << cnt << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
753,736
753,737
u654949547
cpp
p02952
#include <algorithm> #include <iostream> #include <math.h> #include <queue> #include <string> #include <vector> #define print(n) std::cout << n << std::endl using namespace std; int main() { int n; cin >> n; int count = 0; for (int i = 0; i < n; i++) { if (to_string(i).size() % 2 == 1) count++; } print(count); }
#include <algorithm> #include <iostream> #include <math.h> #include <queue> #include <string> #include <vector> #define print(n) std::cout << n << std::endl using namespace std; int main() { int n; cin >> n; int count = 0; for (int i = 0; i < n; i++) { if (to_string(i + 1).size() % 2 == 1) count++; } print(count); }
[ "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change", "misc.off_by_one" ]
753,738
753,739
u999788719
cpp
p02952
#include <bits/stdc++.h> #define INF 1000000000 #define ll long long using namespace std; int main() { ll N; cin >> N; ll ans = 0; for (ll i = 1; i < N; ++i) { string n = to_string(i); if (n.size() % 2 == 1) { ans += 1; } } cout << ans << endl; }
#include <bits/stdc++.h> #define INF 1000000000 #define ll long long using namespace std; int main() { ll N; cin >> N; ll ans = 0; for (ll i = 1; i < N + 1; ++i) { string n = to_string(i); // cout << i << endl; if (n.size() % 2 == 1) { ans += 1; } } cout << ans << endl; }
[ "control_flow.loop.for.condition.change", "misc.off_by_one" ]
753,744
753,745
u023958502
cpp
p02952
#include <bits/stdc++.h> using namespace std; int main() { int N, count = 0; cin >> N; for (int i = 0; i < N; i++) { if (i >= 1 && i <= 9) { count++; } if (i >= 100 && i <= 999) { count++; } if (i >= 10000 && i <= 99999) { count++; } } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, count = 0; cin >> N; for (int i = 1; i <= N; i++) { if (i >= 1 && i <= 9) { count++; } if (i >= 100 && i <= 999) { count++; } if (i >= 10000 && i <= 99999) { count++; } } cout << count << endl; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
753,746
753,747
u327950489
cpp
p02952
#include <bits/stdc++.h> using namespace std; #define ll long long typedef pair<ll, ll> P; #define M 1000000007 int main() { int n, c = 0; for (int i = 1; i <= n; i++) { if (i < 10 || i > 99 && i < 1000 || i > 9999 && i < 100000) c++; } cout << c; }
#include <bits/stdc++.h> using namespace std; #define ll long long typedef pair<ll, ll> P; #define M 1000000007 int main() { int n, c = 0; cin >> n; for (int i = 1; i <= n; i++) { if (i < 10 || i > 99 && i < 1000 || i > 9999 && i < 100000) c++; } cout << c; }
[]
753,754
753,755
u987476436
cpp
p02952
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int count = 0; for (int i = 1; i < N; i++) { int c = 0; int j = i; while (j > 0) { j /= 10; c += 1; } if (c % 2 != 0) { count += 1; } } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int count = 0; for (int i = 1; i <= N; i++) { int c = 0; int j = i; while (j > 0) { j /= 10; c += 1; } if (c % 2 != 0) { count += 1; } } cout << count << endl; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
753,762
753,763
u817228348
cpp
p02952
#include <stdio.h> int main(void) { //変数nを定義 int n; scanf("%d", &n); //奇数桁まるまるをカウント int x = 10, res = 0; while (x <= n) { res += x - x / 10; x *= 100; } if (n >= x / 10) { res += n - x / 10 + 1; } printf("%d", &res); return 0; }
#include <stdio.h> int main() { //変数nを定義 int n; scanf("%d", &n); //奇数桁まるまるをカウント int x = 10, res = 0; while (x <= n) { res += x - x / 10; x *= 100; } if (n >= x / 10) { res += n - x / 10 + 1; } printf("%d\n", res); return 0; }
[ "literal.string.change", "call.arguments.change", "io.output.change", "io.output.newline.add" ]
753,775
753,776
u240511938
cpp
p02952
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; using P = pair<int, int>; typedef long long int ll; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) int main() { int n; cin >> n; int ans = 0; for (int i = 1; i < n; i++) { string s; s = to_string(i); if (s.size() % 2 != 0) ans++; } cout << ans << endl; return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; using P = pair<int, int>; typedef long long int ll; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) int main() { int n; cin >> n; int ans = 0; for (int i = 1; i <= n; i++) { string s; s = to_string(i); if (s.size() % 2 != 0) ans++; } cout << ans << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
753,781
753,782
u729285002
cpp
p02952
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; ++i) #define rep2(i, s, n) for (int i = s; i < n; ++i) #define all(a) a.begin(), a.end() #define tmax(a, b, c) max(a, max(b, c)) #define tmin(a, b, c) min(a, min(b, c)) #define pb push_back #define fi first #define se second using namespace std; using ll = long long; using P = pair<int, int>; 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; } const int inf = 1001001001; int main() { int n; cin >> n; int ans = 0; auto cnt = [](int n) { int ret = 0; while (n > 0) { ret++; n /= 10; } return ret; }; rep2(i, 1, n) { if (cnt(i) % 2 == 1) ans++; } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; ++i) #define rep2(i, s, n) for (int i = s; i < n; ++i) #define all(a) a.begin(), a.end() #define tmax(a, b, c) max(a, max(b, c)) #define tmin(a, b, c) min(a, min(b, c)) #define pb push_back #define fi first #define se second using namespace std; using ll = long long; using P = pair<int, int>; 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; } const int inf = 1001001001; int main() { int n; cin >> n; int ans = 0; auto cnt = [](int n) { int ret = 0; while (n > 0) { ret++; n /= 10; } return ret; }; rep2(i, 1, n + 1) { if (cnt(i) % 2 == 1) ans++; } cout << ans << endl; }
[ "expression.operation.binary.add" ]
753,787
753,788
u853721692
cpp
p02952
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n; cin >> n; int count = 0; for (int i = 1; i < n; i++) { string s = to_string(i); if (s.size() % 2 == 1) count++; } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n; cin >> n; int count = 0; for (int i = 1; i <= n; i++) { string s = to_string(i); if (s.size() % 2 == 1) count++; } cout << count << endl; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
753,789
753,790
u799521877
cpp
p02952
#include <iostream> #include <string> using namespace std; bool judge(int n) { bool ans = false; int count = 0; while (n < 0) { count++; n /= 10; }; if (count % 2 != 0) ans = true; return ans; } int main() { int n; cin >> n; int ct = 0; for (int i = 1; i <= n; ++i) { bool tmp = judge(i); if (tmp) ct++; } cout << ct << endl; return 0; }
#include <iostream> #include <string> using namespace std; bool judge(int n) { bool ans = false; int count = 0; while (n > 0) { count++; n /= 10; }; if (count % 2 != 0) ans = true; return ans; } int main() { int n; cin >> n; int ct = 0; for (int i = 1; i <= n; ++i) { bool tmp = judge(i); if (tmp) ct++; } cout << ct << endl; return 0; }
[ "misc.opposites", "expression.operator.compare.change", "control_flow.loop.condition.change" ]
753,801
753,802
u904995051
cpp
p02952
#include <iostream> #include <string> using namespace std; bool judge(int n) { bool ans = false; int count = 0; while (n / 10 < 0) { count++; n /= 10; }; if (count % 2 != 0) ans = true; return ans; } int main() { int n; cin >> n; int ct = 0; for (int i = 1; i <= n; ++i) { bool tmp = judge(i); if (tmp) ct++; } cout << ct << endl; return 0; }
#include <iostream> #include <string> using namespace std; bool judge(int n) { bool ans = false; int count = 0; while (n > 0) { count++; n /= 10; }; if (count % 2 != 0) ans = true; return ans; } int main() { int n; cin >> n; int ct = 0; for (int i = 1; i <= n; ++i) { bool tmp = judge(i); if (tmp) ct++; } cout << ct << endl; return 0; }
[ "control_flow.loop.condition.change", "expression.operation.binary.remove" ]
753,803
753,802
u904995051
cpp
p02952
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int Digit_num(int n) { //桁数を返す関数 int digit = 0; while (n > 0) { digit++; n /= 10; } return digit; } int main() { int n; cin >> n; int count = 0; for (int i = 1; i <= n; i++) { if (Digit_num(i) % 1 == 0) { count++; } } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int Digit_num(int n) { //桁数を返す関数 int digit = 0; while (n > 0) { digit++; n /= 10; } return digit; } int main() { int n; cin >> n; int count = 0; for (int i = 1; i <= n; i++) { if (Digit_num(i) % 2 == 1) { count++; } } cout << count << endl; }
[ "literal.number.change", "control_flow.branch.if.condition.change" ]
753,808
753,809
u452154326
cpp
p02952
#include <bits/stdc++.h> using namespace std; int main() { int N, count; cin >> N; count = 0; for (int i = 1; i < N; i++) { if (i >= 1 && 9 >= i) { count++; } else if (i >= 100 && 999 >= i) { count++; } else if (i >= 10000 && 99999 >= i) { count++; } } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, count; cin >> N; count = 0; for (int i = 1; i <= N; i++) { if (i >= 1 && 9 >= i) { count++; } else if (i >= 100 && 999 >= i) { count++; } else if (i >= 10000 && 99999 >= i) { count++; } } cout << count << endl; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
753,810
753,811
u564060397
cpp
p02949
/* ░░░░░░░░░░░░░░░░▄▄█▀▀██▄▄░░░░░░░ ░░░░░░░░░░░░░▄█▀▀░░░░░░░▀█░░░░░░ ░░░░░░░░░░░▄▀░░░░░░░░░░░░░█░░░░░ ░░░░░░░░░▄█░░░░░░░░░░░░░░░█░░░░░ ░░░░░░░██▀░░░░░░░▄▄▄░░▄░█▄█▄░░░░ ░░░░░▄▀░░░░░░░░░░████░█▄██░▀▄░░░ ░░░░█▀░░░░░░░░▄▄██▀░░█████░██░░░ ░░░█▀░░░░░░░░░▀█░▀█▀█▀▀▄██▄█▀░░░ ░░░██░░░░░░░░░░█░░█░█░░▀▀▄█▀░░░░ ░░░░█░░░░░█░░░▀█░░░░▄░░░░░▄█░░░░ ░░░░▀█░░░░███▄░█░░░░░░▄▄▄▄█▀█▄░░ ░░░░░▀██░░█▄▀▀██░░░░░░░░▄▄█░░▀▄░ ░░░░░░▀▀█▄░▀▄▄░▄░░░░░░░███▀░░▄██ ░░░░░░░░░▀▀▀███▀█▄░░░░░█▀░▀░░░▀█ ░░░░░░░░░░░░▄▀░░░▀█▄░░░░░▄▄░░▄█▀ ░░░▄▄▄▀▀▀▀▀█▀░░░░░█▄▀▄▄▄▄▄▄█▀▀░░ ░▄█░░░▄██▀░░░░░░░░░█▄░░░░░░░░░░░ █▀▀░▄█░░░░░░░░░░░░░░▀▀█▄░░░░░░░░ █░░░█░░░░░░░░░░░░░░░░░░█▄░░░░░░░ */ #include <bits/stdc++.h> using namespace std; #define pb push_back #define dbg(x) cout << #x << '=' << x << '\n'; #define ll long long #define x first #define y second #define pi pair<int, int> #define pii pair<pair<int, int>, int> #define vi vector<int> const ll mod = 1000000007; const ll nmax = 1000003; #define int ll int n, m, p, d[50001]; vi g1[2505]; vector<pi> g[50001]; vector<pii> edg; bool viz[2505], viz1[2505]; void dfs(int nod) { viz[nod] = 1; for (int i : g1[nod]) { if (!viz[i]) { dfs(i); } } } void dfs1(int nod) { viz1[nod] = 1; for (pi i : g[nod]) { if (!viz1[i.x]) { dfs1(i.x); } } } int32_t main() { ios_base ::sync_with_stdio(0); cin.tie(); cout.tie(); cin >> n >> m >> p; for (int i = 1, x, y, c; i <= m; i++) { cin >> x >> y >> c; g[x].pb({y, p - c}); g1[y].pb(x); // edg.pb({{x, y}, c}); } dfs(n); dfs1(1); // for(int i=1; i<=n; i++) cout<<viz[i]<<" "; vi prev; set<int> s; prev.pb(1); for (int i = 2; i <= n; i++) d[i] = 1e9; for (int i = 1; i <= n; i++) { for (int x : prev) { for (pi xd : g[x]) { int y = xd.x, c = xd.y, lol = d[y]; d[y] = min(d[y], d[x] + c); if (i == n && viz[y] == 0 && viz1[y] == 0 && lol != d[y]) return cout << -1, 0; if (lol != d[y]) s.insert(y); } } prev.clear(); for (int nod : s) prev.pb(nod); s.clear(); } cout << max(0LL, -d[n]); }
/* ░░░░░░░░░░░░░░░░▄▄█▀▀██▄▄░░░░░░░ ░░░░░░░░░░░░░▄█▀▀░░░░░░░▀█░░░░░░ ░░░░░░░░░░░▄▀░░░░░░░░░░░░░█░░░░░ ░░░░░░░░░▄█░░░░░░░░░░░░░░░█░░░░░ ░░░░░░░██▀░░░░░░░▄▄▄░░▄░█▄█▄░░░░ ░░░░░▄▀░░░░░░░░░░████░█▄██░▀▄░░░ ░░░░█▀░░░░░░░░▄▄██▀░░█████░██░░░ ░░░█▀░░░░░░░░░▀█░▀█▀█▀▀▄██▄█▀░░░ ░░░██░░░░░░░░░░█░░█░█░░▀▀▄█▀░░░░ ░░░░█░░░░░█░░░▀█░░░░▄░░░░░▄█░░░░ ░░░░▀█░░░░███▄░█░░░░░░▄▄▄▄█▀█▄░░ ░░░░░▀██░░█▄▀▀██░░░░░░░░▄▄█░░▀▄░ ░░░░░░▀▀█▄░▀▄▄░▄░░░░░░░███▀░░▄██ ░░░░░░░░░▀▀▀███▀█▄░░░░░█▀░▀░░░▀█ ░░░░░░░░░░░░▄▀░░░▀█▄░░░░░▄▄░░▄█▀ ░░░▄▄▄▀▀▀▀▀█▀░░░░░█▄▀▄▄▄▄▄▄█▀▀░░ ░▄█░░░▄██▀░░░░░░░░░█▄░░░░░░░░░░░ █▀▀░▄█░░░░░░░░░░░░░░▀▀█▄░░░░░░░░ █░░░█░░░░░░░░░░░░░░░░░░█▄░░░░░░░ */ #include <bits/stdc++.h> using namespace std; #define pb push_back #define dbg(x) cout << #x << '=' << x << '\n'; #define ll long long #define x first #define y second #define pi pair<int, int> #define pii pair<pair<int, int>, int> #define vi vector<int> const ll mod = 1000000007; const ll nmax = 1000003; #define int ll int n, m, p, d[50001]; vi g1[2505]; vector<pi> g[50001]; vector<pii> edg; bool viz[2505], viz1[2505]; void dfs(int nod) { viz[nod] = 1; for (int i : g1[nod]) { if (!viz[i]) { dfs(i); } } } void dfs1(int nod) { viz1[nod] = 1; for (pi i : g[nod]) { if (!viz1[i.x]) { dfs1(i.x); } } } int32_t main() { ios_base ::sync_with_stdio(0); cin.tie(); cout.tie(); cin >> n >> m >> p; for (int i = 1, x, y, c; i <= m; i++) { cin >> x >> y >> c; g[x].pb({y, p - c}); g1[y].pb(x); // edg.pb({{x, y}, c}); } dfs(n); dfs1(1); // for(int i=1; i<=n; i++) cout<<viz[i]<<" "; vi prev; set<int> s; prev.pb(1); for (int i = 2; i <= n; i++) d[i] = 1e9; for (int i = 1; i <= n; i++) { for (int x : prev) { for (pi xd : g[x]) { int y = xd.x, c = xd.y, lol = d[y]; d[y] = min(d[y], d[x] + c); if (i == n && viz[y] && viz1[y] && lol != d[y]) return cout << -1, 0; if (lol != d[y]) s.insert(y); } } prev.clear(); for (int nod : s) prev.pb(nod); s.clear(); } cout << max(0LL, -d[n]); }
[ "control_flow.loop.for.condition.change", "expression.operation.binary.remove" ]
753,812
753,813
u392848063
cpp
p02949
#include <bits/stdc++.h> #define inf 1000000000 using namespace std; typedef long long ll; int n, m, a, b, c, p, d[2501], us[2501], from_st[2501]; vector<pair<pair<int, int>, int>> ed; vector<int> v[2501]; bool can = false; void _dfs(int x) { from_st[x] = 1; for (auto u : v[x]) if (!from_st[u]) _dfs(u); } void dfs(int x) { if (x == n - 1) can = true; return; us[x] = 1; for (auto u : v[x]) if (!us[u]) dfs(u); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> p; for (int i = 0; i < m; i++) { cin >> a >> b >> c; c -= p; a--; b--; ed.push_back({{a, b}, -c}); v[a].push_back(b); } for (int i = 1; i < n; i++) d[i] = inf; vector<int> was; for (int i = 0; i < n; i++) { was.clear(); for (int j = 0; j < m; j++) { if (d[ed[j].first.first] != inf && d[ed[j].first.first] + ed[j].second < d[ed[j].first.second]) { was.push_back(ed[j].first.second); d[ed[j].first.second] = d[ed[j].first.first] + ed[j].second; } } } _dfs(0); for (auto u : was) if (from_st[u] && !us[u]) dfs(u); if (can || d[n - 1] == inf) { cout << -1; return 0; } cout << max(0, -d[n - 1]); }
#include <bits/stdc++.h> #define inf 1000000000 using namespace std; typedef long long ll; int n, m, a, b, c, p, d[2501], us[2501], from_st[2501]; vector<pair<pair<int, int>, int>> ed; vector<int> v[2501]; bool can = false; void _dfs(int x) { from_st[x] = 1; for (auto u : v[x]) if (!from_st[u]) _dfs(u); } void dfs(int x) { if (x == n - 1) can = true; us[x] = 1; for (auto u : v[x]) if (!us[u]) dfs(u); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> p; for (int i = 0; i < m; i++) { cin >> a >> b >> c; c -= p; a--; b--; ed.push_back({{a, b}, -c}); v[a].push_back(b); } for (int i = 1; i < n; i++) d[i] = inf; vector<int> was; for (int i = 0; i < n; i++) { was.clear(); for (int j = 0; j < m; j++) { if (d[ed[j].first.first] != inf && d[ed[j].first.first] + ed[j].second < d[ed[j].first.second]) { was.push_back(ed[j].first.second); d[ed[j].first.second] = d[ed[j].first.first] + ed[j].second; } } } _dfs(0); for (auto u : was) if (from_st[u] && !us[u]) dfs(u); if (can || d[n - 1] == inf) { cout << -1; return 0; } cout << max(0, -d[n - 1]); }
[]
753,814
753,815
u299067843
cpp
p02949
#include <bits/stdc++.h> using namespace std; #define ll long long const ll inf = 1e18; const int N = 6000; ll d[N], e[N]; int a[N], b[N], c[N]; int n, m, p; int main() { // freopen("p.in","r",stdin); // freopen("p.out","w",stdout); cin >> n >> m >> p; for (int i = 1; i <= m; i++) { cin >> a[i] >> b[i] >> c[i]; c[i] = p - c[i]; } for (int i = 2; i <= n; i++) d[i] = e[i] = inf; for (int j = 1; j <= n - 1; j++) for (int i = 1; i <= m; i++) if (d[b[i]] > d[a[i]] + c[i] && d[a[i]] != inf) d[b[i]] = d[a[i]] + c[i]; e[1] = inf; e[n] = 0; for (int j = 1; j <= n - 1; j++) for (int i = 1; i <= m; i++) if (e[a[i]] > e[b[i]] + c[i] && e[a[i]] != inf) e[a[i]] = e[b[i]] + c[i]; for (int i = 1; i <= m; i++) if (d[a[i]] < inf && e[a[i]] < inf && d[b[i]] < inf && e[b[i]] < inf && d[b[i]] > d[a[i]] + c[i]) { printf("-1"); return 0; } ll ans = -1ll * d[n]; if (ans < 0ll) ans = 0ll; cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long const ll inf = 1e18; const int N = 6000; ll d[N], e[N]; int a[N], b[N], c[N]; int n, m, p; int main() { // freopen("p.in","r",stdin); // freopen("p.out","w",stdout); cin >> n >> m >> p; for (int i = 1; i <= m; i++) { cin >> a[i] >> b[i] >> c[i]; c[i] = p - c[i]; } for (int i = 2; i <= n; i++) d[i] = e[i] = inf; for (int j = 1; j <= n - 1; j++) for (int i = 1; i <= m; i++) if (d[b[i]] > d[a[i]] + c[i] && d[a[i]] != inf) d[b[i]] = d[a[i]] + c[i]; e[1] = inf; e[n] = 0; for (int j = 1; j <= n - 1; j++) for (int i = 1; i <= m; i++) if (e[a[i]] > e[b[i]] + c[i] && e[b[i]] != inf) e[a[i]] = e[b[i]] + c[i]; for (int i = 1; i <= m; i++) if (d[a[i]] < inf && e[a[i]] < inf && d[b[i]] < inf && e[b[i]] < inf && d[b[i]] > d[a[i]] + c[i]) { printf("-1"); return 0; } ll ans = -1 * d[n]; if (ans < 0) ans = 0; cout << ans; return 0; }
[ "identifier.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
753,816
753,817
u405338557
cpp
p02949
#include <bits/stdc++.h> using namespace std; #define ll long long const ll inf = 1e18; const int N = 6000; ll d[N], e[N]; int a[N], b[N], c[N]; int n, m, p; int main() { // freopen("p.in","r",stdin); // freopen("p.out","w",stdout); cin >> n >> m >> p; for (int i = 1; i <= m; i++) { cin >> a[i] >> b[i] >> c[i]; c[i] = p - c[i]; } for (int i = 2; i <= n; i++) d[i] = e[i] = inf; for (int j = 1; j <= n; j++) for (int i = 1; i <= m; i++) if (d[b[i]] > d[a[i]] + c[i] && d[a[i]] != inf) d[b[i]] = d[a[i]] + c[i]; e[1] = inf; e[n] = 0; for (int j = 1; j <= n; j++) for (int i = 1; i <= m; i++) if (e[a[i]] > e[b[i]] + c[i] && e[a[i]] != inf) e[a[i]] = e[b[i]] + c[i]; for (int i = 1; i <= m; i++) if (d[a[i]] < inf && e[a[i]] < inf && d[b[i]] < inf && e[b[i]] < inf && d[b[i]] > d[a[i]] + c[i]) { printf("-1"); return 0; } ll ans = -1ll * d[n]; if (ans < 0) ans = 0; cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long const ll inf = 1e18; const int N = 6000; ll d[N], e[N]; int a[N], b[N], c[N]; int n, m, p; int main() { // freopen("p.in","r",stdin); // freopen("p.out","w",stdout); cin >> n >> m >> p; for (int i = 1; i <= m; i++) { cin >> a[i] >> b[i] >> c[i]; c[i] = p - c[i]; } for (int i = 2; i <= n; i++) d[i] = e[i] = inf; for (int j = 1; j <= n - 1; j++) for (int i = 1; i <= m; i++) if (d[b[i]] > d[a[i]] + c[i] && d[a[i]] != inf) d[b[i]] = d[a[i]] + c[i]; e[1] = inf; e[n] = 0; for (int j = 1; j <= n - 1; j++) for (int i = 1; i <= m; i++) if (e[a[i]] > e[b[i]] + c[i] && e[b[i]] != inf) e[a[i]] = e[b[i]] + c[i]; for (int i = 1; i <= m; i++) if (d[a[i]] < inf && e[a[i]] < inf && d[b[i]] < inf && e[b[i]] < inf && d[b[i]] > d[a[i]] + c[i]) { printf("-1"); return 0; } ll ans = -1 * d[n]; if (ans < 0) ans = 0; cout << ans; return 0; }
[ "control_flow.loop.for.condition.change", "misc.off_by_one", "identifier.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
753,818
753,817
u405338557
cpp
p02949
#include <bits/stdc++.h> using namespace std; #define ll long long const ll inf = 1e18; const int N = 6000; ll d[N], e[N]; int a[N], b[N], c[N]; int n, m, p; int main() { // freopen("p.in","r",stdin); // freopen("p.out","w",stdout); cin >> n >> m >> p; for (int i = 1; i <= m; i++) { cin >> a[i] >> b[i] >> c[i]; c[i] = p - c[i]; } for (int i = 2; i <= n; i++) d[i] = e[i] = inf; for (int j = 1; j <= n - 1; j++) for (int i = 1; i <= m; i++) if (d[b[i]] > d[a[i]] + c[i] && d[a[i]] != inf) d[b[i]] = d[a[i]] + c[i]; e[1] = inf; e[n] = 0; for (int j = 1; j <= n - 1; j++) for (int i = 1; i <= m; i++) if (e[a[i]] > e[b[i]] + c[i] && e[a[i]] != inf) e[a[i]] = e[b[i]] + c[i]; for (int i = 1; i <= m; i++) if (d[a[i]] < inf && e[a[i]] < inf && d[b[i]] < inf && e[b[i]] < inf && d[b[i]] > d[a[i]] + c[i]) { printf("-1"); return 0; } ll ans = -1ll * d[n]; if (ans < 0) ans = 0; cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long const ll inf = 1e18; const int N = 6000; ll d[N], e[N]; int a[N], b[N], c[N]; int n, m, p; int main() { // freopen("p.in","r",stdin); // freopen("p.out","w",stdout); cin >> n >> m >> p; for (int i = 1; i <= m; i++) { cin >> a[i] >> b[i] >> c[i]; c[i] = p - c[i]; } for (int i = 2; i <= n; i++) d[i] = e[i] = inf; for (int j = 1; j <= n - 1; j++) for (int i = 1; i <= m; i++) if (d[b[i]] > d[a[i]] + c[i] && d[a[i]] != inf) d[b[i]] = d[a[i]] + c[i]; e[1] = inf; e[n] = 0; for (int j = 1; j <= n - 1; j++) for (int i = 1; i <= m; i++) if (e[a[i]] > e[b[i]] + c[i] && e[b[i]] != inf) e[a[i]] = e[b[i]] + c[i]; for (int i = 1; i <= m; i++) if (d[a[i]] < inf && e[a[i]] < inf && d[b[i]] < inf && e[b[i]] < inf && d[b[i]] > d[a[i]] + c[i]) { printf("-1"); return 0; } ll ans = -1 * d[n]; if (ans < 0) ans = 0; cout << ans; return 0; }
[ "identifier.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
753,819
753,817
u405338557
cpp
p02949
#include <bits/stdc++.h> using namespace std; #define ll long long const ll inf = 1e18; const int N = 6000; ll d[N], e[N]; int a[N], b[N], c[N]; int n, m, p; int main() { // freopen("p.in","r",stdin); // freopen("p.out","w",stdout); cin >> n >> m >> p; for (int i = 1; i <= m; i++) { cin >> a[i] >> b[i] >> c[i]; c[i] = p - c[i]; } for (int i = 2; i <= n; i++) d[i] = e[i] = inf; for (int j = 1; j <= n - 1; j++) for (int i = 1; i <= m; i++) if (d[b[i]] > d[a[i]] + c[i] && d[a[i]] != inf) d[b[i]] = d[a[i]] + c[i]; e[1] = inf; e[n] = 0; for (int j = 1; j <= n - 1; j++) for (int i = 1; i <= m; i++) if (e[a[i]] > e[b[i]] + c[i] && e[a[i]] != inf) e[a[i]] = e[b[i]] + c[i]; for (int i = 1; i <= m; i++) if (d[a[i]] < inf && e[a[i]] < inf && d[b[i]] < inf && e[b[i]] < inf && d[b[i]] > d[a[i]] + c[i]) { printf("-1"); return 0; } ll ans = -1 * d[n]; if (ans < 0) ans = 0; cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long const ll inf = 1e18; const int N = 6000; ll d[N], e[N]; int a[N], b[N], c[N]; int n, m, p; int main() { // freopen("p.in","r",stdin); // freopen("p.out","w",stdout); cin >> n >> m >> p; for (int i = 1; i <= m; i++) { cin >> a[i] >> b[i] >> c[i]; c[i] = p - c[i]; } for (int i = 2; i <= n; i++) d[i] = e[i] = inf; for (int j = 1; j <= n - 1; j++) for (int i = 1; i <= m; i++) if (d[b[i]] > d[a[i]] + c[i] && d[a[i]] != inf) d[b[i]] = d[a[i]] + c[i]; e[1] = inf; e[n] = 0; for (int j = 1; j <= n - 1; j++) for (int i = 1; i <= m; i++) if (e[a[i]] > e[b[i]] + c[i] && e[b[i]] != inf) e[a[i]] = e[b[i]] + c[i]; for (int i = 1; i <= m; i++) if (d[a[i]] < inf && e[a[i]] < inf && d[b[i]] < inf && e[b[i]] < inf && d[b[i]] > d[a[i]] + c[i]) { printf("-1"); return 0; } ll ans = -1 * d[n]; if (ans < 0) ans = 0; cout << ans; return 0; }
[ "identifier.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
753,820
753,817
u405338557
cpp
p02949
#include <bits/stdc++.h> using namespace std; #define sz(a) int(a.size()) bool vis[2510]; vector<int> adj[2510]; void dfs(int u) { vis[u] = 1; for (int v : adj[u]) { if (!vis[v]) dfs(v); } } int main() { int n, m, p; cin >> n >> m >> p; vector<tuple<int, int, int>> edges; for (int i = 0; i < m; i++) { int u, v, w; cin >> u >> v >> w; u--, v--; edges.emplace_back(u, v, w); adj[v].push_back(u); } dfs(n - 1); const int INF = 1 << 30; vector<int> D(n, INF); D[0] = 0; for (int i = 1; i < n; i++) { for (auto t : edges) { int u = get<0>(t), v = get<1>(t), w = get<2>(t); int cost = D[u] != INF ? D[u] + p - w : INF; if (D[v] > cost) D[v] = cost; } } for (auto t : edges) { int u = get<0>(t), v = get<1>(t), w = get<2>(t); int cost = D[u] != INF ? D[u] + p - w : INF; if (D[v] > cost) { puts("-1"); return 0; } if (D[v] > cost) D[v] = cost; } cout << max(0, -D[n - 1]) << endl; }
#include <bits/stdc++.h> using namespace std; #define sz(a) int(a.size()) bool vis[2510]; vector<int> adj[2510]; void dfs(int u) { vis[u] = 1; for (int v : adj[u]) { if (!vis[v]) dfs(v); } } int main() { int n, m, p; cin >> n >> m >> p; vector<tuple<int, int, int>> edges; for (int i = 0; i < m; i++) { int u, v, w; cin >> u >> v >> w; u--, v--; edges.emplace_back(u, v, w); adj[v].push_back(u); } dfs(n - 1); const int INF = 1 << 30; vector<int> D(n, INF); D[0] = 0; for (int i = 1; i < n; i++) { for (auto t : edges) { int u = get<0>(t), v = get<1>(t), w = get<2>(t); int cost = D[u] != INF ? D[u] + p - w : INF; if (D[v] > cost) D[v] = cost; } } for (auto t : edges) { int u = get<0>(t), v = get<1>(t), w = get<2>(t); int cost = D[u] != INF ? D[u] + p - w : INF; if (vis[v] && D[v] > cost) { puts("-1"); return 0; } if (D[v] > cost) D[v] = cost; } cout << max(0, -D[n - 1]) << endl; }
[ "control_flow.branch.if.condition.change" ]
753,823
753,824
u110193617
cpp
p02949
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; vector<int> nodeByA[2500]; vector<int> nodeByB[2500]; bool reachableByA[2500]; bool reachableByB[2500]; bool reachable[2500]; void dfsByA(int n) { if (reachableByA[n]) { return; } reachableByA[n] = true; for (int a : nodeByA[n]) { dfsByA(a); } } void dfsByB(int n) { if (reachableByB[n]) { return; } reachableByB[n] = true; for (int b : nodeByB[n]) { dfsByB(b); } } int main() { int N, M, P; cin >> N >> M >> P; vector<tuple<int, int, int>> edges; rep(i, M) { int A, B, C; cin >> A >> B >> C; A -= 1; B -= 1; C = -1 * (C - P); nodeByA[A].push_back(B); nodeByB[B].push_back(A); edges.emplace_back(A, B, C); } dfsByA(0); dfsByB(N - 1); rep(i, N) { reachable[i] = reachableByA[i] && reachableByB[i]; } vector<int> d(N, INT_MAX); d[0] = 0; bool update = true; int count = 0; while (update) { update = false; rep(i, M) { int a, b, c; tie(a, b, c) = edges[i]; if (!(reachable[a] && reachable[b])) { continue; } int newD = d[a] + c; if (newD < d[b]) { d[b] = newD; update = true; } } count++; if (count > N) { cout << "-1" << endl; return 0; } } cout << max(-d[N - 1], 0) << 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> nodeByA[2500]; vector<int> nodeByB[2500]; bool reachableByA[2500]; bool reachableByB[2500]; bool reachable[2500]; void dfsByA(int n) { if (reachableByA[n]) { return; } reachableByA[n] = true; for (int a : nodeByA[n]) { dfsByA(a); } } void dfsByB(int n) { if (reachableByB[n]) { return; } reachableByB[n] = true; for (int b : nodeByB[n]) { dfsByB(b); } } int main() { int N, M, P; cin >> N >> M >> P; vector<tuple<int, int, int>> edges; rep(i, M) { int A, B, C; cin >> A >> B >> C; A -= 1; B -= 1; C = -1 * (C - P); nodeByA[A].push_back(B); nodeByB[B].push_back(A); edges.emplace_back(A, B, C); } dfsByA(0); dfsByB(N - 1); rep(i, N) { reachable[i] = reachableByA[i] && reachableByB[i]; } // const int INF = 1001001001; vector<int> d(N, 1001001001); d[0] = 0; bool update = true; int count = 0; while (update) { update = false; rep(i, M) { int a, b, c; tie(a, b, c) = edges[i]; if (!(reachable[a] && reachable[b])) { continue; } int newD = d[a] + c; if (newD < d[b]) { d[b] = newD; update = true; } } count++; if (count > N) { cout << "-1" << endl; return 0; } } cout << max(-d[N - 1], 0) << endl; return 0; }
[]
753,827
753,828
u814154745
cpp
p02949
// #define _GLIBCXX_DEBUG // for STL debug (optional) #include <algorithm> #include <bitset> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long int; using int64 = long long int; template <typename T> void chmax(T &a, T b) { a = max(a, b); } template <typename T> void chmin(T &a, T b) { a = min(a, b); } template <typename T> void chadd(T &a, T b) { a = a + b; } int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; const ll INF = 1LL << 60; const ll MOD = 1000000007LL; int main() { ll N, M, P; cin >> N >> M >> P; vector<vector<pair<ll, ll>>> G(N); vector<ll> dist(N, INF); for (int i = 0; i < M; i++) { ll a, b, c; cin >> a >> b >> c; a--; b--; G[a].emplace_back(b, P - c); } dist[0] = 0; ll rec1, rec2; for (int i = 0; i < 2 * N; i++) { for (int j = 0; j < N; j++) { for (auto e : G[j]) { ll k, c; tie(k, c) = e; if (dist[j] != INF and dist[k] > dist[j] + c) { dist[k] = dist[j] + c; } } } if (i == N - 1) rec1 = dist[N - 1]; if (i == 2 * N - 1) rec2 = dist[N - 1]; } if (rec1 != rec2) cout << -1 << endl; else cout << -rec1 << endl; return 0; }
// #define _GLIBCXX_DEBUG // for STL debug (optional) #include <algorithm> #include <bitset> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long int; using int64 = long long int; template <typename T> void chmax(T &a, T b) { a = max(a, b); } template <typename T> void chmin(T &a, T b) { a = min(a, b); } template <typename T> void chadd(T &a, T b) { a = a + b; } int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; const ll INF = 1LL << 60; const ll MOD = 1000000007LL; int main() { ll N, M, P; cin >> N >> M >> P; vector<vector<pair<ll, ll>>> G(N); vector<ll> dist(N, INF); for (int i = 0; i < M; i++) { ll a, b, c; cin >> a >> b >> c; a--; b--; G[a].emplace_back(b, P - c); } dist[0] = 0; ll rec1, rec2; for (int i = 0; i < 2 * N; i++) { for (int j = 0; j < N; j++) { for (auto e : G[j]) { ll k, c; tie(k, c) = e; if (dist[j] != INF and dist[k] > dist[j] + c) { dist[k] = dist[j] + c; } } } if (i == N - 1) rec1 = dist[N - 1]; if (i == 2 * N - 1) rec2 = dist[N - 1]; } if (rec1 != rec2) cout << -1 << endl; else cout << max(0LL, -rec1) << endl; return 0; }
[ "call.add", "call.arguments.change" ]
753,836
753,837
u119460590
cpp
p02949
#include <algorithm> #include <array> #include <bitset> #include <cmath> #include <functional> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; using ll = int64_t; ll const MM = 1000000007; #define pv(val) cerr << #val << '=' << (val) << endl #define pl cerr << '@' << __LINE__ << endl #define rep(i, n) for (ll i = 0; i < (n); i++) #define rep2(i, b, e) for (ll i = (b); i < (e); i++) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() template <class T> ostream &operator<<(ostream &os, vector<T> const &vec); template <class T, size_t S> ostream &operator<<(ostream &os, array<T, S> const &arr); template <class T, class U> ostream &operator<<(ostream &os, pair<T, U> const &p); template <class... Args> ostream &operator<<(ostream &os, tuple<Args...> const &t); template <class T> ostream &operator<<(ostream &os, vector<T> const &vec) { if (vec.empty()) { os << "{}"; } else { os << '{'; for (size_t i = 0; i < vec.size() - 1; i++) os << vec[i] << ", "; os << vec.back() << '}'; } return os; } template <class T, size_t S> ostream &operator<<(ostream &os, array<T, S> const &arr) { if (arr.empty()) { os << "{}"; } else { os << '{'; for (size_t i = 0; i < arr.size() - 1; i++) os << arr[i] << ", "; os << arr.back() << '}'; } return os; } template <class T, class U> ostream &operator<<(ostream &os, pair<T, U> const &p) { os << '(' << p.first << ", " << p.second << ')'; return os; } template <size_t I, class... Args> typename enable_if<sizeof...(Args) == (I + 1)>::type print_tuple(ostream &os, tuple<Args...> const &t) { os << get<I>(t); } template <size_t I, class... Args> typename enable_if<sizeof...(Args) != (I + 1)>::type print_tuple(ostream &os, tuple<Args...> const &t) { os << get<I>(t) << ", "; print_tuple<I + 1, Args...>(os, t); } template <class... Args> ostream &operator<<(ostream &os, tuple<Args...> const &t) { os << '('; print_tuple<0, Args...>(os, t); os << ')'; return os; } namespace math { ll gcd(ll u, ll v) { while (v != 0) { ll r = u % v; u = v; v = r; } return u; } ll lcm(ll m, ll n) { if ((0 == m) || (0 == n)) return 0; return ((m / math::gcd(m, n)) * n); } vector<ll> divisor(ll n) { vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return ret; } set<ll> divisor_set(ll n) { set<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.insert(i); if (i * i != n) ret.insert(n / i); } } return ret; } // https://qiita.com/ofutonfuton/items/92b1a6f4a7775f00b6ae struct Combination { vector<ll> fac; vector<ll> ifac; Combination() : fac(300001), ifac(300001) { fac[0] = 1; ifac[0] = 1; for (ll i = 0; i < 300000; i++) { fac[i + 1] = fac[i] * (i + 1) % MM; ifac[i + 1] = ifac[i] * this->mpow(i + 1, MM - 2) % MM; } } static ll mpow(ll x, ll n) { ll ans = 1; while (n != 0) { if (n & 1) ans = ans * x % MM; x = x * x % MM; n = n >> 1; } return ans; } ll operator()(ll a, ll b) const { return this->comb(a, b); } ll comb(ll a, ll b) const { if (a == 0 && b == 0) return 1; if (a < b || a < 0 || b < 0) return 0; ll const tmp = ifac[a - b] * ifac[b] % MM; return tmp * fac[a] % MM; } } comb; } // namespace math struct UnionFind { vector<ll> data; UnionFind(ll size) : data(size, -1) {} bool unionSet(ll x, ll y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool findSet(ll x, ll y) { return root(x) == root(y); } ll root(ll x) { return data[x] < 0 ? x : data[x] = root(data[x]); } ll size(ll x) { return -data[root(x)]; } }; ll bound(function<bool(ll)> f, ll ng, ll ok) { while (abs(ng - ok) > 1) { ll mid = (ng + ok) / 2; if (f(mid)) ok = mid; else ng = mid; } return ok; } int main(void) { ll N, M, P; cin >> N >> M >> P; vector<tuple<ll, ll, ll>> e(M); vector<vector<ll>> adj(M), radj(M); rep(j, M) { ll A, B, C; cin >> A >> B >> C; A--, B--; e[j] = {A, B, -C + P}; adj[A].push_back(B); radj[B].push_back(A); } ll const inf = 0.1 * numeric_limits<ll>::max(); vector<ll> l(N, inf); l[0] = 0; vector<bool> r(N, false); vector<bool> r2(N, false); vector<ll> stk; stk.push_back(0); vector<bool> visited(N, false); while (!stk.empty()) { ll const t = stk.back(); stk.pop_back(); if (visited[t]) continue; visited[t] = true; r[t] = true; for (ll const v : adj[t]) stk.push_back(v); } stk.push_back(N - 1); fill(all(visited), false); while (!stk.empty()) { ll const t = stk.back(); stk.pop_back(); if (visited[t]) continue; visited[t] = true; r2[t] = true; for (ll const v : radj[t]) stk.push_back(v); } rep(i, N) r[i] = r[i] && r2[i]; rep(i, N) rep(j, M) { ll A, B, W; tie(A, B, W) = e[j]; if (!r[A] || !r[B]) continue; l[B] = min(l[B], l[A] + W); } bool neg = false; rep(j, M) { ll A, B, W; tie(A, B, W) = e[j]; if (!r[A] || !r[B]) continue; if (l[A] + W < l[B]) neg = true; } if (neg) { cout << -1 << endl; } else { cout << max((ll)(0), -l[N - 1]) << endl; } return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cmath> #include <functional> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; using ll = int64_t; ll const MM = 1000000007; #define pv(val) cerr << #val << '=' << (val) << endl #define pl cerr << '@' << __LINE__ << endl #define rep(i, n) for (ll i = 0; i < (n); i++) #define rep2(i, b, e) for (ll i = (b); i < (e); i++) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() template <class T> ostream &operator<<(ostream &os, vector<T> const &vec); template <class T, size_t S> ostream &operator<<(ostream &os, array<T, S> const &arr); template <class T, class U> ostream &operator<<(ostream &os, pair<T, U> const &p); template <class... Args> ostream &operator<<(ostream &os, tuple<Args...> const &t); template <class T> ostream &operator<<(ostream &os, vector<T> const &vec) { if (vec.empty()) { os << "{}"; } else { os << '{'; for (size_t i = 0; i < vec.size() - 1; i++) os << vec[i] << ", "; os << vec.back() << '}'; } return os; } template <class T, size_t S> ostream &operator<<(ostream &os, array<T, S> const &arr) { if (arr.empty()) { os << "{}"; } else { os << '{'; for (size_t i = 0; i < arr.size() - 1; i++) os << arr[i] << ", "; os << arr.back() << '}'; } return os; } template <class T, class U> ostream &operator<<(ostream &os, pair<T, U> const &p) { os << '(' << p.first << ", " << p.second << ')'; return os; } template <size_t I, class... Args> typename enable_if<sizeof...(Args) == (I + 1)>::type print_tuple(ostream &os, tuple<Args...> const &t) { os << get<I>(t); } template <size_t I, class... Args> typename enable_if<sizeof...(Args) != (I + 1)>::type print_tuple(ostream &os, tuple<Args...> const &t) { os << get<I>(t) << ", "; print_tuple<I + 1, Args...>(os, t); } template <class... Args> ostream &operator<<(ostream &os, tuple<Args...> const &t) { os << '('; print_tuple<0, Args...>(os, t); os << ')'; return os; } namespace math { ll gcd(ll u, ll v) { while (v != 0) { ll r = u % v; u = v; v = r; } return u; } ll lcm(ll m, ll n) { if ((0 == m) || (0 == n)) return 0; return ((m / math::gcd(m, n)) * n); } vector<ll> divisor(ll n) { vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return ret; } set<ll> divisor_set(ll n) { set<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.insert(i); if (i * i != n) ret.insert(n / i); } } return ret; } // https://qiita.com/ofutonfuton/items/92b1a6f4a7775f00b6ae struct Combination { vector<ll> fac; vector<ll> ifac; Combination() : fac(300001), ifac(300001) { fac[0] = 1; ifac[0] = 1; for (ll i = 0; i < 300000; i++) { fac[i + 1] = fac[i] * (i + 1) % MM; ifac[i + 1] = ifac[i] * this->mpow(i + 1, MM - 2) % MM; } } static ll mpow(ll x, ll n) { ll ans = 1; while (n != 0) { if (n & 1) ans = ans * x % MM; x = x * x % MM; n = n >> 1; } return ans; } ll operator()(ll a, ll b) const { return this->comb(a, b); } ll comb(ll a, ll b) const { if (a == 0 && b == 0) return 1; if (a < b || a < 0 || b < 0) return 0; ll const tmp = ifac[a - b] * ifac[b] % MM; return tmp * fac[a] % MM; } } comb; } // namespace math struct UnionFind { vector<ll> data; UnionFind(ll size) : data(size, -1) {} bool unionSet(ll x, ll y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool findSet(ll x, ll y) { return root(x) == root(y); } ll root(ll x) { return data[x] < 0 ? x : data[x] = root(data[x]); } ll size(ll x) { return -data[root(x)]; } }; ll bound(function<bool(ll)> f, ll ng, ll ok) { while (abs(ng - ok) > 1) { ll mid = (ng + ok) / 2; if (f(mid)) ok = mid; else ng = mid; } return ok; } int main(void) { ll N, M, P; cin >> N >> M >> P; vector<tuple<ll, ll, ll>> e(M); vector<vector<ll>> adj(N), radj(N); rep(j, M) { ll A, B, C; cin >> A >> B >> C; A--, B--; e[j] = {A, B, -C + P}; adj[A].push_back(B); radj[B].push_back(A); } ll const inf = 0.1 * numeric_limits<ll>::max(); vector<ll> l(N, inf); l[0] = 0; vector<bool> r(N, false); vector<bool> r2(N, false); vector<ll> stk; stk.push_back(0); vector<bool> visited(N, false); while (!stk.empty()) { ll const t = stk.back(); stk.pop_back(); if (visited[t]) continue; visited[t] = true; r[t] = true; for (ll const v : adj[t]) stk.push_back(v); } stk.push_back(N - 1); fill(all(visited), false); while (!stk.empty()) { ll const t = stk.back(); stk.pop_back(); if (visited[t]) continue; visited[t] = true; r2[t] = true; for (ll const v : radj[t]) stk.push_back(v); } rep(i, N) r[i] = r[i] && r2[i]; rep(i, N) rep(j, M) { ll A, B, W; tie(A, B, W) = e[j]; if (!r[A] || !r[B]) continue; l[B] = min(l[B], l[A] + W); } bool neg = false; rep(j, M) { ll A, B, W; tie(A, B, W) = e[j]; if (!r[A] || !r[B]) continue; if (l[A] + W < l[B]) neg = true; } if (neg) { cout << -1 << endl; } else { cout << max((ll)(0), -l[N - 1]) << endl; } return 0; }
[]
753,840
753,841
u967620300
cpp
p02949
#include <bits/stdc++.h> #include <functional> #include <iomanip> using namespace std; #define int long long #define pb push_back #define ub upper_bound #define lb upper_bound #define mp make_pair #define F first #define S second #define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define REP(i, n) FOR(i, 0, n) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define SORT(c) sort((c).begin(), (c).end()) #define ve vector #define vi vector<int> #define vp vector<pair<int, int>> #define vvi vector<vector<int>> using ll = long long; ll INF = LLONG_MAX / 4 - 100; ll mod = 1e9 + 7; int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1}; vector<ll> prime; class fact { public: int fmod = 1e9 + 7; vector<int> fac, inv; fact(int n, int Mod = 1e9 + 7) { fmod = Mod; fac = vector<int>(n, 0); inv = vector<int>(n, 0); fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i - 1] * i % fmod; for (int i = 0; i < n; i++) inv[i] = fact::POW(fac[i], fmod - 2); } ll nCr(ll n, ll r) { return (fac[n] * inv[r] % fmod) * inv[n - r] % fmod; } ll POW(ll a, ll b) { ll c = 1; while (b > 0) { if (b & 1) { c = a * c % fmod; } a = a * a % fmod; b >>= 1; } return c; } }; template <class T = ll> T in() { T x; cin >> x; return (x); } void DEBUG(vector<int> a) { for (int i = 0; i < a.size(); i++) cout << a[i] << " "; cout << endl; } void EMP(int x) { cout << "!!!" << x << "!!!" << endl; } ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; } return a; } ll LCM(ll a, ll b) { return a * b / GCD(a, b); } ll POW(ll a, ll b) { ll c = 1; while (b > 0) { if (b & 1) { c = a * c % mod; } a = a * a % mod; b >>= 1; } return c; } void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; } for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } } template <typename T> T chmin(T &a, T b) { if (a > b) a = b; return a; } template <typename T> T chmax(T &a, T b) { if (a < b) a = b; return b; } bool isSqrt(ll a) { return pow(sqrt(a), 2) == a ? 1 : 0; } void YesNo(bool a) { if (a) cout << "Yes"; else cout << "No"; cout << endl; } void yesno(bool a) { if (a) cout << "yes"; else cout << "no"; cout << endl; } void YESNO(bool a) { if (a) cout << "YES"; else cout << "NO"; cout << endl; } double dis(int x1, int x2, int y1, int y2) { return sqrt((double)abs(x1 - x2) * (double)abs(x1 - x2) + (double)abs(y1 - y2) * (double)abs(y1 - y2)); } int cost[2550][2550]; int poin[2550]; typedef struct { int from; int to; int cost; } Edge; class BellemanFord { public: vector<Edge> edge; vector<ll> dist; bool bellemanford(int v, int s) { dist = vector<ll>(v, INF); dist[s] = 0; for (int i = 0; i < v * 3; i++) { for (int j = 0; j < edge.size(); j++) { if (dist[edge[j].from] + edge[j].cost < dist[edge[j].to]) { if (dist[v - 1] < -INF / 2) return true; dist[edge[j].to] = dist[edge[j].from] + edge[j].cost; if (i == 3 * v - 1 && edge[j].to == v - 1) return true; } } } return false; } }; bool solve() { // REP (i,2550) REP (j,2550) cost[i][j] = INF; BellemanFord bf; // int n,m; cin >> n >> m; // vector<pair<int,int>> ab(n); // REP (i,n) cin >> ab[i].F >> ab[i].S; // set<pair<int,int>> get; // REP (i,n) get.insert(ab[i].S); // sort(all(ab)); reverse(all(ab)); // int day = 0; // int ans = 0; // bool rem[n]; REP (i,n) rem[i] = true; // int now = 0; // REP (i,m+1) { // while(m-ab[now].F < i) get.erase(ab[now].S),now++; // if (get.size() == 0) break; // ans += *get.rbegin(); // int tmp = *get.rbegin(); // cout << tmp << endl; // get.erase(tmp); // } // cout << ans << endl; int n, m, p; cin >> n >> m >> p; REP(i, m) { int a, b, c; cin >> a >> b >> c; bf.edge.pb({--a, --b, -(c - p)}); } if (bf.bellemanford(n, 0)) { cout << -1 << endl; } else { cout << max(-bf.dist[n - 1], 0ll) << endl; } } signed main() { cin.tie(0); ios::sync_with_stdio(false); solve(); }
#include <bits/stdc++.h> #include <functional> #include <iomanip> using namespace std; #define int long long #define pb push_back #define ub upper_bound #define lb upper_bound #define mp make_pair #define F first #define S second #define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define REP(i, n) FOR(i, 0, n) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define SORT(c) sort((c).begin(), (c).end()) #define ve vector #define vi vector<int> #define vp vector<pair<int, int>> #define vvi vector<vector<int>> using ll = long long; ll INF = LLONG_MAX / 4 - 100; ll mod = 1e9 + 7; int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1}; vector<ll> prime; class fact { public: int fmod = 1e9 + 7; vector<int> fac, inv; fact(int n, int Mod = 1e9 + 7) { fmod = Mod; fac = vector<int>(n, 0); inv = vector<int>(n, 0); fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i - 1] * i % fmod; for (int i = 0; i < n; i++) inv[i] = fact::POW(fac[i], fmod - 2); } ll nCr(ll n, ll r) { return (fac[n] * inv[r] % fmod) * inv[n - r] % fmod; } ll POW(ll a, ll b) { ll c = 1; while (b > 0) { if (b & 1) { c = a * c % fmod; } a = a * a % fmod; b >>= 1; } return c; } }; template <class T = ll> T in() { T x; cin >> x; return (x); } void DEBUG(vector<int> a) { for (int i = 0; i < a.size(); i++) cout << a[i] << " "; cout << endl; } void EMP(int x) { cout << "!!!" << x << "!!!" << endl; } ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; } return a; } ll LCM(ll a, ll b) { return a * b / GCD(a, b); } ll POW(ll a, ll b) { ll c = 1; while (b > 0) { if (b & 1) { c = a * c % mod; } a = a * a % mod; b >>= 1; } return c; } void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; } for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } } template <typename T> T chmin(T &a, T b) { if (a > b) a = b; return a; } template <typename T> T chmax(T &a, T b) { if (a < b) a = b; return b; } bool isSqrt(ll a) { return pow(sqrt(a), 2) == a ? 1 : 0; } void YesNo(bool a) { if (a) cout << "Yes"; else cout << "No"; cout << endl; } void yesno(bool a) { if (a) cout << "yes"; else cout << "no"; cout << endl; } void YESNO(bool a) { if (a) cout << "YES"; else cout << "NO"; cout << endl; } double dis(int x1, int x2, int y1, int y2) { return sqrt((double)abs(x1 - x2) * (double)abs(x1 - x2) + (double)abs(y1 - y2) * (double)abs(y1 - y2)); } int cost[2550][2550]; int poin[2550]; typedef struct { int from; int to; int cost; } Edge; class BellemanFord { public: vector<Edge> edge; vector<ll> dist; bool bellemanford(int v, int s) { dist = vector<ll>(v, INF); dist[s] = 0; for (int i = 0; i < v * 3; i++) { for (int j = 0; j < edge.size(); j++) { if (dist[edge[j].from] + edge[j].cost < dist[edge[j].to]) { if (dist[v - 1] < -INF / 2) return true; dist[edge[j].to] = dist[edge[j].from] + edge[j].cost; if (i >= v - 1 && edge[j].to == v - 1) return true; } } } return false; } }; bool solve() { // REP (i,2550) REP (j,2550) cost[i][j] = INF; BellemanFord bf; // int n,m; cin >> n >> m; // vector<pair<int,int>> ab(n); // REP (i,n) cin >> ab[i].F >> ab[i].S; // set<pair<int,int>> get; // REP (i,n) get.insert(ab[i].S); // sort(all(ab)); reverse(all(ab)); // int day = 0; // int ans = 0; // bool rem[n]; REP (i,n) rem[i] = true; // int now = 0; // REP (i,m+1) { // while(m-ab[now].F < i) get.erase(ab[now].S),now++; // if (get.size() == 0) break; // ans += *get.rbegin(); // int tmp = *get.rbegin(); // cout << tmp << endl; // get.erase(tmp); // } // cout << ans << endl; int n, m, p; cin >> n >> m >> p; REP(i, m) { int a, b, c; cin >> a >> b >> c; bf.edge.pb({--a, --b, -(c - p)}); } if (bf.bellemanford(n, 0)) { cout << -1 << endl; } else { cout << max(-bf.dist[n - 1], 0ll) << endl; } } signed main() { cin.tie(0); ios::sync_with_stdio(false); solve(); }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change", "expression.operation.binary.remove" ]
753,842
753,843
u764234894
cpp
p02949
#include <bits/stdc++.h> #include <functional> #include <iomanip> using namespace std; #define int long long #define pb push_back #define ub upper_bound #define lb upper_bound #define mp make_pair #define F first #define S second #define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define REP(i, n) FOR(i, 0, n) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define SORT(c) sort((c).begin(), (c).end()) #define ve vector #define vi vector<int> #define vp vector<pair<int, int>> #define vvi vector<vector<int>> using ll = long long; ll INF = LLONG_MAX / 4 - 100; ll mod = 1e9 + 7; int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1}; vector<ll> prime; class fact { public: int fmod = 1e9 + 7; vector<int> fac, inv; fact(int n, int Mod = 1e9 + 7) { fmod = Mod; fac = vector<int>(n, 0); inv = vector<int>(n, 0); fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i - 1] * i % fmod; for (int i = 0; i < n; i++) inv[i] = fact::POW(fac[i], fmod - 2); } ll nCr(ll n, ll r) { return (fac[n] * inv[r] % fmod) * inv[n - r] % fmod; } ll POW(ll a, ll b) { ll c = 1; while (b > 0) { if (b & 1) { c = a * c % fmod; } a = a * a % fmod; b >>= 1; } return c; } }; template <class T = ll> T in() { T x; cin >> x; return (x); } void DEBUG(vector<int> a) { for (int i = 0; i < a.size(); i++) cout << a[i] << " "; cout << endl; } void EMP(int x) { cout << "!!!" << x << "!!!" << endl; } ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; } return a; } ll LCM(ll a, ll b) { return a * b / GCD(a, b); } ll POW(ll a, ll b) { ll c = 1; while (b > 0) { if (b & 1) { c = a * c % mod; } a = a * a % mod; b >>= 1; } return c; } void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; } for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } } template <typename T> T chmin(T &a, T b) { if (a > b) a = b; return a; } template <typename T> T chmax(T &a, T b) { if (a < b) a = b; return b; } bool isSqrt(ll a) { return pow(sqrt(a), 2) == a ? 1 : 0; } void YesNo(bool a) { if (a) cout << "Yes"; else cout << "No"; cout << endl; } void yesno(bool a) { if (a) cout << "yes"; else cout << "no"; cout << endl; } void YESNO(bool a) { if (a) cout << "YES"; else cout << "NO"; cout << endl; } double dis(int x1, int x2, int y1, int y2) { return sqrt((double)abs(x1 - x2) * (double)abs(x1 - x2) + (double)abs(y1 - y2) * (double)abs(y1 - y2)); } int cost[2550][2550]; int poin[2550]; typedef struct { int from; int to; int cost; } Edge; class BellemanFord { public: vector<Edge> edge; vector<ll> dist; bool bellemanford(int v, int s) { dist = vector<ll>(v, INF); dist[s] = 0; for (int i = 0; i < v * 2; i++) { for (int j = 0; j < edge.size(); j++) { if (dist[edge[j].from] + edge[j].cost < dist[edge[j].to]) { if (dist[v - 1] < -INF / 2) return true; dist[edge[j].to] = dist[edge[j].from] + edge[j].cost; if (i == 2 * v - 1 && edge[j].to == v - 1) return true; } } } return false; } }; bool solve() { // REP (i,2550) REP (j,2550) cost[i][j] = INF; BellemanFord bf; // int n,m; cin >> n >> m; // vector<pair<int,int>> ab(n); // REP (i,n) cin >> ab[i].F >> ab[i].S; // set<pair<int,int>> get; // REP (i,n) get.insert(ab[i].S); // sort(all(ab)); reverse(all(ab)); // int day = 0; // int ans = 0; // bool rem[n]; REP (i,n) rem[i] = true; // int now = 0; // REP (i,m+1) { // while(m-ab[now].F < i) get.erase(ab[now].S),now++; // if (get.size() == 0) break; // ans += *get.rbegin(); // int tmp = *get.rbegin(); // cout << tmp << endl; // get.erase(tmp); // } // cout << ans << endl; int n, m, p; cin >> n >> m >> p; REP(i, m) { int a, b, c; cin >> a >> b >> c; bf.edge.pb({--a, --b, -(c - p)}); } if (bf.bellemanford(n, 0)) { cout << -1 << endl; } else { cout << max(-bf.dist[n - 1], 0ll) << endl; } } signed main() { cin.tie(0); ios::sync_with_stdio(false); solve(); }
#include <bits/stdc++.h> #include <functional> #include <iomanip> using namespace std; #define int long long #define pb push_back #define ub upper_bound #define lb upper_bound #define mp make_pair #define F first #define S second #define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define REP(i, n) FOR(i, 0, n) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define SORT(c) sort((c).begin(), (c).end()) #define ve vector #define vi vector<int> #define vp vector<pair<int, int>> #define vvi vector<vector<int>> using ll = long long; ll INF = LLONG_MAX / 4 - 100; ll mod = 1e9 + 7; int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1}; vector<ll> prime; class fact { public: int fmod = 1e9 + 7; vector<int> fac, inv; fact(int n, int Mod = 1e9 + 7) { fmod = Mod; fac = vector<int>(n, 0); inv = vector<int>(n, 0); fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i - 1] * i % fmod; for (int i = 0; i < n; i++) inv[i] = fact::POW(fac[i], fmod - 2); } ll nCr(ll n, ll r) { return (fac[n] * inv[r] % fmod) * inv[n - r] % fmod; } ll POW(ll a, ll b) { ll c = 1; while (b > 0) { if (b & 1) { c = a * c % fmod; } a = a * a % fmod; b >>= 1; } return c; } }; template <class T = ll> T in() { T x; cin >> x; return (x); } void DEBUG(vector<int> a) { for (int i = 0; i < a.size(); i++) cout << a[i] << " "; cout << endl; } void EMP(int x) { cout << "!!!" << x << "!!!" << endl; } ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; } return a; } ll LCM(ll a, ll b) { return a * b / GCD(a, b); } ll POW(ll a, ll b) { ll c = 1; while (b > 0) { if (b & 1) { c = a * c % mod; } a = a * a % mod; b >>= 1; } return c; } void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; } for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } } template <typename T> T chmin(T &a, T b) { if (a > b) a = b; return a; } template <typename T> T chmax(T &a, T b) { if (a < b) a = b; return b; } bool isSqrt(ll a) { return pow(sqrt(a), 2) == a ? 1 : 0; } void YesNo(bool a) { if (a) cout << "Yes"; else cout << "No"; cout << endl; } void yesno(bool a) { if (a) cout << "yes"; else cout << "no"; cout << endl; } void YESNO(bool a) { if (a) cout << "YES"; else cout << "NO"; cout << endl; } double dis(int x1, int x2, int y1, int y2) { return sqrt((double)abs(x1 - x2) * (double)abs(x1 - x2) + (double)abs(y1 - y2) * (double)abs(y1 - y2)); } int cost[2550][2550]; int poin[2550]; typedef struct { int from; int to; int cost; } Edge; class BellemanFord { public: vector<Edge> edge; vector<ll> dist; bool bellemanford(int v, int s) { dist = vector<ll>(v, INF); dist[s] = 0; for (int i = 0; i < v * 3; i++) { for (int j = 0; j < edge.size(); j++) { if (dist[edge[j].from] + edge[j].cost < dist[edge[j].to]) { if (dist[v - 1] < -INF / 2) return true; dist[edge[j].to] = dist[edge[j].from] + edge[j].cost; if (i >= v - 1 && edge[j].to == v - 1) return true; } } } return false; } }; bool solve() { // REP (i,2550) REP (j,2550) cost[i][j] = INF; BellemanFord bf; // int n,m; cin >> n >> m; // vector<pair<int,int>> ab(n); // REP (i,n) cin >> ab[i].F >> ab[i].S; // set<pair<int,int>> get; // REP (i,n) get.insert(ab[i].S); // sort(all(ab)); reverse(all(ab)); // int day = 0; // int ans = 0; // bool rem[n]; REP (i,n) rem[i] = true; // int now = 0; // REP (i,m+1) { // while(m-ab[now].F < i) get.erase(ab[now].S),now++; // if (get.size() == 0) break; // ans += *get.rbegin(); // int tmp = *get.rbegin(); // cout << tmp << endl; // get.erase(tmp); // } // cout << ans << endl; int n, m, p; cin >> n >> m >> p; REP(i, m) { int a, b, c; cin >> a >> b >> c; bf.edge.pb({--a, --b, -(c - p)}); } if (bf.bellemanford(n, 0)) { cout << -1 << endl; } else { cout << max(-bf.dist[n - 1], 0ll) << endl; } } signed main() { cin.tie(0); ios::sync_with_stdio(false); solve(); }
[ "literal.number.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change", "expression.operator.compare.change", "control_flow.branch.if.condition.change", "expression.operation.binary.remove" ]
753,844
753,843
u764234894
cpp
p02949
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; #define REP(var, a, b) for (int var = (a); var < (b); var++) #define rep(var, n) for (int var = 0; var < (n); ++var) #define ALL(c) (c).begin(), (c).end() #define rALL(c) (c).rbegin(), (c).rend() ll MOD = 1000000007; ll INF = 1LL << 60; struct Edge { ll from, to, cost; Edge(ll f, ll t, ll c) : from(f), to(t), cost(c) {} }; bool find_negative_loop(ll n, const vector<Edge> &edges) { vl d(n, INF); d[0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < edges.size(); j++) { Edge e = edges[j]; if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; if (i == n - 1) { return true; } } } } return false; } ll bellman_ford(ll n, const vector<Edge> &edges) { vl dist(n, INF); dist[0] = 0; for (int k = 0; k < n; ++k) { bool update = false; for (int i = 0; i < edges.size(); ++i) { Edge e = edges[i]; if (dist[e.from] != INF && dist[e.to] > dist[e.from] + e.cost) { dist[e.to] = dist[e.from] + e.cost; update = true; } } if (!update) break; } return dist[n - 1]; } int main() { // ll n, m, p; cin >> n >> m >> p; vl a(m), b(m), c(m); vvl edge(n), edge2(n); set<ll> reachable, reachable2; reachable.insert(0); reachable2.insert(n - 1); rep(i, m) { cin >> a[i] >> b[i] >> c[i]; a[i]--; b[i]--; edge[a[i]].push_back(b[i]); edge2[b[i]].push_back(a[i]); } queue<ll> que; que.push(0); while (!que.empty()) { ll u = que.front(); que.pop(); for (auto &v : edge[u]) { if (reachable.find(v) == reachable.end()) { que.push(v); reachable.insert(v); } } } que.push(n - 1); while (!que.empty()) { ll u = que.front(); que.pop(); for (auto &v : edge[u]) { if (reachable2.find(v) == reachable2.end()) { que.push(v); reachable2.insert(v); } } } vector<Edge> edges; rep(i, m) { if (reachable.find(a[i]) != reachable.end() && reachable2.find(a[i]) != reachable2.end() && reachable.find(b[i]) != reachable.end() && reachable2.find(b[i]) != reachable2.end()) { // edges.push_back(Edge(a[i], b[i], p - c[i])); } } if (find_negative_loop(n, edges)) { cout << -1 << endl; return 0; } ll ans = bellman_ford(n, edges); cout << max(0LL, -ans) << endl; }
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; #define REP(var, a, b) for (int var = (a); var < (b); var++) #define rep(var, n) for (int var = 0; var < (n); ++var) #define ALL(c) (c).begin(), (c).end() #define rALL(c) (c).rbegin(), (c).rend() ll MOD = 1000000007; ll INF = 1LL << 60; struct Edge { ll from, to, cost; Edge(ll f, ll t, ll c) : from(f), to(t), cost(c) {} }; bool find_negative_loop(ll n, const vector<Edge> &edges) { vl d(n, INF); d[0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < edges.size(); j++) { Edge e = edges[j]; if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; if (i == n - 1) { return true; } } } } return false; } ll bellman_ford(ll n, const vector<Edge> &edges) { vl dist(n, INF); dist[0] = 0; for (int k = 0; k < n; ++k) { bool update = false; for (int i = 0; i < edges.size(); ++i) { Edge e = edges[i]; if (dist[e.from] != INF && dist[e.to] > dist[e.from] + e.cost) { dist[e.to] = dist[e.from] + e.cost; update = true; } } if (!update) break; } return dist[n - 1]; } int main() { // ll n, m, p; cin >> n >> m >> p; vl a(m), b(m), c(m); vvl edge(n), edge2(n); set<ll> reachable, reachable2; reachable.insert(0); reachable2.insert(n - 1); rep(i, m) { cin >> a[i] >> b[i] >> c[i]; a[i]--; b[i]--; edge[a[i]].push_back(b[i]); edge2[b[i]].push_back(a[i]); } queue<ll> que; que.push(0); while (!que.empty()) { ll u = que.front(); que.pop(); for (auto &v : edge[u]) { if (reachable.find(v) == reachable.end()) { que.push(v); reachable.insert(v); } } } que.push(n - 1); while (!que.empty()) { ll u = que.front(); que.pop(); for (auto &v : edge2[u]) { if (reachable2.find(v) == reachable2.end()) { que.push(v); reachable2.insert(v); } } } vector<Edge> edges; rep(i, m) { if (reachable.find(a[i]) != reachable.end() && reachable2.find(a[i]) != reachable2.end() && reachable.find(b[i]) != reachable.end() && reachable2.find(b[i]) != reachable2.end()) { // edges.push_back(Edge(a[i], b[i], p - c[i])); } } if (find_negative_loop(n, edges)) { cout << -1 << endl; return 0; } ll ans = bellman_ford(n, edges); cout << max(0LL, -ans) << endl; return 0; }
[ "identifier.change", "control_flow.return.add", "control_flow.return.0.add" ]
753,851
753,852
u194385557
cpp
p02949
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; #define REP(var, a, b) for (int var = (a); var < (b); var++) #define rep(var, n) for (int var = 0; var < (n); ++var) #define ALL(c) (c).begin(), (c).end() #define rALL(c) (c).rbegin(), (c).rend() ll MOD = 1000000007; ll INF = 1LL << 60; struct Edge { ll from, to, cost; Edge(ll f, ll t, ll c) : from(f), to(t), cost(c) {} }; bool find_negative_loop(ll n, const vector<Edge> &edges) { vl d(n, INF); d[0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < edges.size(); j++) { Edge e = edges[j]; if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; if (i == n - 1) { return true; } } } } return false; } ll bellman_ford(ll n, const vector<Edge> &edges) { vl dist(n, INF); dist[0] = 0; for (int k = 0; k < n; ++k) { bool update = false; for (int i = 0; i < edges.size(); ++i) { Edge e = edges[i]; if (dist[e.from] != INF && dist[e.to] > dist[e.from] + e.cost) { dist[e.to] = dist[e.from] + e.cost; update = true; } } if (!update) break; } return dist[n - 1]; } int main() { // ll n, m, p; cin >> n >> m >> p; vl a(m), b(m), c(m); vvl edge(n), edge2(n); set<ll> reachable, reachable2; reachable.insert(0); reachable2.insert(n - 1); rep(i, m) { cin >> a[i] >> b[i] >> c[i]; a[i]--; b[i]--; edge[a[i]].push_back(b[i]); edge2[b[i]].push_back(a[i]); } queue<ll> que; que.push(0); while (!que.empty()) { ll u = que.front(); que.pop(); for (auto &v : edge[u]) { if (reachable.find(v) == reachable.end()) { que.push(v); reachable.insert(v); } } } que.push(n - 1); while (!que.empty()) { ll u = que.front(); que.pop(); for (auto &v : edge[u]) { if (reachable2.find(v) == reachable2.end()) { que.push(v); reachable2.insert(v); } } } vector<Edge> edges; rep(i, m) { if (reachable.find(a[i]) != reachable.end() && reachable2.find(a[i]) != reachable2.end() && reachable.find(b[i]) != reachable.end() && reachable2.find(b[i]) != reachable2.end()) { // edges.push_back(Edge(a[i], b[i], p - c[i])); } } if (find_negative_loop(n, edges)) { cout << -1 << endl; return 0; } ll ans = bellman_ford(n, edges); cout << max(0LL, ans) << endl; }
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; #define REP(var, a, b) for (int var = (a); var < (b); var++) #define rep(var, n) for (int var = 0; var < (n); ++var) #define ALL(c) (c).begin(), (c).end() #define rALL(c) (c).rbegin(), (c).rend() ll MOD = 1000000007; ll INF = 1LL << 60; struct Edge { ll from, to, cost; Edge(ll f, ll t, ll c) : from(f), to(t), cost(c) {} }; bool find_negative_loop(ll n, const vector<Edge> &edges) { vl d(n, INF); d[0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < edges.size(); j++) { Edge e = edges[j]; if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; if (i == n - 1) { return true; } } } } return false; } ll bellman_ford(ll n, const vector<Edge> &edges) { vl dist(n, INF); dist[0] = 0; for (int k = 0; k < n; ++k) { bool update = false; for (int i = 0; i < edges.size(); ++i) { Edge e = edges[i]; if (dist[e.from] != INF && dist[e.to] > dist[e.from] + e.cost) { dist[e.to] = dist[e.from] + e.cost; update = true; } } if (!update) break; } return dist[n - 1]; } int main() { // ll n, m, p; cin >> n >> m >> p; vl a(m), b(m), c(m); vvl edge(n), edge2(n); set<ll> reachable, reachable2; reachable.insert(0); reachable2.insert(n - 1); rep(i, m) { cin >> a[i] >> b[i] >> c[i]; a[i]--; b[i]--; edge[a[i]].push_back(b[i]); edge2[b[i]].push_back(a[i]); } queue<ll> que; que.push(0); while (!que.empty()) { ll u = que.front(); que.pop(); for (auto &v : edge[u]) { if (reachable.find(v) == reachable.end()) { que.push(v); reachable.insert(v); } } } que.push(n - 1); while (!que.empty()) { ll u = que.front(); que.pop(); for (auto &v : edge2[u]) { if (reachable2.find(v) == reachable2.end()) { que.push(v); reachable2.insert(v); } } } vector<Edge> edges; rep(i, m) { if (reachable.find(a[i]) != reachable.end() && reachable2.find(a[i]) != reachable2.end() && reachable.find(b[i]) != reachable.end() && reachable2.find(b[i]) != reachable2.end()) { // edges.push_back(Edge(a[i], b[i], p - c[i])); } } if (find_negative_loop(n, edges)) { cout << -1 << endl; return 0; } ll ans = bellman_ford(n, edges); cout << max(0LL, -ans) << endl; return 0; }
[ "identifier.change", "expression.operation.unary.add", "call.arguments.change", "control_flow.return.add", "control_flow.return.0.add" ]
753,853
753,852
u194385557
cpp
p02949
#define _USE_MATH_DEFINES #include <algorithm> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <string> #include <vector> #define rep(i, a, b) for (int i = (a); i < (b); i++) using namespace std; typedef long long int ll; typedef complex<double> com; typedef pair<int, int> P; const int mod = 1e9 + 7; const int MOD = 998244353; const ll INF = 4e18; int main() { int n, m, k; cin >> n >> m >> k; vector<int> a(m), b(m), c(m); rep(i, 0, m) { cin >> a[i] >> b[i] >> c[i]; a[i]--; b[i]--; c[i] *= -1; c[i] += k; } vector<ll> dist(n, INF); dist[0] = 0; rep(roop, 0, n) { bool update = false; rep(i, 0, m) { if (dist[a[i]] != INF && dist[b[i]] > dist[a[i]] + c[i]) { dist[b[i]] = dist[a[i]] + c[i]; update = true; } } if (!update) break; } ll ans = dist[n - 1]; vector<bool> neg(n, false); rep(roop, 0, n) rep(i, 0, m) { if (dist[a[i]] == INF) continue; if (dist[b[i]] > dist[a[i]] + c[i]) { dist[b[i]] = dist[a[i]] + c[i]; neg[b[i]] = true; } if (neg[a[i]]) neg[b[i]] = true; } if (neg[n - 1]) printf("-1"); else printf("%lld", -ans); return 0; }
#define _USE_MATH_DEFINES #include <algorithm> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <string> #include <vector> #define rep(i, a, b) for (int i = (a); i < (b); i++) using namespace std; typedef long long int ll; typedef complex<double> com; typedef pair<int, int> P; const int mod = 1e9 + 7; const int MOD = 998244353; const ll INF = 4e18; int main() { int n, m, k; cin >> n >> m >> k; vector<int> a(m), b(m), c(m); rep(i, 0, m) { cin >> a[i] >> b[i] >> c[i]; a[i]--; b[i]--; c[i] *= -1; c[i] += k; } vector<ll> dist(n, INF); dist[0] = 0; rep(roop, 0, n) { bool update = false; rep(i, 0, m) { if (dist[a[i]] != INF && dist[b[i]] > dist[a[i]] + c[i]) { dist[b[i]] = dist[a[i]] + c[i]; update = true; } } if (!update) break; } ll ans = dist[n - 1]; vector<bool> neg(n, false); rep(roop, 0, n) rep(i, 0, m) { if (dist[a[i]] == INF) continue; if (dist[b[i]] > dist[a[i]] + c[i]) { dist[b[i]] = dist[a[i]] + c[i]; neg[b[i]] = true; } if (neg[a[i]]) neg[b[i]] = true; } if (neg[n - 1]) printf("-1"); else printf("%lld", max(0LL, -ans)); return 0; }
[ "call.add", "call.arguments.change" ]
753,854
753,855
u407614884
cpp
p02949
#include <algorithm> #include <bitset> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, n) repr(i, 0, n) #define INF 1e9 #define MOD 1000000007 #define LINF (long long)4e18 using ll = long long; using Pi = pair<int, int>; using Pl = pair<ll, ll>; vector<vector<int>> to, from; vector<bool> to_used, from_used; void dfs(int u) { if (to_used[u] == true) return; to_used[u] = true; for (int v : to[u]) { dfs(v); } } void rdfs(int u) { if (from_used[u] == true) return; from_used[u] = true; for (int v : from[u]) { rdfs(v); } } int main() { int N, M, P; cin >> N >> M >> P; vector<tuple<int, int, int>> edges; to.resize(N); from.resize(N); to_used.resize(N, false); from_used.resize(N, false); rep(i, M) { int A, B, C; cin >> A >> B >> C; A--; B--; C -= P; C = -C; edges.emplace_back(A, B, C); to[A].push_back(B); from[B].push_back(A); } dfs(0); rdfs(N - 1); // bellmanford vector<int> dist(N, INF); dist[0] = 0; int cnt = 0; bool upd = true; vector<bool> ok(N); rep(i, N) { ok[i] = to_used[i] & from_used[i]; } while (upd) { upd = false; rep(i, M) { int A, B, C; tie(A, B, C) = edges[i]; if (!ok[A]) continue; if (!ok[B]) continue; if (dist[B] > dist[A] + C) { dist[B] = dist[A] + C; upd = true; } } cnt++; if (cnt > N) { cout << -1 << endl; return 0; } } int ans = -dist[N - 1]; cout << ans << endl; }
#include <algorithm> #include <bitset> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, n) repr(i, 0, n) #define INF 1e9 #define MOD 1000000007 #define LINF (long long)4e18 using ll = long long; using Pi = pair<int, int>; using Pl = pair<ll, ll>; vector<vector<int>> to, from; vector<bool> to_used, from_used; void dfs(int u) { if (to_used[u] == true) return; to_used[u] = true; for (int v : to[u]) { dfs(v); } } void rdfs(int u) { if (from_used[u] == true) return; from_used[u] = true; for (int v : from[u]) { rdfs(v); } } int main() { int N, M, P; cin >> N >> M >> P; vector<tuple<int, int, int>> edges; to.resize(N); from.resize(N); to_used.resize(N, false); from_used.resize(N, false); rep(i, M) { int A, B, C; cin >> A >> B >> C; A--; B--; C -= P; C = -C; edges.emplace_back(A, B, C); to[A].push_back(B); from[B].push_back(A); } dfs(0); rdfs(N - 1); // bellmanford vector<int> dist(N, INF); dist[0] = 0; int cnt = 0; bool upd = true; vector<bool> ok(N); rep(i, N) { ok[i] = to_used[i] & from_used[i]; } while (upd) { upd = false; rep(i, M) { int A, B, C; tie(A, B, C) = edges[i]; if (!ok[A]) continue; if (!ok[B]) continue; if (dist[B] > dist[A] + C) { dist[B] = dist[A] + C; upd = true; } } cnt++; if (cnt > N) { cout << -1 << endl; return 0; } } int ans = max(-dist[N - 1], 0); cout << ans << endl; }
[ "call.add", "call.arguments.add" ]
753,857
753,858
u314008046
cpp
p02949
#include <algorithm> #include <iomanip> #include <iostream> #include <queue> #include <set> #include <string> #include <vector> using namespace std; // 隣接リストで使う辺を表す型 struct Edge { long long to, cost; // 辺の接続先頂点, 辺の重み Edge(long long to, long long cost) : to(to), cost(cost) {} // コンストラクタ }; typedef vector<vector<Edge>> AdjList; // 隣接リストの型 AdjList graph; // グラフの辺を格納した構造体 // graph[v][i]は頂点vから出るi番目の辺Edge const long long INF = 100000000000000; vector<long long> dist; // 最短距離 // 戻り値がtrueなら負の閉路を含む bool bellman_ford(long long n, long long s) { // nは頂点数、sは開始頂点 dist = vector<long long>(n, INF); dist[s] = 0; // 開始点の距離は0 for (long long i = 0; i < n + 5002; i++) { for (long long v = 0; v < n; v++) { for (long long k = 0; k < graph[v].size(); k++) { Edge e = graph[v][k]; if (dist[v] != INF && dist[e.to] > dist[v] + e.cost) { dist[e.to] = dist[v] + e.cost; if (i == n - 1 + 5000) { if (e.to == n - 1) return true; // n回目にも更新があるなら負の閉路が存在 } } } } } return false; } int main() { long long n, m, p; cin >> n >> m >> p; graph = AdjList(n); for (long long i = 0; i < m; i++) { long long from, to, cost; cin >> from >> to >> cost; from--; to--; cost *= (-1); cost += p; graph[from].push_back(Edge(to, cost)); } if (bellman_ford(n, 0)) { cout << -1 << endl; } else { cout << (dist[n - 1] * (-1) > 0 ? dist[n - 1] * (-1) : 0) << endl; } return 0; }
#include <algorithm> #include <iomanip> #include <iostream> #include <queue> #include <set> #include <string> #include <vector> using namespace std; // 隣接リストで使う辺を表す型 struct Edge { long long to, cost; // 辺の接続先頂点, 辺の重み Edge(long long to, long long cost) : to(to), cost(cost) {} // コンストラクタ }; typedef vector<vector<Edge>> AdjList; // 隣接リストの型 AdjList graph; // グラフの辺を格納した構造体 // graph[v][i]は頂点vから出るi番目の辺Edge const long long INF = 100000000000000; vector<long long> dist; // 最短距離 // 戻り値がtrueなら負の閉路を含む bool bellman_ford(long long n, long long s) { // nは頂点数、sは開始頂点 dist = vector<long long>(n, INF); dist[s] = 0; // 開始点の距離は0 for (long long i = 0; i < n + 5002; i++) { for (long long v = 0; v < n; v++) { for (long long k = 0; k < graph[v].size(); k++) { Edge e = graph[v][k]; if (dist[v] != INF && dist[e.to] > dist[v] + e.cost) { dist[e.to] = dist[v] + e.cost; if (i >= n - 1) { if (e.to == n - 1) return true; // n回目にも更新があるなら負の閉路が存在 } } } } } return false; } int main() { long long n, m, p; cin >> n >> m >> p; graph = AdjList(n); for (long long i = 0; i < m; i++) { long long from, to, cost; cin >> from >> to >> cost; from--; to--; cost *= (-1); cost += p; graph[from].push_back(Edge(to, cost)); } if (bellman_ford(n, 0)) { cout << -1 << endl; } else { cout << (dist[n - 1] * (-1) > 0 ? dist[n - 1] * (-1) : 0) << endl; } return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change", "expression.operation.binary.remove" ]
753,864
753,865
u990764614
cpp
p02949
#include <algorithm> #include <iomanip> #include <iostream> #include <queue> #include <set> #include <string> #include <vector> using namespace std; // 隣接リストで使う辺を表す型 struct Edge { long long to, cost; // 辺の接続先頂点, 辺の重み Edge(long long to, long long cost) : to(to), cost(cost) {} // コンストラクタ }; typedef vector<vector<Edge>> AdjList; // 隣接リストの型 AdjList graph; // グラフの辺を格納した構造体 // graph[v][i]は頂点vから出るi番目の辺Edge const long long INF = 100000000000000; vector<long long> dist; // 最短距離 // 戻り値がtrueなら負の閉路を含む bool bellman_ford(long long n, long long s) { // nは頂点数、sは開始頂点 dist = vector<long long>(n, INF); dist[s] = 0; // 開始点の距離は0 for (long long i = 0; i < n + 5000; i++) { for (long long v = 0; v < n; v++) { for (long long k = 0; k < graph[v].size(); k++) { Edge e = graph[v][k]; if (dist[v] != INF && dist[e.to] > dist[v] + e.cost) { dist[e.to] = dist[v] + e.cost; if (i == n - 1 + 5000) { if (e.to == n - 1) return true; // n回目にも更新があるなら負の閉路が存在 } } } } } return false; } int main() { long long n, m, p; cin >> n >> m >> p; graph = AdjList(n); for (long long i = 0; i < m; i++) { long long from, to, cost; cin >> from >> to >> cost; from--; to--; cost *= (-1); cost += p; graph[from].push_back(Edge(to, cost)); } if (bellman_ford(n, 0)) { cout << -1 << endl; } else { cout << (dist[n - 1] * (-1) > 0 ? dist[n - 1] * (-1) : 0) << endl; } return 0; }
#include <algorithm> #include <iomanip> #include <iostream> #include <queue> #include <set> #include <string> #include <vector> using namespace std; // 隣接リストで使う辺を表す型 struct Edge { long long to, cost; // 辺の接続先頂点, 辺の重み Edge(long long to, long long cost) : to(to), cost(cost) {} // コンストラクタ }; typedef vector<vector<Edge>> AdjList; // 隣接リストの型 AdjList graph; // グラフの辺を格納した構造体 // graph[v][i]は頂点vから出るi番目の辺Edge const long long INF = 100000000000000; vector<long long> dist; // 最短距離 // 戻り値がtrueなら負の閉路を含む bool bellman_ford(long long n, long long s) { // nは頂点数、sは開始頂点 dist = vector<long long>(n, INF); dist[s] = 0; // 開始点の距離は0 for (long long i = 0; i < n + 5002; i++) { for (long long v = 0; v < n; v++) { for (long long k = 0; k < graph[v].size(); k++) { Edge e = graph[v][k]; if (dist[v] != INF && dist[e.to] > dist[v] + e.cost) { dist[e.to] = dist[v] + e.cost; if (i >= n - 1) { if (e.to == n - 1) return true; // n回目にも更新があるなら負の閉路が存在 } } } } } return false; } int main() { long long n, m, p; cin >> n >> m >> p; graph = AdjList(n); for (long long i = 0; i < m; i++) { long long from, to, cost; cin >> from >> to >> cost; from--; to--; cost *= (-1); cost += p; graph[from].push_back(Edge(to, cost)); } if (bellman_ford(n, 0)) { cout << -1 << endl; } else { cout << (dist[n - 1] * (-1) > 0 ? dist[n - 1] * (-1) : 0) << endl; } return 0; }
[ "literal.number.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change", "expression.operator.compare.change", "control_flow.branch.if.condition.change", "expression.operation.binary.remove" ]
753,866
753,865
u990764614
cpp
p02949
#include <algorithm> #include <iomanip> #include <iostream> #include <queue> #include <set> #include <string> #include <vector> using namespace std; // 隣接リストで使う辺を表す型 struct Edge { long long to, cost; // 辺の接続先頂点, 辺の重み Edge(long long to, long long cost) : to(to), cost(cost) {} // コンストラクタ }; typedef vector<vector<Edge>> AdjList; // 隣接リストの型 AdjList graph; // グラフの辺を格納した構造体 // graph[v][i]は頂点vから出るi番目の辺Edge const long long INF = 100000000000000; vector<long long> dist; // 最短距離 // 戻り値がtrueなら負の閉路を含む bool bellman_ford(long long n, long long s) { // nは頂点数、sは開始頂点 dist = vector<long long>(n, INF); dist[s] = 0; // 開始点の距離は0 for (long long i = 0; i < n; i++) { for (long long v = 0; v < n; v++) { for (long long k = 0; k < graph[v].size(); k++) { Edge e = graph[v][k]; if (dist[v] != INF && dist[e.to] > dist[v] + e.cost) { dist[e.to] = dist[v] + e.cost; if (i == n - 1) { if (e.to == n - 1) return true; // n回目にも更新があるなら負の閉路が存在 } } } } } return false; } int main() { long long n, m, p; cin >> n >> m >> p; graph = AdjList(n); for (long long i = 0; i < m; i++) { long long from, to, cost; cin >> from >> to >> cost; from--; to--; cost *= (-1); cost += p; graph[from].push_back(Edge(to, cost)); } if (bellman_ford(n, 0)) { cout << 1 << endl; } else { cout << (dist[n - 1] * (-1) > 0 ? dist[n - 1] * (-1) : 0) << endl; } return 0; }
#include <algorithm> #include <iomanip> #include <iostream> #include <queue> #include <set> #include <string> #include <vector> using namespace std; // 隣接リストで使う辺を表す型 struct Edge { long long to, cost; // 辺の接続先頂点, 辺の重み Edge(long long to, long long cost) : to(to), cost(cost) {} // コンストラクタ }; typedef vector<vector<Edge>> AdjList; // 隣接リストの型 AdjList graph; // グラフの辺を格納した構造体 // graph[v][i]は頂点vから出るi番目の辺Edge const long long INF = 100000000000000; vector<long long> dist; // 最短距離 // 戻り値がtrueなら負の閉路を含む bool bellman_ford(long long n, long long s) { // nは頂点数、sは開始頂点 dist = vector<long long>(n, INF); dist[s] = 0; // 開始点の距離は0 for (long long i = 0; i < n + 5002; i++) { for (long long v = 0; v < n; v++) { for (long long k = 0; k < graph[v].size(); k++) { Edge e = graph[v][k]; if (dist[v] != INF && dist[e.to] > dist[v] + e.cost) { dist[e.to] = dist[v] + e.cost; if (i >= n - 1) { if (e.to == n - 1) return true; // n回目にも更新があるなら負の閉路が存在 } } } } } return false; } int main() { long long n, m, p; cin >> n >> m >> p; graph = AdjList(n); for (long long i = 0; i < m; i++) { long long from, to, cost; cin >> from >> to >> cost; from--; to--; cost *= (-1); cost += p; graph[from].push_back(Edge(to, cost)); } if (bellman_ford(n, 0)) { cout << -1 << endl; } else { cout << (dist[n - 1] * (-1) > 0 ? dist[n - 1] * (-1) : 0) << endl; } return 0; }
[ "control_flow.loop.for.condition.change", "expression.operator.compare.change", "control_flow.branch.if.condition.change", "expression.operation.unary.arithmetic.add" ]
753,867
753,865
u990764614
cpp
p02949
#include <bits/stdc++.h> using namespace std; #define FOR(i, j, k) for (int i = j; i < k; i++) #define REP(i, j) FOR(i, 0, j) #define fst first #define snd second #define pb push_back #define eb emplace_back #define all(obj) (obj).begin(), (obj).end() #define rall(obj) (obj).rbegin(), (obj).rend() typedef long long int ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vi> vvi; #define BELLMAN_FORD_MAX_E 10005 #define BELLMAN_FORD_MAX_V 10005 struct edge { int from, to, cost; edge() {} edge(int f, int t, int c) : from(f), to(t), cost(c) {} }; edge es[BELLMAN_FORD_MAX_E]; int d[BELLMAN_FORD_MAX_V]; bool negative[BELLMAN_FORD_MAX_V]; int V, E; void shortest_path(int s, bool is_find_negative_loop) { for (int i = 0; i < V; i++) d[i] = (1 << 30); d[s] = 0; for (int j = 0; j < V; j++) { bool update = false; for (int i = 0; i < E; i++) { const edge &e = es[i]; if (d[e.from] != (1 << 30) && d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; update = true; } } if (!update) break; } if (is_find_negative_loop) { for (int i = 0; i < V; i++) { negative[i] = false; } for (int i = 0; i < V; i++) { for (int j = 0; j < E; j++) { const edge &e = es[j]; if (d[e.from] != (1 << 30) && d[e.to] > d[e.from] + e.cost) { negative[e.to] = true; } if (negative[e.from]) { negative[e.to] = true; } } } } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed; int p; cin >> V >> E >> p; REP(i, E) { int a, b, c; cin >> a >> b >> c; a--; b--; es[i] = edge(a, b, p - c); } shortest_path(0, true); if (negative[V - 1]) { cout << "-1" << endl; } else { cout << -d[V - 1] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, j, k) for (int i = j; i < k; i++) #define REP(i, j) FOR(i, 0, j) #define fst first #define snd second #define pb push_back #define eb emplace_back #define all(obj) (obj).begin(), (obj).end() #define rall(obj) (obj).rbegin(), (obj).rend() typedef long long int ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vi> vvi; #define BELLMAN_FORD_MAX_E 10005 #define BELLMAN_FORD_MAX_V 10005 struct edge { int from, to, cost; edge() {} edge(int f, int t, int c) : from(f), to(t), cost(c) {} }; edge es[BELLMAN_FORD_MAX_E]; int d[BELLMAN_FORD_MAX_V]; bool negative[BELLMAN_FORD_MAX_V]; int V, E; void shortest_path(int s, bool is_find_negative_loop) { for (int i = 0; i < V; i++) d[i] = (1 << 30); d[s] = 0; for (int j = 0; j < V; j++) { bool update = false; for (int i = 0; i < E; i++) { const edge &e = es[i]; if (d[e.from] != (1 << 30) && d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; update = true; } } if (!update) break; } if (is_find_negative_loop) { for (int i = 0; i < V; i++) { negative[i] = false; } for (int i = 0; i < V; i++) { for (int j = 0; j < E; j++) { const edge &e = es[j]; if (d[e.from] != (1 << 30) && d[e.to] > d[e.from] + e.cost) { negative[e.to] = true; } if (negative[e.from]) { negative[e.to] = true; } } } } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed; int p; cin >> V >> E >> p; REP(i, E) { int a, b, c; cin >> a >> b >> c; a--; b--; es[i] = edge(a, b, p - c); } shortest_path(0, true); if (negative[V - 1]) { cout << "-1" << endl; } else { cout << max(0, -d[V - 1]) << endl; } return 0; }
[ "call.add", "call.arguments.change" ]
753,868
753,869
u463697306
cpp
p02949
#include <algorithm> #include <bits/stdc++.h> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <sstream> #include <string> #include <vector> using namespace std; #define REP(i, n) FOR(i, 0, n) #define FOR(i, sta, n) \ for (long long i = (sta), i##Len_ = (n); i < i##Len_; i++) typedef long long ll; static const ll MOD = 1000000007; // static const ll INF = 1000000000000000000LL; const ll mod = 998244353; const ll INF = mod * mod; struct edge { int to; ll cost; }; const int em_max = 2500; vector<edge> G[em_max]; vector<int> rG[em_max]; ll score[em_max]; bool canGoal[em_max]; bool canStart[em_max]; //最短経路問題 //負の辺がでてくる int main() { ll N, M, P; cin >> N >> M >> P; REP(i, N) { // edge:a->b; cost:c int a, b, c; cin >> a >> b >> c; --a; --b; G[a].push_back({b, c}); rG[b].push_back(a); } //初期化 std::fill(score, score + N, -INF); score[0] = 0; // 0 -> N-1 queue<int> q; q.push(N - 1); canGoal[N - 1] = true; while (!q.empty()) { int id = q.front(); q.pop(); REP(j, rG[id].size()) { int to = rG[id][j]; //すでにゴールに到達できることがわかっている if (canGoal[to]) continue; canGoal[to] = true; q.push(to); } } // q.empty() == true q.push(0); canStart[0] = true; while (!q.empty()) { int id = q.front(); q.pop(); REP(j, G[id].size()) { int to = G[id][j].to; if (canStart[to]) continue; canStart[to] = true; q.push(to); } } REP(i, N) { if (canStart[i] == false) { canGoal[i] = false; } } REP(t, 5000) { REP(i, N) { if (canGoal[i] == false) continue; REP(j, G[i].size()) { int to = G[i][j].to; if (canGoal[to] == false) continue; // 1辺の移動のたびに -P される ll ns = score[i] + G[i][j].cost - P; if (score[to] < ns) { score[to] = ns; } } } } //まだ最大値が更新されるなら、存在しない REP(i, N) { if (canGoal[i] == false) continue; REP(j, G[i].size()) { int to = G[i][j].to; if (canGoal[to] == false) continue; // 1辺の移動のたびに -P される ll ns = score[i] + G[i][j].cost - P; if (score[to] < ns) { score[to] = ns; cout << -1 << endl; return 0; } } } if (score[N - 1] < 0) score[N - 1] = 0; cout << score[N - 1] << endl; return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <sstream> #include <string> #include <vector> using namespace std; #define REP(i, n) FOR(i, 0, n) #define FOR(i, sta, n) \ for (long long i = (sta), i##Len_ = (n); i < i##Len_; i++) typedef long long ll; static const ll MOD = 1000000007; // static const ll INF = 1000000000000000000LL; const ll mod = 998244353; const ll INF = mod * mod; struct edge { int to; ll cost; }; const int em_max = 2500; vector<edge> G[em_max]; vector<int> rG[em_max]; ll score[em_max]; bool canGoal[em_max]; bool canStart[em_max]; //最短経路問題 //負の辺がでてくる int main() { ll N, M, P; cin >> N >> M >> P; REP(i, M) { // edge:a->b; cost:c int a, b, c; cin >> a >> b >> c; --a; --b; G[a].push_back({b, c}); rG[b].push_back(a); } //初期化 std::fill(score, score + N, -INF); score[0] = 0; // 0 -> N-1 queue<int> q; q.push(N - 1); canGoal[N - 1] = true; while (!q.empty()) { int id = q.front(); q.pop(); REP(j, rG[id].size()) { int to = rG[id][j]; //すでにゴールに到達できることがわかっている if (canGoal[to]) continue; canGoal[to] = true; q.push(to); } } // q.empty() == true q.push(0); canStart[0] = true; while (!q.empty()) { int id = q.front(); q.pop(); REP(j, G[id].size()) { int to = G[id][j].to; if (canStart[to]) continue; canStart[to] = true; q.push(to); } } REP(i, N) { if (canStart[i] == false) { canGoal[i] = false; } } REP(t, 5000) { REP(i, N) { if (canGoal[i] == false) continue; REP(j, G[i].size()) { int to = G[i][j].to; if (canGoal[to] == false) continue; // 1辺の移動のたびに -P される ll ns = score[i] + G[i][j].cost - P; if (score[to] < ns) { score[to] = ns; } } } } //まだ最大値が更新されるなら、存在しない REP(i, N) { if (canGoal[i] == false) continue; REP(j, G[i].size()) { int to = G[i][j].to; if (canGoal[to] == false) continue; // 1辺の移動のたびに -P される ll ns = score[i] + G[i][j].cost - P; if (score[to] < ns) { score[to] = ns; cout << -1 << endl; return 0; } } } if (score[N - 1] < 0) score[N - 1] = 0; cout << score[N - 1] << endl; return 0; }
[]
753,870
753,871
u485731913
cpp
p02949
#include <bits/stdc++.h> using namespace std; using lint = long long; template <class T = int> using V = vector<T>; template <class T = int> using VV = V<V<T>>; const int inf = 1e9; struct edge { int to, cost; edge(int to, int cost) : to(to), cost(cost) {} }; template <class T> bool bellman_ford(int s, const VV<edge> &g, V<T> &d) { int n = g.size(); d.assign(n, inf); d[s] = 0; for (int i = 0; i < n - 1; i++) { bool upd = false; for (int v = 0; v < g.size(); v++) if (d[v] != inf) { for (auto &&e : g[v]) { if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; upd = true; } } } if (!upd) return false; } return true; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m, p; cin >> n >> m >> p; VV<edge> g(n); { V<> a(m), b(m), c(m); VV<> h(n); for (int i = 0; i < m; ++i) { cin >> a[i] >> b[i] >> c[i], --a[i], --b[i]; h[b[i]].push_back(a[i]); } bitset<2500> bs; auto dfs = [&](const auto &dfs, int v) -> void { bs[v] = true; for (int w : h[v]) if (!bs[w]) { dfs(dfs, w); } }; dfs(dfs, n - 1); for (int i = 0; i < m; ++i) { if (!bs[a[i]] or !bs[b[i]]) continue; g[a[i]].emplace_back(edge{b[i], p - c[i]}); } } V<lint> d; if (bellman_ford(0, g, d)) { cout << -1 << '\n'; } else { cout << max(-d.back(), 0LL) << '\n'; } }
#include <bits/stdc++.h> using namespace std; using lint = long long; template <class T = int> using V = vector<T>; template <class T = int> using VV = V<V<T>>; const int inf = 1e9; struct edge { int to, cost; edge(int to, int cost) : to(to), cost(cost) {} }; template <class T> bool bellman_ford(int s, const VV<edge> &g, V<T> &d) { int n = g.size(); d.assign(n, inf); d[s] = 0; for (int i = 0; i < n; i++) { bool upd = false; for (int v = 0; v < g.size(); v++) if (d[v] != inf) { for (auto &&e : g[v]) { if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; upd = true; } } } if (!upd) return false; } return true; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m, p; cin >> n >> m >> p; VV<edge> g(n); { V<> a(m), b(m), c(m); VV<> h(n); for (int i = 0; i < m; ++i) { cin >> a[i] >> b[i] >> c[i], --a[i], --b[i]; h[b[i]].push_back(a[i]); } bitset<2500> bs; auto dfs = [&](const auto &dfs, int v) -> void { bs[v] = true; for (int w : h[v]) if (!bs[w]) { dfs(dfs, w); } }; dfs(dfs, n - 1); for (int i = 0; i < m; ++i) { if (!bs[a[i]] or !bs[b[i]]) continue; g[a[i]].emplace_back(edge{b[i], p - c[i]}); } } V<lint> d; if (bellman_ford(0, g, d)) { cout << -1 << '\n'; } else { cout << max(-d.back(), 0LL) << '\n'; } }
[ "control_flow.loop.for.condition.change", "expression.operation.binary.remove" ]
753,872
753,873
u536580583
cpp
p02949
#define _USE_MATH_DEFINES #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <time.h> #include <unordered_map> #include <vector> //#include <boost/multiprecision/cpp_int.hpp> using namespace std; using Int = long long; // using namespace boost::multiprecision; const double EPS = 1e-10; long long const MOD = 1000000007; long long mod_pow(long long x, long long n) { long long res = 1; for (int i = 0; i < 60; i++) { if (n >> i & 1) res = res * x % MOD; x = x * x % MOD; } return res; } template <typename T> T gcd(T a, T b) { return b != 0 ? gcd(b, a % b) : a; } template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); } void fastInput() { cin.tie(0); ios::sync_with_stdio(false); } struct Edge { int from, to, cost; }; int main(void) { int N, M, P; cin >> N >> M >> P; vector<vector<Edge>> G(N + 1); for (int i = 0; i < M; i++) { int a, b, c; cin >> a >> b >> c; a--; b--; c -= P; G[a].push_back({a, b, c}); } long long INF = 1; vector<vector<long long>> v(10001, vector<long long>(N + 1, -INF)); v[0][0] = 0; for (int time = 0; time < 10000; time++) { for (int i = 0; i < N; i++) { if (v[time][i] == -INF) continue; for (int j = 0; j < G[i].size(); j++) { Edge e = G[i][j]; v[time + 1][e.to] = max(v[time][e.from] + e.cost, v[time + 1][e.to]); } v[time + 1][i] = max(v[time][i], v[time + 1][i]); if (i == N - 1) { v[time + 1][N] = max(v[time][N - 1], v[time + 1][N]); } } if (time > 5000 && v[time + 1][N] > v[time][N]) { cout << -1 << endl; return 0; } } cout << max(v[10000][N], 0LL) << endl; }
#define _USE_MATH_DEFINES #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <time.h> #include <unordered_map> #include <vector> //#include <boost/multiprecision/cpp_int.hpp> using namespace std; using Int = long long; // using namespace boost::multiprecision; const double EPS = 1e-10; long long const MOD = 1000000007; long long mod_pow(long long x, long long n) { long long res = 1; for (int i = 0; i < 60; i++) { if (n >> i & 1) res = res * x % MOD; x = x * x % MOD; } return res; } template <typename T> T gcd(T a, T b) { return b != 0 ? gcd(b, a % b) : a; } template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); } void fastInput() { cin.tie(0); ios::sync_with_stdio(false); } struct Edge { int from, to, cost; }; int main(void) { int N, M, P; cin >> N >> M >> P; vector<vector<Edge>> G(N + 1); for (int i = 0; i < M; i++) { int a, b, c; cin >> a >> b >> c; a--; b--; c -= P; G[a].push_back({a, b, c}); } long long INF = 10000000000000000; vector<vector<long long>> v(10001, vector<long long>(N + 1, -INF)); v[0][0] = 0; for (int time = 0; time < 10000; time++) { for (int i = 0; i < N; i++) { if (v[time][i] == -INF) continue; for (int j = 0; j < G[i].size(); j++) { Edge e = G[i][j]; v[time + 1][e.to] = max(v[time][e.from] + e.cost, v[time + 1][e.to]); } v[time + 1][i] = max(v[time][i], v[time + 1][i]); if (i == N - 1) { v[time + 1][N] = max(v[time][N - 1], v[time + 1][N]); } } if (time > 5000 && v[time + 1][N] > v[time][N]) { cout << -1 << endl; return 0; } } cout << max(v[10000][N - 1], 0LL) << endl; }
[ "literal.number.change", "variable_declaration.value.change" ]
753,886
753,887
u543284218
cpp
p02949
#include <bits/stdc++.h> using namespace std; class Graph { public: struct Edge { long long to; long long distance; Edge(const long long t, const long long d) { this->to = t; this->distance = d; } bool operator<(const Edge &e) const { return this->distance < e.distance; } bool operator<=(const Edge &e) const { return this->distance <= e.distance; } bool operator>(const Edge &e) const { return this->distance > e.distance; } bool operator>=(const Edge &e) const { return this->distance >= e.distance; } bool operator==(const Edge &e) const { return this->distance == e.distance; } }; vector<vector<long long>> adjacency_matrix; long long node; long long initial_value; vector<vector<Edge>> edge; Graph(const long long N) { setNode(N); initializeEdgeVector(); } Graph(const long long N, const long long init) { setNode(N); initializeEdgeVector(); setInitialValue(init); } void setNode(const long long N) { this->node = N + 1; } void setInitialValue(const long long init) { this->initial_value = init; } void initializeAdjacencyMatrix() { this->adjacency_matrix = vector<vector<long long>>( this->node, vector<long long>(this->node, this->initial_value)); } void initializeAdjacencyMatrix(const long long init) { setInitialValue(init); initializeAdjacencyMatrix(); } void initializeEdgeVector() { this->edge = vector<vector<Edge>>(this->node); } void updateAdjacencyMatrix(const long long from, const long long to, const long long distance = 1) { this->adjacency_matrix[from][to] = distance; } void addEdge(const long long from, const long long to, const long long distance = 1) { this->edge[from].push_back({to, distance}); } // O(V^3) // CAUTION: Use adjacency matrix vector<vector<long long>> runFloydWarshall() const { vector<vector<long long>> ret(this->adjacency_matrix); for (long long i = 0; i < this->node; i++) { for (long long j = 0; j < this->node; j++) { for (long long k = 0; k < this->node; k++) { ret[j][k] = min(ret[j][k], ret[j][i] + ret[i][k]); } } } return ret; } // O(E) // CAUTION: Non-weighted only // CAUTION: Use edge vector long long runBFS(const long long from, const long long to) const { vector<bool> visited(this->node, false); queue<long long> q; q.push(from); for (long long i = 1; i <= this->node && !q.empty(); i++) { queue<long long> tmp; while (!q.empty()) { for (Edge e : this->edge[q.front()]) { if (e.to == to) { return i; } if (visited[e.to]) { continue; } visited[e.to] = true; tmp.push(e.to); } q.pop(); } q = tmp; } return this->initial_value; } // O(VE) // CAUTION: Use edge vector vector<long long> runBellmanFord(const long long from) const { vector<long long> distance(this->node, this->initial_value); distance[from] = 0; for (long long i = 0; i < this->node - 1; i++) { for (long long j = 1; j < this->node; j++) { for (auto itr = this->edge[j].begin(); itr != this->edge[j].end(); itr++) { if (distance[itr->to] > distance[j] + itr->distance) { distance[itr->to] = distance[j] + itr->distance; } } } } for (long long i = 1; i < this->node; i++) { for (auto itr = this->edge[i].begin(); itr != this->edge[i].end(); itr++) { if (distance[itr->to] > distance[i] + itr->distance) { distance[0]--; } } } return distance; } long long runModifiedBellmanFord(const long long from) const { vector<long long> distance(this->node, this->initial_value); distance[from] = 0; for (long long i = 0; i < this->node - 1; i++) { for (long long j = 1; j < this->node; j++) { for (auto itr = this->edge[j].begin(); itr != this->edge[j].end(); itr++) { if (distance[itr->to] > distance[j] + itr->distance) { distance[itr->to] = distance[j] + itr->distance; } } } } long long ret = distance.back(); for (long long i = 0; i < 3 * (this->node - 1); i++) { for (long long j = 1; j < this->node; j++) { for (auto itr = this->edge[j].begin(); itr != this->edge[j].end(); itr++) { if (distance[itr->to] > distance[j] + itr->distance) { distance[itr->to] = distance[j] + itr->distance; } } } } if (ret > distance.back()) { return -1; } return max(0ll, -distance.back()); } // O(E + VlogV) // CAUTION: Use edge vector vector<long long> runDijkstra(const long long from) const { vector<long long> distance(this->node, this->initial_value); priority_queue<Edge, vector<Edge>, greater<Edge>> queue; queue.push(Edge(from, 0)); while (!queue.empty()) { long long d = queue.top().distance; long long to = queue.top().to; queue.pop(); if (distance[to] == this->initial_value) { distance[to] = d; for (auto itr = this->edge[to].begin(); itr != this->edge[to].end(); itr++) { if (distance[itr->to] == this->initial_value) { queue.push({itr->to, itr->distance + d}); } } } } return distance; } // O(ElogV) // CAUTION: Use edge vector long long runPrim() const { vector<bool> is_visited(this->node, false); long long cost = 0; priority_queue<Edge, vector<Edge>, greater<Edge>> queue; queue.push(Edge(1, 0)); while (!queue.empty()) { long long distance = queue.top().distance; long long to = queue.top().to; queue.pop(); if (!is_visited[to]) { cost += distance; is_visited[to] = true; for (auto itr = this->edge[to].begin(); itr != this->edge[to].end(); itr++) { queue.push({itr->to, itr->distance}); } } } return cost; } long long runKruskal() {} }; int main() { long long N, M, P; cin >> N >> M >> P; Graph g(N); long long A, B, C; for (long long i = 0; i < M; i++) { cin >> A >> B >> C; g.addEdge(A, B, -(C - P)); } cout << g.runModifiedBellmanFord(1) << endl; }
#include <bits/stdc++.h> using namespace std; class Graph { public: struct Edge { long long to; long long distance; Edge(const long long t, const long long d) { this->to = t; this->distance = d; } bool operator<(const Edge &e) const { return this->distance < e.distance; } bool operator<=(const Edge &e) const { return this->distance <= e.distance; } bool operator>(const Edge &e) const { return this->distance > e.distance; } bool operator>=(const Edge &e) const { return this->distance >= e.distance; } bool operator==(const Edge &e) const { return this->distance == e.distance; } }; vector<vector<long long>> adjacency_matrix; long long node; long long initial_value; vector<vector<Edge>> edge; Graph(const long long N) { setNode(N); initializeEdgeVector(); } Graph(const long long N, const long long init) { setNode(N); initializeEdgeVector(); setInitialValue(init); } void setNode(const long long N) { this->node = N + 1; } void setInitialValue(const long long init) { this->initial_value = init; } void initializeAdjacencyMatrix() { this->adjacency_matrix = vector<vector<long long>>( this->node, vector<long long>(this->node, this->initial_value)); } void initializeAdjacencyMatrix(const long long init) { setInitialValue(init); initializeAdjacencyMatrix(); } void initializeEdgeVector() { this->edge = vector<vector<Edge>>(this->node); } void updateAdjacencyMatrix(const long long from, const long long to, const long long distance = 1) { this->adjacency_matrix[from][to] = distance; } void addEdge(const long long from, const long long to, const long long distance = 1) { this->edge[from].push_back({to, distance}); } // O(V^3) // CAUTION: Use adjacency matrix vector<vector<long long>> runFloydWarshall() const { vector<vector<long long>> ret(this->adjacency_matrix); for (long long i = 0; i < this->node; i++) { for (long long j = 0; j < this->node; j++) { for (long long k = 0; k < this->node; k++) { ret[j][k] = min(ret[j][k], ret[j][i] + ret[i][k]); } } } return ret; } // O(E) // CAUTION: Non-weighted only // CAUTION: Use edge vector long long runBFS(const long long from, const long long to) const { vector<bool> visited(this->node, false); queue<long long> q; q.push(from); for (long long i = 1; i <= this->node && !q.empty(); i++) { queue<long long> tmp; while (!q.empty()) { for (Edge e : this->edge[q.front()]) { if (e.to == to) { return i; } if (visited[e.to]) { continue; } visited[e.to] = true; tmp.push(e.to); } q.pop(); } q = tmp; } return this->initial_value; } // O(VE) // CAUTION: Use edge vector vector<long long> runBellmanFord(const long long from) const { vector<long long> distance(this->node, this->initial_value); distance[from] = 0; for (long long i = 0; i < this->node - 1; i++) { for (long long j = 1; j < this->node; j++) { for (auto itr = this->edge[j].begin(); itr != this->edge[j].end(); itr++) { if (distance[itr->to] > distance[j] + itr->distance) { distance[itr->to] = distance[j] + itr->distance; } } } } for (long long i = 1; i < this->node; i++) { for (auto itr = this->edge[i].begin(); itr != this->edge[i].end(); itr++) { if (distance[itr->to] > distance[i] + itr->distance) { distance[0]--; } } } return distance; } long long runModifiedBellmanFord(const long long from) const { vector<long long> distance(this->node, this->initial_value); distance[from] = 0; for (long long i = 0; i < this->node - 1; i++) { for (long long j = 1; j < this->node; j++) { for (auto itr = this->edge[j].begin(); itr != this->edge[j].end(); itr++) { if (distance[itr->to] > distance[j] + itr->distance) { distance[itr->to] = distance[j] + itr->distance; } } } } long long ret = distance.back(); for (long long i = 0; i < 3 * (this->node - 1); i++) { for (long long j = 1; j < this->node; j++) { for (auto itr = this->edge[j].begin(); itr != this->edge[j].end(); itr++) { if (distance[itr->to] > distance[j] + itr->distance) { distance[itr->to] = distance[j] + itr->distance; } } } } if (ret > distance.back()) { return -1; } return max(0ll, -distance.back()); } // O(E + VlogV) // CAUTION: Use edge vector vector<long long> runDijkstra(const long long from) const { vector<long long> distance(this->node, this->initial_value); priority_queue<Edge, vector<Edge>, greater<Edge>> queue; queue.push(Edge(from, 0)); while (!queue.empty()) { long long d = queue.top().distance; long long to = queue.top().to; queue.pop(); if (distance[to] == this->initial_value) { distance[to] = d; for (auto itr = this->edge[to].begin(); itr != this->edge[to].end(); itr++) { if (distance[itr->to] == this->initial_value) { queue.push({itr->to, itr->distance + d}); } } } } return distance; } // O(ElogV) // CAUTION: Use edge vector long long runPrim() const { vector<bool> is_visited(this->node, false); long long cost = 0; priority_queue<Edge, vector<Edge>, greater<Edge>> queue; queue.push(Edge(1, 0)); while (!queue.empty()) { long long distance = queue.top().distance; long long to = queue.top().to; queue.pop(); if (!is_visited[to]) { cost += distance; is_visited[to] = true; for (auto itr = this->edge[to].begin(); itr != this->edge[to].end(); itr++) { queue.push({itr->to, itr->distance}); } } } return cost; } long long runKruskal() {} }; int main() { long long N, M, P; cin >> N >> M >> P; Graph g(N, 1e15); long long A, B, C; for (long long i = 0; i < M; i++) { cin >> A >> B >> C; g.addEdge(A, B, -(C - P)); } cout << g.runModifiedBellmanFord(1) << endl; }
[ "call.arguments.add" ]
753,888
753,889
u618697411
cpp
p02949
/*vvv> zzzzzI .---. zzuzuI .vgggg&,. +++++= dAC:|I .WbbWo JMM9^```?TMB` ..&gNNg,. gggggggJ, qgggggggg] (&&&&&&&&[ c+OA&J, (&&&&&&+J, .cJeAA&-. (&&&&&&&&x .&AA&=-. +++++= dTqk|I Xpbpbp JM#` (M#^ ?MMp MM| +TMN. JMF ' |yk ` dVY 7Vk, Vy XV cVf ?Y! JM V$ ` +++++= dcf:|I Xppppp dMN .MM+ .MM MM| MM] JMMMMMM+ |@tqkoh) ,y0 (V$ yyyyyyyV7 VV JMWyZWr TWVVVVW&, ++++++ d7qk|0 Xppppp ^HMN, _.db WMm, .MMF MM| ..MM` JMF . |yk .WV&. .XW' yy 4yn. jyn +. JM #S `++++` ?ZZZX= ?WWWW= -THMMMMH9^ (TMMMMM9! MMMMMMM"" JMMMMMMMME |UU. ?TUUUUY= UU. (UU- ^7TUUUV7! JUUUUUUUU 7TUNKO*/ // Ricty Diminished #include "bits/stdc++.h" using namespace std; typedef long long lint; typedef vector<lint> liv; //#define rep(i,n) for(int i=0;i<n;++i) #define all(v) v.begin(), v.end() #define pb push_back #define _vcppunko4(tuple) _getname4 tuple #define _getname4(_1, _2, _3, _4, name, ...) name #define _getname3(_1, _2, _3, name, ...) name #define _trep2(tuple) _rep2 tuple #define _trep3(tuple) _rep3 tuple #define _trep4(tuple) _rep4 tuple #define _rep1(n) for (lint i = 0; i < n; ++i) #define _rep2(i, n) for (lint i = 0; i < n; ++i) #define _rep3(i, a, b) for (lint i = a; i < b; ++i) #define _rep4(i, a, b, c) for (lint i = a; i < b; i += c) #define _trrep2(tuple) _rrep2 tuple #define _trrep3(tuple) _rrep3 tuple #define _trrep4(tuple) _rrep4 tuple #define _rrep1(n) for (lint i = n - 1; i >= 0; --i) #define _rrep2(i, n) for (lint i = n - 1; i >= 0; --i) #define _rrep3(i, a, b) for (lint i = b - 1; i >= a; --i) #define _rrep4(i, a, b, c) \ for (lint i = a + (b - a - 1) / c * c; i >= a; i -= c) template <class T> istream &operator>>(istream &is, vector<T> &vec); template <class T, size_t size> istream &operator>>(istream &is, array<T, size> &vec); template <class T, class L> istream &operator>>(istream &is, pair<T, L> &p); template <class T> ostream &operator<<(ostream &os, vector<T> &vec); template <class T, class L> ostream &operator<<(ostream &os, pair<T, L> &p); template <class T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <class T, class L> istream &operator>>(istream &is, pair<T, L> &p) { is >> p.first; is >> p.second; return is; } // template<class T> // ostream& operator<<(ostream& os,vector<T>& vec){ // os<<vec[0];rep(i,1,vec.size())os<<' '<<vec[i];return os; } template<class T> // ostream& operator<<(ostream& os,deque<T>& deq){ // os<<deq[0];rep(i,1,deq.size())os<<' '<<deq[i];return os; } template <class T, class L> ostream &operator<<(ostream &os, pair<T, L> &p) { os << p.first << " " << p.second; return os; } inline void in() {} template <class Head, class... Tail> inline void in(Head &&head, Tail &&...tail) { cin >> head; in(move(tail)...); } template <class T> inline bool out(T t) { cout << t << '\n'; return 0; } inline bool out() { cout << '\n'; return 0; } template <class Head, class... Tail> inline bool out(Head head, Tail... tail) { cout << head << ' '; out(move(tail)...); return 0; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } // http://beet-aizu.hatenablog.com/entry/2018/04/08/145516 #define rep(...) \ _vcppunko4((__VA_ARGS__, _trep4, _trep3, _trep2, _rep1))((__VA_ARGS__)) #define rrep(...) \ _vcppunko4((__VA_ARGS__, _trrep4, _trrep3, _trrep2, _rrep1))((__VA_ARGS__)) #define each(v) for (auto &i : v) #define lin(...) \ lint __VA_ARGS__; \ in(__VA_ARGS__) #define stin(...) \ string __VA_ARGS__; \ in(__VA_ARGS__) #define vin(type, name, size) \ vector<type> name(size); \ in(name) #define fi e.first #define se e.second #define YES(c) cout << ((c) ? "YES\n" : "NO\n"), 0 #define Yes(c) cout << ((c) ? "Yes\n" : "No\n"), 0 #define o(p) cout << p << endl, 0 #define sp(p) cout << p << " " #define deb(p) cerr << p << endl, 0 #define dd(n) cout << fixed << setprecision(n) #define linf 1152921504606846976 #define MAXN 200100 #define md_1e9_7 1000000007 #define md_998244353 998244353 #define mod md_1e9_7 #define inf linf // INT_MAX // mint #define md_tmp template <uint_fast64_t md = 1000000007> md_tmp class mint { using u64 = uint_fast64_t; public: u64 a; constexpr mint(const u64 x = 0) noexcept : a(x % md) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr mint operator+(const mint rhs) const noexcept { return mint(*this) += rhs; } constexpr mint operator-(const mint rhs) const noexcept { return mint(*this) -= rhs; } constexpr mint operator*(const mint rhs) const noexcept { return mint(*this) *= rhs; } constexpr mint operator^(const lint rhs) const noexcept { return mint(*this) ^= rhs; } constexpr mint operator/(const mint rhs) const noexcept { return mint(*this) /= rhs; } constexpr mint &operator+=(const mint rhs) noexcept { a += rhs.a; if (a >= md) a -= md; return *this; } constexpr mint &operator-=(const mint rhs) noexcept { if (a < rhs.a) a += md; a -= rhs.a; return *this; } constexpr mint &operator*=(const mint rhs) noexcept { a = a * rhs.a % md; return *this; } constexpr mint &operator^=(const lint rhs) noexcept { if (!rhs) return *this = 1; u64 exp = rhs - 1; mint base = this->a; while (exp) { if (exp & 1) *this *= base; base *= base; exp >>= 1; } return *this; } constexpr mint &operator/=(const mint rhs) noexcept { a = (*this * (rhs ^ (md - 2))).a; return *this; } }; md_tmp istream &operator>>(istream &os, mint<md> &m) { os >> m.a, m.a %= md; return os; } md_tmp ostream &operator<<(ostream &os, const mint<md> &m) { return os << m.a; } md_tmp mint<md> ncr(lint n, lint r) { if (n < r || n < 0 || r < 0) return mint<md>(0); mint<md> ncr_res = 1, ncr_div = 1; rep(r) ncr_res *= (n - i), ncr_div *= (r - i); return ncr_res / ncr_div; } // mint<> operator""m(unsigned long long n){ return mint<>(n); } // mint<998244353> operator""m9(unsigned long long n){ return // mint<998244353>(n); } mint<1000003> operator""m3(unsigned long long n){ return // mint<1000003>(n); } using mi = mint<>; // P class P { public: lint x, y; }; istream &operator>>(istream &os, P &p) { os >> p.x >> p.y; return os; } bool operator<(P &l, P &r) { return (l.x - r.x ? l.x < r.x : l.y < r.y); } bool operator>(P &l, P &r) { return (l.x - r.x ? l.x > r.x : l.y > r.y); } class co : public P { public: constexpr co() noexcept : P({0, 0}) {} constexpr co(lint x, lint y) noexcept : P({x, y}) {} // constexpr const lint &value() const noexcept{ return x*x+y*y; } constexpr co operator-() const noexcept { return *this * -1; } constexpr bool operator==(const co rhs) const noexcept { return x == rhs.x && y == rhs.y; } constexpr bool operator!=(const co rhs) const noexcept { return x != rhs.x && y != rhs.y; } constexpr co operator+(const co rhs) const noexcept { return co(*this) += rhs; } constexpr co operator-(const co rhs) const noexcept { return co(*this) -= rhs; } constexpr co operator*(const lint rhs) const noexcept { return co(*this) *= rhs; } constexpr double operator/(const co rhs) const noexcept { if (!x && !y) return 0; if (!rhs.x && !rhs.y) return 101010.10101; if (!(x * rhs.y) ^ !(y * rhs.x)) return 101010.10101; return (x * rhs.y - y * rhs.x ? 101010.10101 : (!rhs.x ? y / rhs.y : x / rhs.x)); } constexpr co &operator+=(const co rhs) noexcept { x += rhs.x; y += rhs.y; return *this; } constexpr co &operator-=(const co rhs) noexcept { x -= rhs.x; y -= rhs.y; return *this; } constexpr co &operator*=(const lint rhs) noexcept { x *= rhs; y *= rhs; return *this; } }; struct edge { lint from, to, cost; }; vector<vector<edge>> g; vector<edge> edges; int n, m, p; lint d[MAXN]; bool bellman_ford(int start, int goal) { //ゴールまでの経路に負の閉路があるか rep(n) d[i] = inf; d[start] = 0; rep(n) { rep(j, m) { edge now = edges[j]; if (d[now.from] != inf && d[now.to] > d[now.from] + now.cost) { d[now.to] = d[now.from] + now.cost; if (i >= n - 1 && now.to == goal) { //全体で負の閉路があるかどうかだったら、==を消す return 1; } if (i >= n - 1) { d[now.to] = -inf; } } } } return 0; } int main() { in(n, m, p); lint a, b, c; g.resize(n); rep(m) { in(a, b, c); --a, --b; g[a].pb({a, b, p - c}); edges.pb({a, b, p - c}); } if (bellman_ford(0, n - 1)) o(-1); else o(max(0ll, -d[n - 1])); } // sub-EOF
/*vvv> zzzzzI .---. zzuzuI .vgggg&,. +++++= dAC:|I .WbbWo JMM9^```?TMB` ..&gNNg,. gggggggJ, qgggggggg] (&&&&&&&&[ c+OA&J, (&&&&&&+J, .cJeAA&-. (&&&&&&&&x .&AA&=-. +++++= dTqk|I Xpbpbp JM#` (M#^ ?MMp MM| +TMN. JMF ' |yk ` dVY 7Vk, Vy XV cVf ?Y! JM V$ ` +++++= dcf:|I Xppppp dMN .MM+ .MM MM| MM] JMMMMMM+ |@tqkoh) ,y0 (V$ yyyyyyyV7 VV JMWyZWr TWVVVVW&, ++++++ d7qk|0 Xppppp ^HMN, _.db WMm, .MMF MM| ..MM` JMF . |yk .WV&. .XW' yy 4yn. jyn +. JM #S `++++` ?ZZZX= ?WWWW= -THMMMMH9^ (TMMMMM9! MMMMMMM"" JMMMMMMMME |UU. ?TUUUUY= UU. (UU- ^7TUUUV7! JUUUUUUUU 7TUNKO*/ // Ricty Diminished #include "bits/stdc++.h" using namespace std; typedef long long lint; typedef vector<lint> liv; //#define rep(i,n) for(int i=0;i<n;++i) #define all(v) v.begin(), v.end() #define pb push_back #define _vcppunko4(tuple) _getname4 tuple #define _getname4(_1, _2, _3, _4, name, ...) name #define _getname3(_1, _2, _3, name, ...) name #define _trep2(tuple) _rep2 tuple #define _trep3(tuple) _rep3 tuple #define _trep4(tuple) _rep4 tuple #define _rep1(n) for (lint i = 0; i < n; ++i) #define _rep2(i, n) for (lint i = 0; i < n; ++i) #define _rep3(i, a, b) for (lint i = a; i < b; ++i) #define _rep4(i, a, b, c) for (lint i = a; i < b; i += c) #define _trrep2(tuple) _rrep2 tuple #define _trrep3(tuple) _rrep3 tuple #define _trrep4(tuple) _rrep4 tuple #define _rrep1(n) for (lint i = n - 1; i >= 0; --i) #define _rrep2(i, n) for (lint i = n - 1; i >= 0; --i) #define _rrep3(i, a, b) for (lint i = b - 1; i >= a; --i) #define _rrep4(i, a, b, c) \ for (lint i = a + (b - a - 1) / c * c; i >= a; i -= c) template <class T> istream &operator>>(istream &is, vector<T> &vec); template <class T, size_t size> istream &operator>>(istream &is, array<T, size> &vec); template <class T, class L> istream &operator>>(istream &is, pair<T, L> &p); template <class T> ostream &operator<<(ostream &os, vector<T> &vec); template <class T, class L> ostream &operator<<(ostream &os, pair<T, L> &p); template <class T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <class T, class L> istream &operator>>(istream &is, pair<T, L> &p) { is >> p.first; is >> p.second; return is; } // template<class T> // ostream& operator<<(ostream& os,vector<T>& vec){ // os<<vec[0];rep(i,1,vec.size())os<<' '<<vec[i];return os; } template<class T> // ostream& operator<<(ostream& os,deque<T>& deq){ // os<<deq[0];rep(i,1,deq.size())os<<' '<<deq[i];return os; } template <class T, class L> ostream &operator<<(ostream &os, pair<T, L> &p) { os << p.first << " " << p.second; return os; } inline void in() {} template <class Head, class... Tail> inline void in(Head &&head, Tail &&...tail) { cin >> head; in(move(tail)...); } template <class T> inline bool out(T t) { cout << t << '\n'; return 0; } inline bool out() { cout << '\n'; return 0; } template <class Head, class... Tail> inline bool out(Head head, Tail... tail) { cout << head << ' '; out(move(tail)...); return 0; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } // http://beet-aizu.hatenablog.com/entry/2018/04/08/145516 #define rep(...) \ _vcppunko4((__VA_ARGS__, _trep4, _trep3, _trep2, _rep1))((__VA_ARGS__)) #define rrep(...) \ _vcppunko4((__VA_ARGS__, _trrep4, _trrep3, _trrep2, _rrep1))((__VA_ARGS__)) #define each(v) for (auto &i : v) #define lin(...) \ lint __VA_ARGS__; \ in(__VA_ARGS__) #define stin(...) \ string __VA_ARGS__; \ in(__VA_ARGS__) #define vin(type, name, size) \ vector<type> name(size); \ in(name) #define fi e.first #define se e.second #define YES(c) cout << ((c) ? "YES\n" : "NO\n"), 0 #define Yes(c) cout << ((c) ? "Yes\n" : "No\n"), 0 #define o(p) cout << p << endl, 0 #define sp(p) cout << p << " " #define deb(p) cerr << p << endl, 0 #define dd(n) cout << fixed << setprecision(n) #define linf 1152921504606846976 #define MAXN 200100 #define md_1e9_7 1000000007 #define md_998244353 998244353 #define mod md_1e9_7 #define inf linf // INT_MAX // mint #define md_tmp template <uint_fast64_t md = 1000000007> md_tmp class mint { using u64 = uint_fast64_t; public: u64 a; constexpr mint(const u64 x = 0) noexcept : a(x % md) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr mint operator+(const mint rhs) const noexcept { return mint(*this) += rhs; } constexpr mint operator-(const mint rhs) const noexcept { return mint(*this) -= rhs; } constexpr mint operator*(const mint rhs) const noexcept { return mint(*this) *= rhs; } constexpr mint operator^(const lint rhs) const noexcept { return mint(*this) ^= rhs; } constexpr mint operator/(const mint rhs) const noexcept { return mint(*this) /= rhs; } constexpr mint &operator+=(const mint rhs) noexcept { a += rhs.a; if (a >= md) a -= md; return *this; } constexpr mint &operator-=(const mint rhs) noexcept { if (a < rhs.a) a += md; a -= rhs.a; return *this; } constexpr mint &operator*=(const mint rhs) noexcept { a = a * rhs.a % md; return *this; } constexpr mint &operator^=(const lint rhs) noexcept { if (!rhs) return *this = 1; u64 exp = rhs - 1; mint base = this->a; while (exp) { if (exp & 1) *this *= base; base *= base; exp >>= 1; } return *this; } constexpr mint &operator/=(const mint rhs) noexcept { a = (*this * (rhs ^ (md - 2))).a; return *this; } }; md_tmp istream &operator>>(istream &os, mint<md> &m) { os >> m.a, m.a %= md; return os; } md_tmp ostream &operator<<(ostream &os, const mint<md> &m) { return os << m.a; } md_tmp mint<md> ncr(lint n, lint r) { if (n < r || n < 0 || r < 0) return mint<md>(0); mint<md> ncr_res = 1, ncr_div = 1; rep(r) ncr_res *= (n - i), ncr_div *= (r - i); return ncr_res / ncr_div; } // mint<> operator""m(unsigned long long n){ return mint<>(n); } // mint<998244353> operator""m9(unsigned long long n){ return // mint<998244353>(n); } mint<1000003> operator""m3(unsigned long long n){ return // mint<1000003>(n); } using mi = mint<>; // P class P { public: lint x, y; }; istream &operator>>(istream &os, P &p) { os >> p.x >> p.y; return os; } bool operator<(P &l, P &r) { return (l.x - r.x ? l.x < r.x : l.y < r.y); } bool operator>(P &l, P &r) { return (l.x - r.x ? l.x > r.x : l.y > r.y); } class co : public P { public: constexpr co() noexcept : P({0, 0}) {} constexpr co(lint x, lint y) noexcept : P({x, y}) {} // constexpr const lint &value() const noexcept{ return x*x+y*y; } constexpr co operator-() const noexcept { return *this * -1; } constexpr bool operator==(const co rhs) const noexcept { return x == rhs.x && y == rhs.y; } constexpr bool operator!=(const co rhs) const noexcept { return x != rhs.x && y != rhs.y; } constexpr co operator+(const co rhs) const noexcept { return co(*this) += rhs; } constexpr co operator-(const co rhs) const noexcept { return co(*this) -= rhs; } constexpr co operator*(const lint rhs) const noexcept { return co(*this) *= rhs; } constexpr double operator/(const co rhs) const noexcept { if (!x && !y) return 0; if (!rhs.x && !rhs.y) return 101010.10101; if (!(x * rhs.y) ^ !(y * rhs.x)) return 101010.10101; return (x * rhs.y - y * rhs.x ? 101010.10101 : (!rhs.x ? y / rhs.y : x / rhs.x)); } constexpr co &operator+=(const co rhs) noexcept { x += rhs.x; y += rhs.y; return *this; } constexpr co &operator-=(const co rhs) noexcept { x -= rhs.x; y -= rhs.y; return *this; } constexpr co &operator*=(const lint rhs) noexcept { x *= rhs; y *= rhs; return *this; } }; struct edge { lint from, to, cost; }; vector<vector<edge>> g; vector<edge> edges; int n, m, p; lint d[MAXN]; bool bellman_ford(int start, int goal) { //ゴールまでの経路に負の閉路があるか rep(n) d[i] = inf; d[start] = 0; rep(2 * n) { rep(j, m) { edge now = edges[j]; if (d[now.from] != inf && d[now.to] > d[now.from] + now.cost) { d[now.to] = d[now.from] + now.cost; if (i >= n - 1 && now.to == goal) { //全体で負の閉路があるかどうかだったら、==を消す return 1; } if (i >= n - 1) { d[now.to] = -inf; } } } } return 0; } int main() { in(n, m, p); lint a, b, c; g.resize(n); rep(m) { in(a, b, c); --a, --b; g[a].pb({a, b, p - c}); edges.pb({a, b, p - c}); } if (bellman_ford(0, n - 1)) o(-1); else o(max(0ll, -d[n - 1])); } // sub-EOF
[ "expression.operation.binary.add" ]
753,895
753,896
u675296835
cpp
p02949
/*vvv> zzzzzI .---. zzuzuI .vgggg&,. +++++= dAC:|I .WbbWo JMM9^```?TMB` ..&gNNg,. gggggggJ, qgggggggg] (&&&&&&&&[ c+OA&J, (&&&&&&+J, .cJeAA&-. (&&&&&&&&x .&AA&=-. +++++= dTqk|I Xpbpbp JM#` (M#^ ?MMp MM| +TMN. JMF ' |yk ` dVY 7Vk, Vy XV cVf ?Y! JM V$ ` +++++= dcf:|I Xppppp dMN .MM+ .MM MM| MM] JMMMMMM+ |@tqkoh) ,y0 (V$ yyyyyyyV7 VV JMWyZWr TWVVVVW&, ++++++ d7qk|0 Xppppp ^HMN, _.db WMm, .MMF MM| ..MM` JMF . |yk .WV&. .XW' yy 4yn. jyn +. JM #S `++++` ?ZZZX= ?WWWW= -THMMMMH9^ (TMMMMM9! MMMMMMM"" JMMMMMMMME |UU. ?TUUUUY= UU. (UU- ^7TUUUV7! JUUUUUUUU 7TUNKO*/ // Ricty Diminished #include "bits/stdc++.h" using namespace std; typedef long long lint; typedef vector<lint> liv; //#define rep(i,n) for(int i=0;i<n;++i) #define all(v) v.begin(), v.end() #define pb push_back #define _vcppunko4(tuple) _getname4 tuple #define _getname4(_1, _2, _3, _4, name, ...) name #define _getname3(_1, _2, _3, name, ...) name #define _trep2(tuple) _rep2 tuple #define _trep3(tuple) _rep3 tuple #define _trep4(tuple) _rep4 tuple #define _rep1(n) for (lint i = 0; i < n; ++i) #define _rep2(i, n) for (lint i = 0; i < n; ++i) #define _rep3(i, a, b) for (lint i = a; i < b; ++i) #define _rep4(i, a, b, c) for (lint i = a; i < b; i += c) #define _trrep2(tuple) _rrep2 tuple #define _trrep3(tuple) _rrep3 tuple #define _trrep4(tuple) _rrep4 tuple #define _rrep1(n) for (lint i = n - 1; i >= 0; --i) #define _rrep2(i, n) for (lint i = n - 1; i >= 0; --i) #define _rrep3(i, a, b) for (lint i = b - 1; i >= a; --i) #define _rrep4(i, a, b, c) \ for (lint i = a + (b - a - 1) / c * c; i >= a; i -= c) template <class T> istream &operator>>(istream &is, vector<T> &vec); template <class T, size_t size> istream &operator>>(istream &is, array<T, size> &vec); template <class T, class L> istream &operator>>(istream &is, pair<T, L> &p); template <class T> ostream &operator<<(ostream &os, vector<T> &vec); template <class T, class L> ostream &operator<<(ostream &os, pair<T, L> &p); template <class T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <class T, class L> istream &operator>>(istream &is, pair<T, L> &p) { is >> p.first; is >> p.second; return is; } // template<class T> // ostream& operator<<(ostream& os,vector<T>& vec){ // os<<vec[0];rep(i,1,vec.size())os<<' '<<vec[i];return os; } template<class T> // ostream& operator<<(ostream& os,deque<T>& deq){ // os<<deq[0];rep(i,1,deq.size())os<<' '<<deq[i];return os; } template <class T, class L> ostream &operator<<(ostream &os, pair<T, L> &p) { os << p.first << " " << p.second; return os; } inline void in() {} template <class Head, class... Tail> inline void in(Head &&head, Tail &&...tail) { cin >> head; in(move(tail)...); } template <class T> inline bool out(T t) { cout << t << '\n'; return 0; } inline bool out() { cout << '\n'; return 0; } template <class Head, class... Tail> inline bool out(Head head, Tail... tail) { cout << head << ' '; out(move(tail)...); return 0; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } // http://beet-aizu.hatenablog.com/entry/2018/04/08/145516 #define rep(...) \ _vcppunko4((__VA_ARGS__, _trep4, _trep3, _trep2, _rep1))((__VA_ARGS__)) #define rrep(...) \ _vcppunko4((__VA_ARGS__, _trrep4, _trrep3, _trrep2, _rrep1))((__VA_ARGS__)) #define each(v) for (auto &i : v) #define lin(...) \ lint __VA_ARGS__; \ in(__VA_ARGS__) #define stin(...) \ string __VA_ARGS__; \ in(__VA_ARGS__) #define vin(type, name, size) \ vector<type> name(size); \ in(name) #define fi e.first #define se e.second #define YES(c) cout << ((c) ? "YES\n" : "NO\n"), 0 #define Yes(c) cout << ((c) ? "Yes\n" : "No\n"), 0 #define o(p) cout << p << endl, 0 #define sp(p) cout << p << " " #define deb(p) cerr << p << endl, 0 #define dd(n) cout << fixed << setprecision(n) #define linf 1152921504606846976 #define MAXN 200100 #define md_1e9_7 1000000007 #define md_998244353 998244353 #define mod md_1e9_7 #define inf linf // INT_MAX // mint #define md_tmp template <uint_fast64_t md = 1000000007> md_tmp class mint { using u64 = uint_fast64_t; public: u64 a; constexpr mint(const u64 x = 0) noexcept : a(x % md) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr mint operator+(const mint rhs) const noexcept { return mint(*this) += rhs; } constexpr mint operator-(const mint rhs) const noexcept { return mint(*this) -= rhs; } constexpr mint operator*(const mint rhs) const noexcept { return mint(*this) *= rhs; } constexpr mint operator^(const lint rhs) const noexcept { return mint(*this) ^= rhs; } constexpr mint operator/(const mint rhs) const noexcept { return mint(*this) /= rhs; } constexpr mint &operator+=(const mint rhs) noexcept { a += rhs.a; if (a >= md) a -= md; return *this; } constexpr mint &operator-=(const mint rhs) noexcept { if (a < rhs.a) a += md; a -= rhs.a; return *this; } constexpr mint &operator*=(const mint rhs) noexcept { a = a * rhs.a % md; return *this; } constexpr mint &operator^=(const lint rhs) noexcept { if (!rhs) return *this = 1; u64 exp = rhs - 1; mint base = this->a; while (exp) { if (exp & 1) *this *= base; base *= base; exp >>= 1; } return *this; } constexpr mint &operator/=(const mint rhs) noexcept { a = (*this * (rhs ^ (md - 2))).a; return *this; } }; md_tmp istream &operator>>(istream &os, mint<md> &m) { os >> m.a, m.a %= md; return os; } md_tmp ostream &operator<<(ostream &os, const mint<md> &m) { return os << m.a; } md_tmp mint<md> ncr(lint n, lint r) { if (n < r || n < 0 || r < 0) return mint<md>(0); mint<md> ncr_res = 1, ncr_div = 1; rep(r) ncr_res *= (n - i), ncr_div *= (r - i); return ncr_res / ncr_div; } // mint<> operator""m(unsigned long long n){ return mint<>(n); } // mint<998244353> operator""m9(unsigned long long n){ return // mint<998244353>(n); } mint<1000003> operator""m3(unsigned long long n){ return // mint<1000003>(n); } using mi = mint<>; // P class P { public: lint x, y; }; istream &operator>>(istream &os, P &p) { os >> p.x >> p.y; return os; } bool operator<(P &l, P &r) { return (l.x - r.x ? l.x < r.x : l.y < r.y); } bool operator>(P &l, P &r) { return (l.x - r.x ? l.x > r.x : l.y > r.y); } class co : public P { public: constexpr co() noexcept : P({0, 0}) {} constexpr co(lint x, lint y) noexcept : P({x, y}) {} // constexpr const lint &value() const noexcept{ return x*x+y*y; } constexpr co operator-() const noexcept { return *this * -1; } constexpr bool operator==(const co rhs) const noexcept { return x == rhs.x && y == rhs.y; } constexpr bool operator!=(const co rhs) const noexcept { return x != rhs.x && y != rhs.y; } constexpr co operator+(const co rhs) const noexcept { return co(*this) += rhs; } constexpr co operator-(const co rhs) const noexcept { return co(*this) -= rhs; } constexpr co operator*(const lint rhs) const noexcept { return co(*this) *= rhs; } constexpr double operator/(const co rhs) const noexcept { if (!x && !y) return 0; if (!rhs.x && !rhs.y) return 101010.10101; if (!(x * rhs.y) ^ !(y * rhs.x)) return 101010.10101; return (x * rhs.y - y * rhs.x ? 101010.10101 : (!rhs.x ? y / rhs.y : x / rhs.x)); } constexpr co &operator+=(const co rhs) noexcept { x += rhs.x; y += rhs.y; return *this; } constexpr co &operator-=(const co rhs) noexcept { x -= rhs.x; y -= rhs.y; return *this; } constexpr co &operator*=(const lint rhs) noexcept { x *= rhs; y *= rhs; return *this; } }; struct edge { lint from, to, cost; }; vector<vector<edge>> g; vector<edge> edges; int n, m, p; lint d[MAXN]; bool bellman_ford(int start, int goal) { //ゴールまでの経路に負の閉路があるか rep(n) d[i] = inf; d[start] = 0; rep(2 * n) { rep(j, m) { edge now = edges[j]; if (d[now.from] != inf && d[now.to] > d[now.from] + now.cost) { d[now.to] = d[now.from] + now.cost; if (i >= n - 1 && now.to == goal) { //全体で負の閉路があるかどうかだったら、==を消す return 1; } if (i >= n - 1) { d[now.to] = inf; } } } } return 0; } int main() { in(n, m, p); lint a, b, c; g.resize(n); rep(m) { in(a, b, c); --a, --b; g[a].pb({a, b, p - c}); edges.pb({a, b, p - c}); } if (bellman_ford(0, n - 1)) o(-1); else o(max(0ll, -d[n - 1])); } // sub-EOF
/*vvv> zzzzzI .---. zzuzuI .vgggg&,. +++++= dAC:|I .WbbWo JMM9^```?TMB` ..&gNNg,. gggggggJ, qgggggggg] (&&&&&&&&[ c+OA&J, (&&&&&&+J, .cJeAA&-. (&&&&&&&&x .&AA&=-. +++++= dTqk|I Xpbpbp JM#` (M#^ ?MMp MM| +TMN. JMF ' |yk ` dVY 7Vk, Vy XV cVf ?Y! JM V$ ` +++++= dcf:|I Xppppp dMN .MM+ .MM MM| MM] JMMMMMM+ |@tqkoh) ,y0 (V$ yyyyyyyV7 VV JMWyZWr TWVVVVW&, ++++++ d7qk|0 Xppppp ^HMN, _.db WMm, .MMF MM| ..MM` JMF . |yk .WV&. .XW' yy 4yn. jyn +. JM #S `++++` ?ZZZX= ?WWWW= -THMMMMH9^ (TMMMMM9! MMMMMMM"" JMMMMMMMME |UU. ?TUUUUY= UU. (UU- ^7TUUUV7! JUUUUUUUU 7TUNKO*/ // Ricty Diminished #include "bits/stdc++.h" using namespace std; typedef long long lint; typedef vector<lint> liv; //#define rep(i,n) for(int i=0;i<n;++i) #define all(v) v.begin(), v.end() #define pb push_back #define _vcppunko4(tuple) _getname4 tuple #define _getname4(_1, _2, _3, _4, name, ...) name #define _getname3(_1, _2, _3, name, ...) name #define _trep2(tuple) _rep2 tuple #define _trep3(tuple) _rep3 tuple #define _trep4(tuple) _rep4 tuple #define _rep1(n) for (lint i = 0; i < n; ++i) #define _rep2(i, n) for (lint i = 0; i < n; ++i) #define _rep3(i, a, b) for (lint i = a; i < b; ++i) #define _rep4(i, a, b, c) for (lint i = a; i < b; i += c) #define _trrep2(tuple) _rrep2 tuple #define _trrep3(tuple) _rrep3 tuple #define _trrep4(tuple) _rrep4 tuple #define _rrep1(n) for (lint i = n - 1; i >= 0; --i) #define _rrep2(i, n) for (lint i = n - 1; i >= 0; --i) #define _rrep3(i, a, b) for (lint i = b - 1; i >= a; --i) #define _rrep4(i, a, b, c) \ for (lint i = a + (b - a - 1) / c * c; i >= a; i -= c) template <class T> istream &operator>>(istream &is, vector<T> &vec); template <class T, size_t size> istream &operator>>(istream &is, array<T, size> &vec); template <class T, class L> istream &operator>>(istream &is, pair<T, L> &p); template <class T> ostream &operator<<(ostream &os, vector<T> &vec); template <class T, class L> ostream &operator<<(ostream &os, pair<T, L> &p); template <class T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <class T, class L> istream &operator>>(istream &is, pair<T, L> &p) { is >> p.first; is >> p.second; return is; } // template<class T> // ostream& operator<<(ostream& os,vector<T>& vec){ // os<<vec[0];rep(i,1,vec.size())os<<' '<<vec[i];return os; } template<class T> // ostream& operator<<(ostream& os,deque<T>& deq){ // os<<deq[0];rep(i,1,deq.size())os<<' '<<deq[i];return os; } template <class T, class L> ostream &operator<<(ostream &os, pair<T, L> &p) { os << p.first << " " << p.second; return os; } inline void in() {} template <class Head, class... Tail> inline void in(Head &&head, Tail &&...tail) { cin >> head; in(move(tail)...); } template <class T> inline bool out(T t) { cout << t << '\n'; return 0; } inline bool out() { cout << '\n'; return 0; } template <class Head, class... Tail> inline bool out(Head head, Tail... tail) { cout << head << ' '; out(move(tail)...); return 0; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } // http://beet-aizu.hatenablog.com/entry/2018/04/08/145516 #define rep(...) \ _vcppunko4((__VA_ARGS__, _trep4, _trep3, _trep2, _rep1))((__VA_ARGS__)) #define rrep(...) \ _vcppunko4((__VA_ARGS__, _trrep4, _trrep3, _trrep2, _rrep1))((__VA_ARGS__)) #define each(v) for (auto &i : v) #define lin(...) \ lint __VA_ARGS__; \ in(__VA_ARGS__) #define stin(...) \ string __VA_ARGS__; \ in(__VA_ARGS__) #define vin(type, name, size) \ vector<type> name(size); \ in(name) #define fi e.first #define se e.second #define YES(c) cout << ((c) ? "YES\n" : "NO\n"), 0 #define Yes(c) cout << ((c) ? "Yes\n" : "No\n"), 0 #define o(p) cout << p << endl, 0 #define sp(p) cout << p << " " #define deb(p) cerr << p << endl, 0 #define dd(n) cout << fixed << setprecision(n) #define linf 1152921504606846976 #define MAXN 200100 #define md_1e9_7 1000000007 #define md_998244353 998244353 #define mod md_1e9_7 #define inf linf // INT_MAX // mint #define md_tmp template <uint_fast64_t md = 1000000007> md_tmp class mint { using u64 = uint_fast64_t; public: u64 a; constexpr mint(const u64 x = 0) noexcept : a(x % md) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr mint operator+(const mint rhs) const noexcept { return mint(*this) += rhs; } constexpr mint operator-(const mint rhs) const noexcept { return mint(*this) -= rhs; } constexpr mint operator*(const mint rhs) const noexcept { return mint(*this) *= rhs; } constexpr mint operator^(const lint rhs) const noexcept { return mint(*this) ^= rhs; } constexpr mint operator/(const mint rhs) const noexcept { return mint(*this) /= rhs; } constexpr mint &operator+=(const mint rhs) noexcept { a += rhs.a; if (a >= md) a -= md; return *this; } constexpr mint &operator-=(const mint rhs) noexcept { if (a < rhs.a) a += md; a -= rhs.a; return *this; } constexpr mint &operator*=(const mint rhs) noexcept { a = a * rhs.a % md; return *this; } constexpr mint &operator^=(const lint rhs) noexcept { if (!rhs) return *this = 1; u64 exp = rhs - 1; mint base = this->a; while (exp) { if (exp & 1) *this *= base; base *= base; exp >>= 1; } return *this; } constexpr mint &operator/=(const mint rhs) noexcept { a = (*this * (rhs ^ (md - 2))).a; return *this; } }; md_tmp istream &operator>>(istream &os, mint<md> &m) { os >> m.a, m.a %= md; return os; } md_tmp ostream &operator<<(ostream &os, const mint<md> &m) { return os << m.a; } md_tmp mint<md> ncr(lint n, lint r) { if (n < r || n < 0 || r < 0) return mint<md>(0); mint<md> ncr_res = 1, ncr_div = 1; rep(r) ncr_res *= (n - i), ncr_div *= (r - i); return ncr_res / ncr_div; } // mint<> operator""m(unsigned long long n){ return mint<>(n); } // mint<998244353> operator""m9(unsigned long long n){ return // mint<998244353>(n); } mint<1000003> operator""m3(unsigned long long n){ return // mint<1000003>(n); } using mi = mint<>; // P class P { public: lint x, y; }; istream &operator>>(istream &os, P &p) { os >> p.x >> p.y; return os; } bool operator<(P &l, P &r) { return (l.x - r.x ? l.x < r.x : l.y < r.y); } bool operator>(P &l, P &r) { return (l.x - r.x ? l.x > r.x : l.y > r.y); } class co : public P { public: constexpr co() noexcept : P({0, 0}) {} constexpr co(lint x, lint y) noexcept : P({x, y}) {} // constexpr const lint &value() const noexcept{ return x*x+y*y; } constexpr co operator-() const noexcept { return *this * -1; } constexpr bool operator==(const co rhs) const noexcept { return x == rhs.x && y == rhs.y; } constexpr bool operator!=(const co rhs) const noexcept { return x != rhs.x && y != rhs.y; } constexpr co operator+(const co rhs) const noexcept { return co(*this) += rhs; } constexpr co operator-(const co rhs) const noexcept { return co(*this) -= rhs; } constexpr co operator*(const lint rhs) const noexcept { return co(*this) *= rhs; } constexpr double operator/(const co rhs) const noexcept { if (!x && !y) return 0; if (!rhs.x && !rhs.y) return 101010.10101; if (!(x * rhs.y) ^ !(y * rhs.x)) return 101010.10101; return (x * rhs.y - y * rhs.x ? 101010.10101 : (!rhs.x ? y / rhs.y : x / rhs.x)); } constexpr co &operator+=(const co rhs) noexcept { x += rhs.x; y += rhs.y; return *this; } constexpr co &operator-=(const co rhs) noexcept { x -= rhs.x; y -= rhs.y; return *this; } constexpr co &operator*=(const lint rhs) noexcept { x *= rhs; y *= rhs; return *this; } }; struct edge { lint from, to, cost; }; vector<vector<edge>> g; vector<edge> edges; int n, m, p; lint d[MAXN]; bool bellman_ford(int start, int goal) { //ゴールまでの経路に負の閉路があるか rep(n) d[i] = inf; d[start] = 0; rep(2 * n) { rep(j, m) { edge now = edges[j]; if (d[now.from] != inf && d[now.to] > d[now.from] + now.cost) { d[now.to] = d[now.from] + now.cost; if (i >= n - 1 && now.to == goal) { //全体で負の閉路があるかどうかだったら、==を消す return 1; } if (i >= n - 1) { d[now.to] = -inf; } } } } return 0; } int main() { in(n, m, p); lint a, b, c; g.resize(n); rep(m) { in(a, b, c); --a, --b; g[a].pb({a, b, p - c}); edges.pb({a, b, p - c}); } if (bellman_ford(0, n - 1)) o(-1); else o(max(0ll, -d[n - 1])); } // sub-EOF
[ "expression.operation.unary.add" ]
753,897
753,896
u675296835
cpp
p02949
/*vvv> zzzzzI .---. zzuzuI .vgggg&,. +++++= dAC:|I .WbbWo JMM9^```?TMB` ..&gNNg,. gggggggJ, qgggggggg] (&&&&&&&&[ c+OA&J, (&&&&&&+J, .cJeAA&-. (&&&&&&&&x .&AA&=-. +++++= dTqk|I Xpbpbp JM#` (M#^ ?MMp MM| +TMN. JMF ' |yk ` dVY 7Vk, Vy XV cVf ?Y! JM V$ ` +++++= dcf:|I Xppppp dMN .MM+ .MM MM| MM] JMMMMMM+ |@tqkoh) ,y0 (V$ yyyyyyyV7 VV JMWyZWr TWVVVVW&, ++++++ d7qk|0 Xppppp ^HMN, _.db WMm, .MMF MM| ..MM` JMF . |yk .WV&. .XW' yy 4yn. jyn +. JM #S `++++` ?ZZZX= ?WWWW= -THMMMMH9^ (TMMMMM9! MMMMMMM"" JMMMMMMMME |UU. ?TUUUUY= UU. (UU- ^7TUUUV7! JUUUUUUUU 7TUNKO*/ // Ricty Diminished #include "bits/stdc++.h" using namespace std; typedef long long lint; typedef vector<lint> liv; //#define rep(i,n) for(int i=0;i<n;++i) #define all(v) v.begin(), v.end() #define pb push_back #define _vcppunko4(tuple) _getname4 tuple #define _getname4(_1, _2, _3, _4, name, ...) name #define _getname3(_1, _2, _3, name, ...) name #define _trep2(tuple) _rep2 tuple #define _trep3(tuple) _rep3 tuple #define _trep4(tuple) _rep4 tuple #define _rep1(n) for (lint i = 0; i < n; ++i) #define _rep2(i, n) for (lint i = 0; i < n; ++i) #define _rep3(i, a, b) for (lint i = a; i < b; ++i) #define _rep4(i, a, b, c) for (lint i = a; i < b; i += c) #define _trrep2(tuple) _rrep2 tuple #define _trrep3(tuple) _rrep3 tuple #define _trrep4(tuple) _rrep4 tuple #define _rrep1(n) for (lint i = n - 1; i >= 0; --i) #define _rrep2(i, n) for (lint i = n - 1; i >= 0; --i) #define _rrep3(i, a, b) for (lint i = b - 1; i >= a; --i) #define _rrep4(i, a, b, c) \ for (lint i = a + (b - a - 1) / c * c; i >= a; i -= c) template <class T> istream &operator>>(istream &is, vector<T> &vec); template <class T, size_t size> istream &operator>>(istream &is, array<T, size> &vec); template <class T, class L> istream &operator>>(istream &is, pair<T, L> &p); template <class T> ostream &operator<<(ostream &os, vector<T> &vec); template <class T, class L> ostream &operator<<(ostream &os, pair<T, L> &p); template <class T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <class T, class L> istream &operator>>(istream &is, pair<T, L> &p) { is >> p.first; is >> p.second; return is; } // template<class T> // ostream& operator<<(ostream& os,vector<T>& vec){ // os<<vec[0];rep(i,1,vec.size())os<<' '<<vec[i];return os; } template<class T> // ostream& operator<<(ostream& os,deque<T>& deq){ // os<<deq[0];rep(i,1,deq.size())os<<' '<<deq[i];return os; } template <class T, class L> ostream &operator<<(ostream &os, pair<T, L> &p) { os << p.first << " " << p.second; return os; } inline void in() {} template <class Head, class... Tail> inline void in(Head &&head, Tail &&...tail) { cin >> head; in(move(tail)...); } template <class T> inline bool out(T t) { cout << t << '\n'; return 0; } inline bool out() { cout << '\n'; return 0; } template <class Head, class... Tail> inline bool out(Head head, Tail... tail) { cout << head << ' '; out(move(tail)...); return 0; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } // http://beet-aizu.hatenablog.com/entry/2018/04/08/145516 #define rep(...) \ _vcppunko4((__VA_ARGS__, _trep4, _trep3, _trep2, _rep1))((__VA_ARGS__)) #define rrep(...) \ _vcppunko4((__VA_ARGS__, _trrep4, _trrep3, _trrep2, _rrep1))((__VA_ARGS__)) #define each(v) for (auto &i : v) #define lin(...) \ lint __VA_ARGS__; \ in(__VA_ARGS__) #define stin(...) \ string __VA_ARGS__; \ in(__VA_ARGS__) #define vin(type, name, size) \ vector<type> name(size); \ in(name) #define fi e.first #define se e.second #define YES(c) cout << ((c) ? "YES\n" : "NO\n"), 0 #define Yes(c) cout << ((c) ? "Yes\n" : "No\n"), 0 #define o(p) cout << p << endl, 0 #define sp(p) cout << p << " " #define deb(p) cerr << p << endl, 0 #define dd(n) cout << fixed << setprecision(n) #define linf 1152921504606846976 #define MAXN 200100 #define md_1e9_7 1000000007 #define md_998244353 998244353 #define mod md_1e9_7 #define inf linf // INT_MAX // mint #define md_tmp template <uint_fast64_t md = 1000000007> md_tmp class mint { using u64 = uint_fast64_t; public: u64 a; constexpr mint(const u64 x = 0) noexcept : a(x % md) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr mint operator+(const mint rhs) const noexcept { return mint(*this) += rhs; } constexpr mint operator-(const mint rhs) const noexcept { return mint(*this) -= rhs; } constexpr mint operator*(const mint rhs) const noexcept { return mint(*this) *= rhs; } constexpr mint operator^(const lint rhs) const noexcept { return mint(*this) ^= rhs; } constexpr mint operator/(const mint rhs) const noexcept { return mint(*this) /= rhs; } constexpr mint &operator+=(const mint rhs) noexcept { a += rhs.a; if (a >= md) a -= md; return *this; } constexpr mint &operator-=(const mint rhs) noexcept { if (a < rhs.a) a += md; a -= rhs.a; return *this; } constexpr mint &operator*=(const mint rhs) noexcept { a = a * rhs.a % md; return *this; } constexpr mint &operator^=(const lint rhs) noexcept { if (!rhs) return *this = 1; u64 exp = rhs - 1; mint base = this->a; while (exp) { if (exp & 1) *this *= base; base *= base; exp >>= 1; } return *this; } constexpr mint &operator/=(const mint rhs) noexcept { a = (*this * (rhs ^ (md - 2))).a; return *this; } }; md_tmp istream &operator>>(istream &os, mint<md> &m) { os >> m.a, m.a %= md; return os; } md_tmp ostream &operator<<(ostream &os, const mint<md> &m) { return os << m.a; } md_tmp mint<md> ncr(lint n, lint r) { if (n < r || n < 0 || r < 0) return mint<md>(0); mint<md> ncr_res = 1, ncr_div = 1; rep(r) ncr_res *= (n - i), ncr_div *= (r - i); return ncr_res / ncr_div; } // mint<> operator""m(unsigned long long n){ return mint<>(n); } // mint<998244353> operator""m9(unsigned long long n){ return // mint<998244353>(n); } mint<1000003> operator""m3(unsigned long long n){ return // mint<1000003>(n); } using mi = mint<>; // P class P { public: lint x, y; }; istream &operator>>(istream &os, P &p) { os >> p.x >> p.y; return os; } bool operator<(P &l, P &r) { return (l.x - r.x ? l.x < r.x : l.y < r.y); } bool operator>(P &l, P &r) { return (l.x - r.x ? l.x > r.x : l.y > r.y); } class co : public P { public: constexpr co() noexcept : P({0, 0}) {} constexpr co(lint x, lint y) noexcept : P({x, y}) {} // constexpr const lint &value() const noexcept{ return x*x+y*y; } constexpr co operator-() const noexcept { return *this * -1; } constexpr bool operator==(const co rhs) const noexcept { return x == rhs.x && y == rhs.y; } constexpr bool operator!=(const co rhs) const noexcept { return x != rhs.x && y != rhs.y; } constexpr co operator+(const co rhs) const noexcept { return co(*this) += rhs; } constexpr co operator-(const co rhs) const noexcept { return co(*this) -= rhs; } constexpr co operator*(const lint rhs) const noexcept { return co(*this) *= rhs; } constexpr double operator/(const co rhs) const noexcept { if (!x && !y) return 0; if (!rhs.x && !rhs.y) return 101010.10101; if (!(x * rhs.y) ^ !(y * rhs.x)) return 101010.10101; return (x * rhs.y - y * rhs.x ? 101010.10101 : (!rhs.x ? y / rhs.y : x / rhs.x)); } constexpr co &operator+=(const co rhs) noexcept { x += rhs.x; y += rhs.y; return *this; } constexpr co &operator-=(const co rhs) noexcept { x -= rhs.x; y -= rhs.y; return *this; } constexpr co &operator*=(const lint rhs) noexcept { x *= rhs; y *= rhs; return *this; } }; struct edge { lint from, to, cost; }; vector<vector<edge>> g; vector<edge> edges; int n, m, p; lint d[MAXN]; bool bellman_ford(int start, int goal) { //ゴールまでの経路に負の閉路があるか rep(n) d[i] = inf; d[start] = 0; rep(2 * n) { rep(j, m) { edge now = edges[j]; if (d[now.from] != -inf && d[now.to] > d[now.from] + now.cost) { d[now.to] = d[now.from] + now.cost; if (i >= n - 1 && now.to == goal) { //全体で負の閉路があるかどうかだったら、==を消す return 1; } if (i >= n - 1) { d[now.to] = inf; } } } } return 0; } int main() { in(n, m, p); lint a, b, c; g.resize(n); rep(m) { in(a, b, c); --a, --b; g[a].pb({a, b, p - c}); edges.pb({a, b, p - c}); } if (bellman_ford(0, n - 1)) o(-1); else o(max(0ll, -d[n - 1])); } // sub-EOF
/*vvv> zzzzzI .---. zzuzuI .vgggg&,. +++++= dAC:|I .WbbWo JMM9^```?TMB` ..&gNNg,. gggggggJ, qgggggggg] (&&&&&&&&[ c+OA&J, (&&&&&&+J, .cJeAA&-. (&&&&&&&&x .&AA&=-. +++++= dTqk|I Xpbpbp JM#` (M#^ ?MMp MM| +TMN. JMF ' |yk ` dVY 7Vk, Vy XV cVf ?Y! JM V$ ` +++++= dcf:|I Xppppp dMN .MM+ .MM MM| MM] JMMMMMM+ |@tqkoh) ,y0 (V$ yyyyyyyV7 VV JMWyZWr TWVVVVW&, ++++++ d7qk|0 Xppppp ^HMN, _.db WMm, .MMF MM| ..MM` JMF . |yk .WV&. .XW' yy 4yn. jyn +. JM #S `++++` ?ZZZX= ?WWWW= -THMMMMH9^ (TMMMMM9! MMMMMMM"" JMMMMMMMME |UU. ?TUUUUY= UU. (UU- ^7TUUUV7! JUUUUUUUU 7TUNKO*/ // Ricty Diminished #include "bits/stdc++.h" using namespace std; typedef long long lint; typedef vector<lint> liv; //#define rep(i,n) for(int i=0;i<n;++i) #define all(v) v.begin(), v.end() #define pb push_back #define _vcppunko4(tuple) _getname4 tuple #define _getname4(_1, _2, _3, _4, name, ...) name #define _getname3(_1, _2, _3, name, ...) name #define _trep2(tuple) _rep2 tuple #define _trep3(tuple) _rep3 tuple #define _trep4(tuple) _rep4 tuple #define _rep1(n) for (lint i = 0; i < n; ++i) #define _rep2(i, n) for (lint i = 0; i < n; ++i) #define _rep3(i, a, b) for (lint i = a; i < b; ++i) #define _rep4(i, a, b, c) for (lint i = a; i < b; i += c) #define _trrep2(tuple) _rrep2 tuple #define _trrep3(tuple) _rrep3 tuple #define _trrep4(tuple) _rrep4 tuple #define _rrep1(n) for (lint i = n - 1; i >= 0; --i) #define _rrep2(i, n) for (lint i = n - 1; i >= 0; --i) #define _rrep3(i, a, b) for (lint i = b - 1; i >= a; --i) #define _rrep4(i, a, b, c) \ for (lint i = a + (b - a - 1) / c * c; i >= a; i -= c) template <class T> istream &operator>>(istream &is, vector<T> &vec); template <class T, size_t size> istream &operator>>(istream &is, array<T, size> &vec); template <class T, class L> istream &operator>>(istream &is, pair<T, L> &p); template <class T> ostream &operator<<(ostream &os, vector<T> &vec); template <class T, class L> ostream &operator<<(ostream &os, pair<T, L> &p); template <class T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <class T, class L> istream &operator>>(istream &is, pair<T, L> &p) { is >> p.first; is >> p.second; return is; } // template<class T> // ostream& operator<<(ostream& os,vector<T>& vec){ // os<<vec[0];rep(i,1,vec.size())os<<' '<<vec[i];return os; } template<class T> // ostream& operator<<(ostream& os,deque<T>& deq){ // os<<deq[0];rep(i,1,deq.size())os<<' '<<deq[i];return os; } template <class T, class L> ostream &operator<<(ostream &os, pair<T, L> &p) { os << p.first << " " << p.second; return os; } inline void in() {} template <class Head, class... Tail> inline void in(Head &&head, Tail &&...tail) { cin >> head; in(move(tail)...); } template <class T> inline bool out(T t) { cout << t << '\n'; return 0; } inline bool out() { cout << '\n'; return 0; } template <class Head, class... Tail> inline bool out(Head head, Tail... tail) { cout << head << ' '; out(move(tail)...); return 0; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } // http://beet-aizu.hatenablog.com/entry/2018/04/08/145516 #define rep(...) \ _vcppunko4((__VA_ARGS__, _trep4, _trep3, _trep2, _rep1))((__VA_ARGS__)) #define rrep(...) \ _vcppunko4((__VA_ARGS__, _trrep4, _trrep3, _trrep2, _rrep1))((__VA_ARGS__)) #define each(v) for (auto &i : v) #define lin(...) \ lint __VA_ARGS__; \ in(__VA_ARGS__) #define stin(...) \ string __VA_ARGS__; \ in(__VA_ARGS__) #define vin(type, name, size) \ vector<type> name(size); \ in(name) #define fi e.first #define se e.second #define YES(c) cout << ((c) ? "YES\n" : "NO\n"), 0 #define Yes(c) cout << ((c) ? "Yes\n" : "No\n"), 0 #define o(p) cout << p << endl, 0 #define sp(p) cout << p << " " #define deb(p) cerr << p << endl, 0 #define dd(n) cout << fixed << setprecision(n) #define linf 1152921504606846976 #define MAXN 200100 #define md_1e9_7 1000000007 #define md_998244353 998244353 #define mod md_1e9_7 #define inf linf // INT_MAX // mint #define md_tmp template <uint_fast64_t md = 1000000007> md_tmp class mint { using u64 = uint_fast64_t; public: u64 a; constexpr mint(const u64 x = 0) noexcept : a(x % md) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr mint operator+(const mint rhs) const noexcept { return mint(*this) += rhs; } constexpr mint operator-(const mint rhs) const noexcept { return mint(*this) -= rhs; } constexpr mint operator*(const mint rhs) const noexcept { return mint(*this) *= rhs; } constexpr mint operator^(const lint rhs) const noexcept { return mint(*this) ^= rhs; } constexpr mint operator/(const mint rhs) const noexcept { return mint(*this) /= rhs; } constexpr mint &operator+=(const mint rhs) noexcept { a += rhs.a; if (a >= md) a -= md; return *this; } constexpr mint &operator-=(const mint rhs) noexcept { if (a < rhs.a) a += md; a -= rhs.a; return *this; } constexpr mint &operator*=(const mint rhs) noexcept { a = a * rhs.a % md; return *this; } constexpr mint &operator^=(const lint rhs) noexcept { if (!rhs) return *this = 1; u64 exp = rhs - 1; mint base = this->a; while (exp) { if (exp & 1) *this *= base; base *= base; exp >>= 1; } return *this; } constexpr mint &operator/=(const mint rhs) noexcept { a = (*this * (rhs ^ (md - 2))).a; return *this; } }; md_tmp istream &operator>>(istream &os, mint<md> &m) { os >> m.a, m.a %= md; return os; } md_tmp ostream &operator<<(ostream &os, const mint<md> &m) { return os << m.a; } md_tmp mint<md> ncr(lint n, lint r) { if (n < r || n < 0 || r < 0) return mint<md>(0); mint<md> ncr_res = 1, ncr_div = 1; rep(r) ncr_res *= (n - i), ncr_div *= (r - i); return ncr_res / ncr_div; } // mint<> operator""m(unsigned long long n){ return mint<>(n); } // mint<998244353> operator""m9(unsigned long long n){ return // mint<998244353>(n); } mint<1000003> operator""m3(unsigned long long n){ return // mint<1000003>(n); } using mi = mint<>; // P class P { public: lint x, y; }; istream &operator>>(istream &os, P &p) { os >> p.x >> p.y; return os; } bool operator<(P &l, P &r) { return (l.x - r.x ? l.x < r.x : l.y < r.y); } bool operator>(P &l, P &r) { return (l.x - r.x ? l.x > r.x : l.y > r.y); } class co : public P { public: constexpr co() noexcept : P({0, 0}) {} constexpr co(lint x, lint y) noexcept : P({x, y}) {} // constexpr const lint &value() const noexcept{ return x*x+y*y; } constexpr co operator-() const noexcept { return *this * -1; } constexpr bool operator==(const co rhs) const noexcept { return x == rhs.x && y == rhs.y; } constexpr bool operator!=(const co rhs) const noexcept { return x != rhs.x && y != rhs.y; } constexpr co operator+(const co rhs) const noexcept { return co(*this) += rhs; } constexpr co operator-(const co rhs) const noexcept { return co(*this) -= rhs; } constexpr co operator*(const lint rhs) const noexcept { return co(*this) *= rhs; } constexpr double operator/(const co rhs) const noexcept { if (!x && !y) return 0; if (!rhs.x && !rhs.y) return 101010.10101; if (!(x * rhs.y) ^ !(y * rhs.x)) return 101010.10101; return (x * rhs.y - y * rhs.x ? 101010.10101 : (!rhs.x ? y / rhs.y : x / rhs.x)); } constexpr co &operator+=(const co rhs) noexcept { x += rhs.x; y += rhs.y; return *this; } constexpr co &operator-=(const co rhs) noexcept { x -= rhs.x; y -= rhs.y; return *this; } constexpr co &operator*=(const lint rhs) noexcept { x *= rhs; y *= rhs; return *this; } }; struct edge { lint from, to, cost; }; vector<vector<edge>> g; vector<edge> edges; int n, m, p; lint d[MAXN]; bool bellman_ford(int start, int goal) { //ゴールまでの経路に負の閉路があるか rep(n) d[i] = inf; d[start] = 0; rep(2 * n) { rep(j, m) { edge now = edges[j]; if (d[now.from] != inf && d[now.to] > d[now.from] + now.cost) { d[now.to] = d[now.from] + now.cost; if (i >= n - 1 && now.to == goal) { //全体で負の閉路があるかどうかだったら、==を消す return 1; } if (i >= n - 1) { d[now.to] = -inf; } } } } return 0; } int main() { in(n, m, p); lint a, b, c; g.resize(n); rep(m) { in(a, b, c); --a, --b; g[a].pb({a, b, p - c}); edges.pb({a, b, p - c}); } if (bellman_ford(0, n - 1)) o(-1); else o(max(0ll, -d[n - 1])); } // sub-EOF
[ "expression.operation.unary.arithmetic.remove", "control_flow.branch.if.condition.change", "expression.operation.unary.add" ]
753,898
753,896
u675296835
cpp
p02949
/*vvv> zzzzzI .---. zzuzuI .vgggg&,. +++++= dAC:|I .WbbWo JMM9^```?TMB` ..&gNNg,. gggggggJ, qgggggggg] (&&&&&&&&[ c+OA&J, (&&&&&&+J, .cJeAA&-. (&&&&&&&&x .&AA&=-. +++++= dTqk|I Xpbpbp JM#` (M#^ ?MMp MM| +TMN. JMF ' |yk ` dVY 7Vk, Vy XV cVf ?Y! JM V$ ` +++++= dcf:|I Xppppp dMN .MM+ .MM MM| MM] JMMMMMM+ |@tqkoh) ,y0 (V$ yyyyyyyV7 VV JMWyZWr TWVVVVW&, ++++++ d7qk|0 Xppppp ^HMN, _.db WMm, .MMF MM| ..MM` JMF . |yk .WV&. .XW' yy 4yn. jyn +. JM #S `++++` ?ZZZX= ?WWWW= -THMMMMH9^ (TMMMMM9! MMMMMMM"" JMMMMMMMME |UU. ?TUUUUY= UU. (UU- ^7TUUUV7! JUUUUUUUU 7TUNKO*/ // Ricty Diminished #include "bits/stdc++.h" using namespace std; typedef long long lint; typedef vector<lint> liv; //#define rep(i,n) for(int i=0;i<n;++i) #define all(v) v.begin(), v.end() #define pb push_back #define _vcppunko4(tuple) _getname4 tuple #define _getname4(_1, _2, _3, _4, name, ...) name #define _getname3(_1, _2, _3, name, ...) name #define _trep2(tuple) _rep2 tuple #define _trep3(tuple) _rep3 tuple #define _trep4(tuple) _rep4 tuple #define _rep1(n) for (lint i = 0; i < n; ++i) #define _rep2(i, n) for (lint i = 0; i < n; ++i) #define _rep3(i, a, b) for (lint i = a; i < b; ++i) #define _rep4(i, a, b, c) for (lint i = a; i < b; i += c) #define _trrep2(tuple) _rrep2 tuple #define _trrep3(tuple) _rrep3 tuple #define _trrep4(tuple) _rrep4 tuple #define _rrep1(n) for (lint i = n - 1; i >= 0; --i) #define _rrep2(i, n) for (lint i = n - 1; i >= 0; --i) #define _rrep3(i, a, b) for (lint i = b - 1; i >= a; --i) #define _rrep4(i, a, b, c) \ for (lint i = a + (b - a - 1) / c * c; i >= a; i -= c) template <class T> istream &operator>>(istream &is, vector<T> &vec); template <class T, size_t size> istream &operator>>(istream &is, array<T, size> &vec); template <class T, class L> istream &operator>>(istream &is, pair<T, L> &p); template <class T> ostream &operator<<(ostream &os, vector<T> &vec); template <class T, class L> ostream &operator<<(ostream &os, pair<T, L> &p); template <class T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <class T, class L> istream &operator>>(istream &is, pair<T, L> &p) { is >> p.first; is >> p.second; return is; } // template<class T> // ostream& operator<<(ostream& os,vector<T>& vec){ // os<<vec[0];rep(i,1,vec.size())os<<' '<<vec[i];return os; } template<class T> // ostream& operator<<(ostream& os,deque<T>& deq){ // os<<deq[0];rep(i,1,deq.size())os<<' '<<deq[i];return os; } template <class T, class L> ostream &operator<<(ostream &os, pair<T, L> &p) { os << p.first << " " << p.second; return os; } inline void in() {} template <class Head, class... Tail> inline void in(Head &&head, Tail &&...tail) { cin >> head; in(move(tail)...); } template <class T> inline bool out(T t) { cout << t << '\n'; return 0; } inline bool out() { cout << '\n'; return 0; } template <class Head, class... Tail> inline bool out(Head head, Tail... tail) { cout << head << ' '; out(move(tail)...); return 0; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } // http://beet-aizu.hatenablog.com/entry/2018/04/08/145516 #define rep(...) \ _vcppunko4((__VA_ARGS__, _trep4, _trep3, _trep2, _rep1))((__VA_ARGS__)) #define rrep(...) \ _vcppunko4((__VA_ARGS__, _trrep4, _trrep3, _trrep2, _rrep1))((__VA_ARGS__)) #define each(v) for (auto &i : v) #define lin(...) \ lint __VA_ARGS__; \ in(__VA_ARGS__) #define stin(...) \ string __VA_ARGS__; \ in(__VA_ARGS__) #define vin(type, name, size) \ vector<type> name(size); \ in(name) #define fi e.first #define se e.second #define YES(c) cout << ((c) ? "YES\n" : "NO\n"), 0 #define Yes(c) cout << ((c) ? "Yes\n" : "No\n"), 0 #define o(p) cout << p << endl, 0 #define sp(p) cout << p << " " #define deb(p) cerr << p << endl, 0 #define dd(n) cout << fixed << setprecision(n) #define linf 1152921504606846976 #define MAXN 200100 #define md_1e9_7 1000000007 #define md_998244353 998244353 #define mod md_1e9_7 #define inf linf // INT_MAX // mint #define md_tmp template <uint_fast64_t md = 1000000007> md_tmp class mint { using u64 = uint_fast64_t; public: u64 a; constexpr mint(const u64 x = 0) noexcept : a(x % md) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr mint operator+(const mint rhs) const noexcept { return mint(*this) += rhs; } constexpr mint operator-(const mint rhs) const noexcept { return mint(*this) -= rhs; } constexpr mint operator*(const mint rhs) const noexcept { return mint(*this) *= rhs; } constexpr mint operator^(const lint rhs) const noexcept { return mint(*this) ^= rhs; } constexpr mint operator/(const mint rhs) const noexcept { return mint(*this) /= rhs; } constexpr mint &operator+=(const mint rhs) noexcept { a += rhs.a; if (a >= md) a -= md; return *this; } constexpr mint &operator-=(const mint rhs) noexcept { if (a < rhs.a) a += md; a -= rhs.a; return *this; } constexpr mint &operator*=(const mint rhs) noexcept { a = a * rhs.a % md; return *this; } constexpr mint &operator^=(const lint rhs) noexcept { if (!rhs) return *this = 1; u64 exp = rhs - 1; mint base = this->a; while (exp) { if (exp & 1) *this *= base; base *= base; exp >>= 1; } return *this; } constexpr mint &operator/=(const mint rhs) noexcept { a = (*this * (rhs ^ (md - 2))).a; return *this; } }; md_tmp istream &operator>>(istream &os, mint<md> &m) { os >> m.a, m.a %= md; return os; } md_tmp ostream &operator<<(ostream &os, const mint<md> &m) { return os << m.a; } md_tmp mint<md> ncr(lint n, lint r) { if (n < r || n < 0 || r < 0) return mint<md>(0); mint<md> ncr_res = 1, ncr_div = 1; rep(r) ncr_res *= (n - i), ncr_div *= (r - i); return ncr_res / ncr_div; } // mint<> operator""m(unsigned long long n){ return mint<>(n); } // mint<998244353> operator""m9(unsigned long long n){ return // mint<998244353>(n); } mint<1000003> operator""m3(unsigned long long n){ return // mint<1000003>(n); } using mi = mint<>; // P class P { public: lint x, y; }; istream &operator>>(istream &os, P &p) { os >> p.x >> p.y; return os; } bool operator<(P &l, P &r) { return (l.x - r.x ? l.x < r.x : l.y < r.y); } bool operator>(P &l, P &r) { return (l.x - r.x ? l.x > r.x : l.y > r.y); } class co : public P { public: constexpr co() noexcept : P({0, 0}) {} constexpr co(lint x, lint y) noexcept : P({x, y}) {} // constexpr const lint &value() const noexcept{ return x*x+y*y; } constexpr co operator-() const noexcept { return *this * -1; } constexpr bool operator==(const co rhs) const noexcept { return x == rhs.x && y == rhs.y; } constexpr bool operator!=(const co rhs) const noexcept { return x != rhs.x && y != rhs.y; } constexpr co operator+(const co rhs) const noexcept { return co(*this) += rhs; } constexpr co operator-(const co rhs) const noexcept { return co(*this) -= rhs; } constexpr co operator*(const lint rhs) const noexcept { return co(*this) *= rhs; } constexpr double operator/(const co rhs) const noexcept { if (!x && !y) return 0; if (!rhs.x && !rhs.y) return 101010.10101; if (!(x * rhs.y) ^ !(y * rhs.x)) return 101010.10101; return (x * rhs.y - y * rhs.x ? 101010.10101 : (!rhs.x ? y / rhs.y : x / rhs.x)); } constexpr co &operator+=(const co rhs) noexcept { x += rhs.x; y += rhs.y; return *this; } constexpr co &operator-=(const co rhs) noexcept { x -= rhs.x; y -= rhs.y; return *this; } constexpr co &operator*=(const lint rhs) noexcept { x *= rhs; y *= rhs; return *this; } }; struct edge { lint from, to, cost; }; vector<vector<edge>> g; vector<edge> edges; int n, m, p; lint d[MAXN]; bool bellman_ford(int start, int goal) { //ゴールまでの経路に負の閉路があるか rep(n) d[i] = inf; d[start] = 0; rep(2 * n) { rep(j, m) { edge now = edges[j]; if (d[now.from] != -inf && d[now.to] > d[now.from] + now.cost) { d[now.to] = d[now.from] + now.cost; if (i >= n - 1 && now.to == goal) { //全体で負の閉路があるかどうかだったら、==を消す return 1; } if (i >= n - 1) { d[now.to] = -inf; } } } } return 0; } int main() { in(n, m, p); lint a, b, c; g.resize(n); rep(m) { in(a, b, c); --a, --b; g[a].pb({a, b, p - c}); edges.pb({a, b, p - c}); } if (bellman_ford(0, n - 1)) o(-1); else o(max(0ll, -d[n - 1])); } // sub-EOF
/*vvv> zzzzzI .---. zzuzuI .vgggg&,. +++++= dAC:|I .WbbWo JMM9^```?TMB` ..&gNNg,. gggggggJ, qgggggggg] (&&&&&&&&[ c+OA&J, (&&&&&&+J, .cJeAA&-. (&&&&&&&&x .&AA&=-. +++++= dTqk|I Xpbpbp JM#` (M#^ ?MMp MM| +TMN. JMF ' |yk ` dVY 7Vk, Vy XV cVf ?Y! JM V$ ` +++++= dcf:|I Xppppp dMN .MM+ .MM MM| MM] JMMMMMM+ |@tqkoh) ,y0 (V$ yyyyyyyV7 VV JMWyZWr TWVVVVW&, ++++++ d7qk|0 Xppppp ^HMN, _.db WMm, .MMF MM| ..MM` JMF . |yk .WV&. .XW' yy 4yn. jyn +. JM #S `++++` ?ZZZX= ?WWWW= -THMMMMH9^ (TMMMMM9! MMMMMMM"" JMMMMMMMME |UU. ?TUUUUY= UU. (UU- ^7TUUUV7! JUUUUUUUU 7TUNKO*/ // Ricty Diminished #include "bits/stdc++.h" using namespace std; typedef long long lint; typedef vector<lint> liv; //#define rep(i,n) for(int i=0;i<n;++i) #define all(v) v.begin(), v.end() #define pb push_back #define _vcppunko4(tuple) _getname4 tuple #define _getname4(_1, _2, _3, _4, name, ...) name #define _getname3(_1, _2, _3, name, ...) name #define _trep2(tuple) _rep2 tuple #define _trep3(tuple) _rep3 tuple #define _trep4(tuple) _rep4 tuple #define _rep1(n) for (lint i = 0; i < n; ++i) #define _rep2(i, n) for (lint i = 0; i < n; ++i) #define _rep3(i, a, b) for (lint i = a; i < b; ++i) #define _rep4(i, a, b, c) for (lint i = a; i < b; i += c) #define _trrep2(tuple) _rrep2 tuple #define _trrep3(tuple) _rrep3 tuple #define _trrep4(tuple) _rrep4 tuple #define _rrep1(n) for (lint i = n - 1; i >= 0; --i) #define _rrep2(i, n) for (lint i = n - 1; i >= 0; --i) #define _rrep3(i, a, b) for (lint i = b - 1; i >= a; --i) #define _rrep4(i, a, b, c) \ for (lint i = a + (b - a - 1) / c * c; i >= a; i -= c) template <class T> istream &operator>>(istream &is, vector<T> &vec); template <class T, size_t size> istream &operator>>(istream &is, array<T, size> &vec); template <class T, class L> istream &operator>>(istream &is, pair<T, L> &p); template <class T> ostream &operator<<(ostream &os, vector<T> &vec); template <class T, class L> ostream &operator<<(ostream &os, pair<T, L> &p); template <class T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <class T, class L> istream &operator>>(istream &is, pair<T, L> &p) { is >> p.first; is >> p.second; return is; } // template<class T> // ostream& operator<<(ostream& os,vector<T>& vec){ // os<<vec[0];rep(i,1,vec.size())os<<' '<<vec[i];return os; } template<class T> // ostream& operator<<(ostream& os,deque<T>& deq){ // os<<deq[0];rep(i,1,deq.size())os<<' '<<deq[i];return os; } template <class T, class L> ostream &operator<<(ostream &os, pair<T, L> &p) { os << p.first << " " << p.second; return os; } inline void in() {} template <class Head, class... Tail> inline void in(Head &&head, Tail &&...tail) { cin >> head; in(move(tail)...); } template <class T> inline bool out(T t) { cout << t << '\n'; return 0; } inline bool out() { cout << '\n'; return 0; } template <class Head, class... Tail> inline bool out(Head head, Tail... tail) { cout << head << ' '; out(move(tail)...); return 0; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } // http://beet-aizu.hatenablog.com/entry/2018/04/08/145516 #define rep(...) \ _vcppunko4((__VA_ARGS__, _trep4, _trep3, _trep2, _rep1))((__VA_ARGS__)) #define rrep(...) \ _vcppunko4((__VA_ARGS__, _trrep4, _trrep3, _trrep2, _rrep1))((__VA_ARGS__)) #define each(v) for (auto &i : v) #define lin(...) \ lint __VA_ARGS__; \ in(__VA_ARGS__) #define stin(...) \ string __VA_ARGS__; \ in(__VA_ARGS__) #define vin(type, name, size) \ vector<type> name(size); \ in(name) #define fi e.first #define se e.second #define YES(c) cout << ((c) ? "YES\n" : "NO\n"), 0 #define Yes(c) cout << ((c) ? "Yes\n" : "No\n"), 0 #define o(p) cout << p << endl, 0 #define sp(p) cout << p << " " #define deb(p) cerr << p << endl, 0 #define dd(n) cout << fixed << setprecision(n) #define linf 1152921504606846976 #define MAXN 200100 #define md_1e9_7 1000000007 #define md_998244353 998244353 #define mod md_1e9_7 #define inf linf // INT_MAX // mint #define md_tmp template <uint_fast64_t md = 1000000007> md_tmp class mint { using u64 = uint_fast64_t; public: u64 a; constexpr mint(const u64 x = 0) noexcept : a(x % md) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr mint operator+(const mint rhs) const noexcept { return mint(*this) += rhs; } constexpr mint operator-(const mint rhs) const noexcept { return mint(*this) -= rhs; } constexpr mint operator*(const mint rhs) const noexcept { return mint(*this) *= rhs; } constexpr mint operator^(const lint rhs) const noexcept { return mint(*this) ^= rhs; } constexpr mint operator/(const mint rhs) const noexcept { return mint(*this) /= rhs; } constexpr mint &operator+=(const mint rhs) noexcept { a += rhs.a; if (a >= md) a -= md; return *this; } constexpr mint &operator-=(const mint rhs) noexcept { if (a < rhs.a) a += md; a -= rhs.a; return *this; } constexpr mint &operator*=(const mint rhs) noexcept { a = a * rhs.a % md; return *this; } constexpr mint &operator^=(const lint rhs) noexcept { if (!rhs) return *this = 1; u64 exp = rhs - 1; mint base = this->a; while (exp) { if (exp & 1) *this *= base; base *= base; exp >>= 1; } return *this; } constexpr mint &operator/=(const mint rhs) noexcept { a = (*this * (rhs ^ (md - 2))).a; return *this; } }; md_tmp istream &operator>>(istream &os, mint<md> &m) { os >> m.a, m.a %= md; return os; } md_tmp ostream &operator<<(ostream &os, const mint<md> &m) { return os << m.a; } md_tmp mint<md> ncr(lint n, lint r) { if (n < r || n < 0 || r < 0) return mint<md>(0); mint<md> ncr_res = 1, ncr_div = 1; rep(r) ncr_res *= (n - i), ncr_div *= (r - i); return ncr_res / ncr_div; } // mint<> operator""m(unsigned long long n){ return mint<>(n); } // mint<998244353> operator""m9(unsigned long long n){ return // mint<998244353>(n); } mint<1000003> operator""m3(unsigned long long n){ return // mint<1000003>(n); } using mi = mint<>; // P class P { public: lint x, y; }; istream &operator>>(istream &os, P &p) { os >> p.x >> p.y; return os; } bool operator<(P &l, P &r) { return (l.x - r.x ? l.x < r.x : l.y < r.y); } bool operator>(P &l, P &r) { return (l.x - r.x ? l.x > r.x : l.y > r.y); } class co : public P { public: constexpr co() noexcept : P({0, 0}) {} constexpr co(lint x, lint y) noexcept : P({x, y}) {} // constexpr const lint &value() const noexcept{ return x*x+y*y; } constexpr co operator-() const noexcept { return *this * -1; } constexpr bool operator==(const co rhs) const noexcept { return x == rhs.x && y == rhs.y; } constexpr bool operator!=(const co rhs) const noexcept { return x != rhs.x && y != rhs.y; } constexpr co operator+(const co rhs) const noexcept { return co(*this) += rhs; } constexpr co operator-(const co rhs) const noexcept { return co(*this) -= rhs; } constexpr co operator*(const lint rhs) const noexcept { return co(*this) *= rhs; } constexpr double operator/(const co rhs) const noexcept { if (!x && !y) return 0; if (!rhs.x && !rhs.y) return 101010.10101; if (!(x * rhs.y) ^ !(y * rhs.x)) return 101010.10101; return (x * rhs.y - y * rhs.x ? 101010.10101 : (!rhs.x ? y / rhs.y : x / rhs.x)); } constexpr co &operator+=(const co rhs) noexcept { x += rhs.x; y += rhs.y; return *this; } constexpr co &operator-=(const co rhs) noexcept { x -= rhs.x; y -= rhs.y; return *this; } constexpr co &operator*=(const lint rhs) noexcept { x *= rhs; y *= rhs; return *this; } }; struct edge { lint from, to, cost; }; vector<vector<edge>> g; vector<edge> edges; int n, m, p; lint d[MAXN]; bool bellman_ford(int start, int goal) { //ゴールまでの経路に負の閉路があるか rep(n) d[i] = inf; d[start] = 0; rep(2 * n) { rep(j, m) { edge now = edges[j]; if (d[now.from] != inf && d[now.to] > d[now.from] + now.cost) { d[now.to] = d[now.from] + now.cost; if (i >= n - 1 && now.to == goal) { //全体で負の閉路があるかどうかだったら、==を消す return 1; } if (i >= n - 1) { d[now.to] = -inf; } } } } return 0; } int main() { in(n, m, p); lint a, b, c; g.resize(n); rep(m) { in(a, b, c); --a, --b; g[a].pb({a, b, p - c}); edges.pb({a, b, p - c}); } if (bellman_ford(0, n - 1)) o(-1); else o(max(0ll, -d[n - 1])); } // sub-EOF
[ "expression.operation.unary.arithmetic.remove", "control_flow.branch.if.condition.change" ]
753,900
753,896
u675296835
cpp
p02949
/*vvv> zzzzzI .---. zzuzuI .vgggg&,. +++++= dAC:|I .WbbWo JMM9^```?TMB` ..&gNNg,. gggggggJ, qgggggggg] (&&&&&&&&[ c+OA&J, (&&&&&&+J, .cJeAA&-. (&&&&&&&&x .&AA&=-. +++++= dTqk|I Xpbpbp JM#` (M#^ ?MMp MM| +TMN. JMF ' |yk ` dVY 7Vk, Vy XV cVf ?Y! JM V$ ` +++++= dcf:|I Xppppp dMN .MM+ .MM MM| MM] JMMMMMM+ |@tqkoh) ,y0 (V$ yyyyyyyV7 VV JMWyZWr TWVVVVW&, ++++++ d7qk|0 Xppppp ^HMN, _.db WMm, .MMF MM| ..MM` JMF . |yk .WV&. .XW' yy 4yn. jyn +. JM #S `++++` ?ZZZX= ?WWWW= -THMMMMH9^ (TMMMMM9! MMMMMMM"" JMMMMMMMME |UU. ?TUUUUY= UU. (UU- ^7TUUUV7! JUUUUUUUU 7TUNKO*/ // Ricty Diminished #include "bits/stdc++.h" using namespace std; typedef long long lint; typedef vector<lint> liv; //#define rep(i,n) for(int i=0;i<n;++i) #define all(v) v.begin(), v.end() #define pb push_back #define _vcppunko4(tuple) _getname4 tuple #define _getname4(_1, _2, _3, _4, name, ...) name #define _getname3(_1, _2, _3, name, ...) name #define _trep2(tuple) _rep2 tuple #define _trep3(tuple) _rep3 tuple #define _trep4(tuple) _rep4 tuple #define _rep1(n) for (lint i = 0; i < n; ++i) #define _rep2(i, n) for (lint i = 0; i < n; ++i) #define _rep3(i, a, b) for (lint i = a; i < b; ++i) #define _rep4(i, a, b, c) for (lint i = a; i < b; i += c) #define _trrep2(tuple) _rrep2 tuple #define _trrep3(tuple) _rrep3 tuple #define _trrep4(tuple) _rrep4 tuple #define _rrep1(n) for (lint i = n - 1; i >= 0; --i) #define _rrep2(i, n) for (lint i = n - 1; i >= 0; --i) #define _rrep3(i, a, b) for (lint i = b - 1; i >= a; --i) #define _rrep4(i, a, b, c) \ for (lint i = a + (b - a - 1) / c * c; i >= a; i -= c) template <class T> istream &operator>>(istream &is, vector<T> &vec); template <class T, size_t size> istream &operator>>(istream &is, array<T, size> &vec); template <class T, class L> istream &operator>>(istream &is, pair<T, L> &p); template <class T> ostream &operator<<(ostream &os, vector<T> &vec); template <class T, class L> ostream &operator<<(ostream &os, pair<T, L> &p); template <class T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <class T, class L> istream &operator>>(istream &is, pair<T, L> &p) { is >> p.first; is >> p.second; return is; } // template<class T> // ostream& operator<<(ostream& os,vector<T>& vec){ // os<<vec[0];rep(i,1,vec.size())os<<' '<<vec[i];return os; } template<class T> // ostream& operator<<(ostream& os,deque<T>& deq){ // os<<deq[0];rep(i,1,deq.size())os<<' '<<deq[i];return os; } template <class T, class L> ostream &operator<<(ostream &os, pair<T, L> &p) { os << p.first << " " << p.second; return os; } inline void in() {} template <class Head, class... Tail> inline void in(Head &&head, Tail &&...tail) { cin >> head; in(move(tail)...); } template <class T> inline bool out(T t) { cout << t << '\n'; return 0; } inline bool out() { cout << '\n'; return 0; } template <class Head, class... Tail> inline bool out(Head head, Tail... tail) { cout << head << ' '; out(move(tail)...); return 0; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } // http://beet-aizu.hatenablog.com/entry/2018/04/08/145516 #define rep(...) \ _vcppunko4((__VA_ARGS__, _trep4, _trep3, _trep2, _rep1))((__VA_ARGS__)) #define rrep(...) \ _vcppunko4((__VA_ARGS__, _trrep4, _trrep3, _trrep2, _rrep1))((__VA_ARGS__)) #define each(v) for (auto &i : v) #define lin(...) \ lint __VA_ARGS__; \ in(__VA_ARGS__) #define stin(...) \ string __VA_ARGS__; \ in(__VA_ARGS__) #define vin(type, name, size) \ vector<type> name(size); \ in(name) #define fi e.first #define se e.second #define YES(c) cout << ((c) ? "YES\n" : "NO\n"), 0 #define Yes(c) cout << ((c) ? "Yes\n" : "No\n"), 0 #define o(p) cout << p << endl, 0 #define sp(p) cout << p << " " #define deb(p) cerr << p << endl, 0 #define dd(n) cout << fixed << setprecision(n) #define linf 1152921504606846976 #define MAXN 200100 #define md_1e9_7 1000000007 #define md_998244353 998244353 #define mod md_1e9_7 #define inf linf // INT_MAX // mint #define md_tmp template <uint_fast64_t md = 1000000007> md_tmp class mint { using u64 = uint_fast64_t; public: u64 a; constexpr mint(const u64 x = 0) noexcept : a(x % md) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr mint operator+(const mint rhs) const noexcept { return mint(*this) += rhs; } constexpr mint operator-(const mint rhs) const noexcept { return mint(*this) -= rhs; } constexpr mint operator*(const mint rhs) const noexcept { return mint(*this) *= rhs; } constexpr mint operator^(const lint rhs) const noexcept { return mint(*this) ^= rhs; } constexpr mint operator/(const mint rhs) const noexcept { return mint(*this) /= rhs; } constexpr mint &operator+=(const mint rhs) noexcept { a += rhs.a; if (a >= md) a -= md; return *this; } constexpr mint &operator-=(const mint rhs) noexcept { if (a < rhs.a) a += md; a -= rhs.a; return *this; } constexpr mint &operator*=(const mint rhs) noexcept { a = a * rhs.a % md; return *this; } constexpr mint &operator^=(const lint rhs) noexcept { if (!rhs) return *this = 1; u64 exp = rhs - 1; mint base = this->a; while (exp) { if (exp & 1) *this *= base; base *= base; exp >>= 1; } return *this; } constexpr mint &operator/=(const mint rhs) noexcept { a = (*this * (rhs ^ (md - 2))).a; return *this; } }; md_tmp istream &operator>>(istream &os, mint<md> &m) { os >> m.a, m.a %= md; return os; } md_tmp ostream &operator<<(ostream &os, const mint<md> &m) { return os << m.a; } md_tmp mint<md> ncr(lint n, lint r) { if (n < r || n < 0 || r < 0) return mint<md>(0); mint<md> ncr_res = 1, ncr_div = 1; rep(r) ncr_res *= (n - i), ncr_div *= (r - i); return ncr_res / ncr_div; } // mint<> operator""m(unsigned long long n){ return mint<>(n); } // mint<998244353> operator""m9(unsigned long long n){ return // mint<998244353>(n); } mint<1000003> operator""m3(unsigned long long n){ return // mint<1000003>(n); } using mi = mint<>; // P class P { public: lint x, y; }; istream &operator>>(istream &os, P &p) { os >> p.x >> p.y; return os; } bool operator<(P &l, P &r) { return (l.x - r.x ? l.x < r.x : l.y < r.y); } bool operator>(P &l, P &r) { return (l.x - r.x ? l.x > r.x : l.y > r.y); } class co : public P { public: constexpr co() noexcept : P({0, 0}) {} constexpr co(lint x, lint y) noexcept : P({x, y}) {} // constexpr const lint &value() const noexcept{ return x*x+y*y; } constexpr co operator-() const noexcept { return *this * -1; } constexpr bool operator==(const co rhs) const noexcept { return x == rhs.x && y == rhs.y; } constexpr bool operator!=(const co rhs) const noexcept { return x != rhs.x && y != rhs.y; } constexpr co operator+(const co rhs) const noexcept { return co(*this) += rhs; } constexpr co operator-(const co rhs) const noexcept { return co(*this) -= rhs; } constexpr co operator*(const lint rhs) const noexcept { return co(*this) *= rhs; } constexpr double operator/(const co rhs) const noexcept { if (!x && !y) return 0; if (!rhs.x && !rhs.y) return 101010.10101; if (!(x * rhs.y) ^ !(y * rhs.x)) return 101010.10101; return (x * rhs.y - y * rhs.x ? 101010.10101 : (!rhs.x ? y / rhs.y : x / rhs.x)); } constexpr co &operator+=(const co rhs) noexcept { x += rhs.x; y += rhs.y; return *this; } constexpr co &operator-=(const co rhs) noexcept { x -= rhs.x; y -= rhs.y; return *this; } constexpr co &operator*=(const lint rhs) noexcept { x *= rhs; y *= rhs; return *this; } }; struct edge { lint from, to, cost; }; vector<vector<edge>> g; vector<edge> edges; int n, m, p; lint d[MAXN]; bool bellman_ford(int start, int goal) { //ゴールまでの経路に負の閉路があるか rep(n) d[i] = inf; d[start] = 0; rep(n) { rep(j, m) { edge now = edges[j]; if (d[now.from] != -inf && d[now.to] > d[now.from] + now.cost) { d[now.to] = d[now.from] + now.cost; if (i >= n - 1 && now.to == goal) { //全体で負の閉路があるかどうかだったら、==を消す return 1; } if (i >= n - 1) { d[now.to] = -inf; } } } } return 0; } int main() { in(n, m, p); lint a, b, c; g.resize(n); rep(m) { in(a, b, c); --a, --b; g[a].pb({a, b, p - c}); edges.pb({a, b, p - c}); } if (bellman_ford(0, n - 1)) o(-1); else o(max(0ll, -d[n - 1])); } // sub-EOF
/*vvv> zzzzzI .---. zzuzuI .vgggg&,. +++++= dAC:|I .WbbWo JMM9^```?TMB` ..&gNNg,. gggggggJ, qgggggggg] (&&&&&&&&[ c+OA&J, (&&&&&&+J, .cJeAA&-. (&&&&&&&&x .&AA&=-. +++++= dTqk|I Xpbpbp JM#` (M#^ ?MMp MM| +TMN. JMF ' |yk ` dVY 7Vk, Vy XV cVf ?Y! JM V$ ` +++++= dcf:|I Xppppp dMN .MM+ .MM MM| MM] JMMMMMM+ |@tqkoh) ,y0 (V$ yyyyyyyV7 VV JMWyZWr TWVVVVW&, ++++++ d7qk|0 Xppppp ^HMN, _.db WMm, .MMF MM| ..MM` JMF . |yk .WV&. .XW' yy 4yn. jyn +. JM #S `++++` ?ZZZX= ?WWWW= -THMMMMH9^ (TMMMMM9! MMMMMMM"" JMMMMMMMME |UU. ?TUUUUY= UU. (UU- ^7TUUUV7! JUUUUUUUU 7TUNKO*/ // Ricty Diminished #include "bits/stdc++.h" using namespace std; typedef long long lint; typedef vector<lint> liv; //#define rep(i,n) for(int i=0;i<n;++i) #define all(v) v.begin(), v.end() #define pb push_back #define _vcppunko4(tuple) _getname4 tuple #define _getname4(_1, _2, _3, _4, name, ...) name #define _getname3(_1, _2, _3, name, ...) name #define _trep2(tuple) _rep2 tuple #define _trep3(tuple) _rep3 tuple #define _trep4(tuple) _rep4 tuple #define _rep1(n) for (lint i = 0; i < n; ++i) #define _rep2(i, n) for (lint i = 0; i < n; ++i) #define _rep3(i, a, b) for (lint i = a; i < b; ++i) #define _rep4(i, a, b, c) for (lint i = a; i < b; i += c) #define _trrep2(tuple) _rrep2 tuple #define _trrep3(tuple) _rrep3 tuple #define _trrep4(tuple) _rrep4 tuple #define _rrep1(n) for (lint i = n - 1; i >= 0; --i) #define _rrep2(i, n) for (lint i = n - 1; i >= 0; --i) #define _rrep3(i, a, b) for (lint i = b - 1; i >= a; --i) #define _rrep4(i, a, b, c) \ for (lint i = a + (b - a - 1) / c * c; i >= a; i -= c) template <class T> istream &operator>>(istream &is, vector<T> &vec); template <class T, size_t size> istream &operator>>(istream &is, array<T, size> &vec); template <class T, class L> istream &operator>>(istream &is, pair<T, L> &p); template <class T> ostream &operator<<(ostream &os, vector<T> &vec); template <class T, class L> ostream &operator<<(ostream &os, pair<T, L> &p); template <class T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <class T, class L> istream &operator>>(istream &is, pair<T, L> &p) { is >> p.first; is >> p.second; return is; } // template<class T> // ostream& operator<<(ostream& os,vector<T>& vec){ // os<<vec[0];rep(i,1,vec.size())os<<' '<<vec[i];return os; } template<class T> // ostream& operator<<(ostream& os,deque<T>& deq){ // os<<deq[0];rep(i,1,deq.size())os<<' '<<deq[i];return os; } template <class T, class L> ostream &operator<<(ostream &os, pair<T, L> &p) { os << p.first << " " << p.second; return os; } inline void in() {} template <class Head, class... Tail> inline void in(Head &&head, Tail &&...tail) { cin >> head; in(move(tail)...); } template <class T> inline bool out(T t) { cout << t << '\n'; return 0; } inline bool out() { cout << '\n'; return 0; } template <class Head, class... Tail> inline bool out(Head head, Tail... tail) { cout << head << ' '; out(move(tail)...); return 0; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } // http://beet-aizu.hatenablog.com/entry/2018/04/08/145516 #define rep(...) \ _vcppunko4((__VA_ARGS__, _trep4, _trep3, _trep2, _rep1))((__VA_ARGS__)) #define rrep(...) \ _vcppunko4((__VA_ARGS__, _trrep4, _trrep3, _trrep2, _rrep1))((__VA_ARGS__)) #define each(v) for (auto &i : v) #define lin(...) \ lint __VA_ARGS__; \ in(__VA_ARGS__) #define stin(...) \ string __VA_ARGS__; \ in(__VA_ARGS__) #define vin(type, name, size) \ vector<type> name(size); \ in(name) #define fi e.first #define se e.second #define YES(c) cout << ((c) ? "YES\n" : "NO\n"), 0 #define Yes(c) cout << ((c) ? "Yes\n" : "No\n"), 0 #define o(p) cout << p << endl, 0 #define sp(p) cout << p << " " #define deb(p) cerr << p << endl, 0 #define dd(n) cout << fixed << setprecision(n) #define linf 1152921504606846976 #define MAXN 200100 #define md_1e9_7 1000000007 #define md_998244353 998244353 #define mod md_1e9_7 #define inf linf // INT_MAX // mint #define md_tmp template <uint_fast64_t md = 1000000007> md_tmp class mint { using u64 = uint_fast64_t; public: u64 a; constexpr mint(const u64 x = 0) noexcept : a(x % md) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr mint operator+(const mint rhs) const noexcept { return mint(*this) += rhs; } constexpr mint operator-(const mint rhs) const noexcept { return mint(*this) -= rhs; } constexpr mint operator*(const mint rhs) const noexcept { return mint(*this) *= rhs; } constexpr mint operator^(const lint rhs) const noexcept { return mint(*this) ^= rhs; } constexpr mint operator/(const mint rhs) const noexcept { return mint(*this) /= rhs; } constexpr mint &operator+=(const mint rhs) noexcept { a += rhs.a; if (a >= md) a -= md; return *this; } constexpr mint &operator-=(const mint rhs) noexcept { if (a < rhs.a) a += md; a -= rhs.a; return *this; } constexpr mint &operator*=(const mint rhs) noexcept { a = a * rhs.a % md; return *this; } constexpr mint &operator^=(const lint rhs) noexcept { if (!rhs) return *this = 1; u64 exp = rhs - 1; mint base = this->a; while (exp) { if (exp & 1) *this *= base; base *= base; exp >>= 1; } return *this; } constexpr mint &operator/=(const mint rhs) noexcept { a = (*this * (rhs ^ (md - 2))).a; return *this; } }; md_tmp istream &operator>>(istream &os, mint<md> &m) { os >> m.a, m.a %= md; return os; } md_tmp ostream &operator<<(ostream &os, const mint<md> &m) { return os << m.a; } md_tmp mint<md> ncr(lint n, lint r) { if (n < r || n < 0 || r < 0) return mint<md>(0); mint<md> ncr_res = 1, ncr_div = 1; rep(r) ncr_res *= (n - i), ncr_div *= (r - i); return ncr_res / ncr_div; } // mint<> operator""m(unsigned long long n){ return mint<>(n); } // mint<998244353> operator""m9(unsigned long long n){ return // mint<998244353>(n); } mint<1000003> operator""m3(unsigned long long n){ return // mint<1000003>(n); } using mi = mint<>; // P class P { public: lint x, y; }; istream &operator>>(istream &os, P &p) { os >> p.x >> p.y; return os; } bool operator<(P &l, P &r) { return (l.x - r.x ? l.x < r.x : l.y < r.y); } bool operator>(P &l, P &r) { return (l.x - r.x ? l.x > r.x : l.y > r.y); } class co : public P { public: constexpr co() noexcept : P({0, 0}) {} constexpr co(lint x, lint y) noexcept : P({x, y}) {} // constexpr const lint &value() const noexcept{ return x*x+y*y; } constexpr co operator-() const noexcept { return *this * -1; } constexpr bool operator==(const co rhs) const noexcept { return x == rhs.x && y == rhs.y; } constexpr bool operator!=(const co rhs) const noexcept { return x != rhs.x && y != rhs.y; } constexpr co operator+(const co rhs) const noexcept { return co(*this) += rhs; } constexpr co operator-(const co rhs) const noexcept { return co(*this) -= rhs; } constexpr co operator*(const lint rhs) const noexcept { return co(*this) *= rhs; } constexpr double operator/(const co rhs) const noexcept { if (!x && !y) return 0; if (!rhs.x && !rhs.y) return 101010.10101; if (!(x * rhs.y) ^ !(y * rhs.x)) return 101010.10101; return (x * rhs.y - y * rhs.x ? 101010.10101 : (!rhs.x ? y / rhs.y : x / rhs.x)); } constexpr co &operator+=(const co rhs) noexcept { x += rhs.x; y += rhs.y; return *this; } constexpr co &operator-=(const co rhs) noexcept { x -= rhs.x; y -= rhs.y; return *this; } constexpr co &operator*=(const lint rhs) noexcept { x *= rhs; y *= rhs; return *this; } }; struct edge { lint from, to, cost; }; vector<vector<edge>> g; vector<edge> edges; int n, m, p; lint d[MAXN]; bool bellman_ford(int start, int goal) { //ゴールまでの経路に負の閉路があるか rep(n) d[i] = inf; d[start] = 0; rep(2 * n) { rep(j, m) { edge now = edges[j]; if (d[now.from] != inf && d[now.to] > d[now.from] + now.cost) { d[now.to] = d[now.from] + now.cost; if (i >= n - 1 && now.to == goal) { //全体で負の閉路があるかどうかだったら、==を消す return 1; } if (i >= n - 1) { d[now.to] = -inf; } } } } return 0; } int main() { in(n, m, p); lint a, b, c; g.resize(n); rep(m) { in(a, b, c); --a, --b; g[a].pb({a, b, p - c}); edges.pb({a, b, p - c}); } if (bellman_ford(0, n - 1)) o(-1); else o(max(0ll, -d[n - 1])); } // sub-EOF
[ "expression.operation.unary.arithmetic.remove", "control_flow.branch.if.condition.change" ]
753,901
753,896
u675296835
cpp
p02949
#include <bits/stdc++.h> using namespace std::literals::string_literals; using i64 = long long; using std::cin; using std::cout; using std::endl; template <typename T> std::vector<T> make_v(size_t a) { return std::vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } int main() { int n, m; i64 p; scanf("%d%d%lld", &n, &m, &p); std::vector<int> loop, a(m), b(m); std::vector<i64> c(m); std::vector<std::vector<std::pair<int, i64>>> g(n), rg(n); for (int i = 0; i < m; i++) { scanf("%d%d%lld", &a[i], &b[i], &c[i]); if (a[i] == b[i]) { a[i]--; b[i]--; loop.push_back(i); continue; } g[a[i] - 1].push_back({b[i] - 1, c[i] - p}); rg[b[i] - 1].push_back({a[i] - 1, c[i] - p}); a[i]--; b[i]--; } std::vector<bool> from0(n, false), from1(n, false); from0[0] = from1[n - 1] = true; std::queue<int> qu; qu.push(n - 1); while (!qu.empty()) { auto p = qu.front(); qu.pop(); for (auto e : rg[p]) { if (from1[e.first]) continue; from1[e.first] = true; qu.push(e.first); } } qu.push(0); while (!qu.empty()) { auto p = qu.front(); qu.pop(); for (auto e : g[p]) { if (from0[e.first]) continue; from0[e.first] = true; qu.push(e.first); } } for (auto i : loop) { if (c[i] - p <= 0) continue; if (c[i] - p > 0 and from0[a[i]] and from1[a[i]]) { printf("-1\n"); return 0; } } std::vector<std::vector<std::pair<int, i64>>> G(n); for (int i = 0; i < n; i++) { if (a[i] == b[i]) continue; if (from0[a[i]] and from1[b[i]]) { G[a[i]].push_back({b[i], p - c[i]}); } } bool isFinish = true; const i64 INF = 1LL << 60; std::vector<i64> dist(n, INF); dist[0] = 0; for (int i = 0; i < n; i++) { for (int v = 0; v < n; v++) { for (auto e : G[v]) { if (dist[v] != INF and dist[e.first] > dist[v] + e.second) { dist[e.first] = dist[v] + e.second; if (i == n - 1) isFinish = false; } } } } if (!isFinish) { printf("-1\n"); return 0; } printf("%lld\n", std::max(0LL, -dist[n - 1])); return 0; }
#include <bits/stdc++.h> using namespace std::literals::string_literals; using i64 = long long; using std::cin; using std::cout; using std::endl; template <typename T> std::vector<T> make_v(size_t a) { return std::vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } int main() { int n, m; i64 p; scanf("%d%d%lld", &n, &m, &p); std::vector<int> loop, a(m), b(m); std::vector<i64> c(m); std::vector<std::vector<std::pair<int, i64>>> g(n), rg(n); for (int i = 0; i < m; i++) { scanf("%d%d%lld", &a[i], &b[i], &c[i]); if (a[i] == b[i]) { a[i]--; b[i]--; loop.push_back(i); continue; } g[a[i] - 1].push_back({b[i] - 1, c[i] - p}); rg[b[i] - 1].push_back({a[i] - 1, c[i] - p}); a[i]--; b[i]--; } std::vector<bool> from0(n, false), from1(n, false); from0[0] = from1[n - 1] = true; std::queue<int> qu; qu.push(n - 1); while (!qu.empty()) { auto p = qu.front(); qu.pop(); for (auto e : rg[p]) { if (from1[e.first]) continue; from1[e.first] = true; qu.push(e.first); } } qu.push(0); while (!qu.empty()) { auto p = qu.front(); qu.pop(); for (auto e : g[p]) { if (from0[e.first]) continue; from0[e.first] = true; qu.push(e.first); } } for (auto i : loop) { if (c[i] - p <= 0) continue; if (c[i] - p > 0 and from0[a[i]] and from1[a[i]]) { printf("-1\n"); return 0; } } std::vector<std::vector<std::pair<int, i64>>> G(n); for (int i = 0; i < m; i++) { if (a[i] == b[i]) continue; if (from0[a[i]] and from1[b[i]]) { G[a[i]].push_back({b[i], p - c[i]}); } } bool isFinish = true; const i64 INF = 1LL << 60; std::vector<i64> dist(n, INF); dist[0] = 0; for (int i = 0; i < n; i++) { for (int v = 0; v < n; v++) { for (auto e : G[v]) { if (dist[v] != INF and dist[e.first] > dist[v] + e.second) { dist[e.first] = dist[v] + e.second; if (i == n - 1) isFinish = false; } } } } if (!isFinish) { printf("-1\n"); return 0; } printf("%lld\n", std::max(0LL, -dist[n - 1])); return 0; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
753,905
753,906
u424655672
cpp
p02949
#include <bits/stdc++.h> using namespace std; int INF = -1'000'000'000; int main() { int n, m; long long p; cin >> n >> m >> p; struct edge { int from, to, cost; }; vector<edge> es(m); for (int i = 0; i < m; i++) { cin >> es[i].from >> es[i].to >> es[i].cost; es[i].from--; es[i].to--; } vector<pair<long long, int>> distance(n, {INF, 0}); distance[0] = {0, 0}; for (int i = 0; i < 2 * m; i++) { bool update = false; for (int j = 0; j < m; j++) { edge e = es[j]; if (distance[e.from].first != INF && distance[e.to].first - p * distance[e.to].second < distance[e.from].first + e.cost - p * distance[e.from].second - p) { distance[e.to].first = distance[e.from].first + e.cost; distance[e.to].second = distance[e.from].second + 1; update = true; if (i >= m - 1 && e.to == n - 1) { cout << -1 << endl; exit(0); } } } if (!update) break; } if (distance[n - 1].first == INF) cout << -1 << endl; else cout << max((long long)0, distance[n - 1].first - p * distance[n - 1].second) << endl; }
#include <bits/stdc++.h> using namespace std; int INF = -1'000'000'000; int main() { int n, m; long long p; cin >> n >> m >> p; struct edge { int from, to, cost; }; vector<edge> es(m); for (int i = 0; i < m; i++) { cin >> es[i].from >> es[i].to >> es[i].cost; es[i].from--; es[i].to--; } vector<pair<long long, int>> distance(n, {INF, 0}); distance[0] = {0, 0}; for (int i = 0; i < 2 * n; i++) { bool update = false; for (int j = 0; j < m; j++) { edge e = es[j]; if (distance[e.from].first != INF && distance[e.to].first - p * distance[e.to].second < distance[e.from].first + e.cost - p * distance[e.from].second - p) { distance[e.to].first = distance[e.from].first + e.cost; distance[e.to].second = distance[e.from].second + 1; update = true; if (i >= n - 1 && e.to == n - 1) { cout << -1 << endl; exit(0); } } } if (!update) break; } if (distance[n - 1].first == INF) cout << -1 << endl; else cout << max((long long)0, distance[n - 1].first - p * distance[n - 1].second) << endl; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change", "control_flow.branch.if.condition.change" ]
753,908
753,909
u013408661
cpp
p02949
#include <bits/stdc++.h> using namespace std; int INF = -1'000'000'000; int main() { int n, m, p; cin >> n >> m >> p; struct edge { int from, to, cost; }; vector<edge> es(m); for (int i = 0; i < m; i++) { cin >> es[i].from >> es[i].to >> es[i].cost; es[i].from--; es[i].to--; } vector<pair<long long, int>> distance(n, {INF, 0}); distance[0] = {0, 0}; for (int i = 0; i < 2 * m; i++) { bool update = false; for (int j = 0; j < m; j++) { edge e = es[j]; if (distance[e.from].first != INF && distance[e.to].first - p * distance[e.to].second < distance[e.from].first + e.cost - p * distance[e.from].second - p) { distance[e.to].first = distance[e.from].first + e.cost; distance[e.to].second = distance[e.from].second + 1; update = true; if (i >= m - 1 && e.to == n - 1) { cout << -1 << endl; exit(0); } } } if (!update) break; } if (distance[n - 1].first == INF) cout << -1 << endl; else cout << max((long long)0, distance[n - 1].first - p * distance[n - 1].second) << endl; }
#include <bits/stdc++.h> using namespace std; int INF = -1'000'000'000; int main() { int n, m; long long p; cin >> n >> m >> p; struct edge { int from, to, cost; }; vector<edge> es(m); for (int i = 0; i < m; i++) { cin >> es[i].from >> es[i].to >> es[i].cost; es[i].from--; es[i].to--; } vector<pair<long long, int>> distance(n, {INF, 0}); distance[0] = {0, 0}; for (int i = 0; i < 2 * n; i++) { bool update = false; for (int j = 0; j < m; j++) { edge e = es[j]; if (distance[e.from].first != INF && distance[e.to].first - p * distance[e.to].second < distance[e.from].first + e.cost - p * distance[e.from].second - p) { distance[e.to].first = distance[e.from].first + e.cost; distance[e.to].second = distance[e.from].second + 1; update = true; if (i >= n - 1 && e.to == n - 1) { cout << -1 << endl; exit(0); } } } if (!update) break; } if (distance[n - 1].first == INF) cout << -1 << endl; else cout << max((long long)0, distance[n - 1].first - p * distance[n - 1].second) << endl; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change", "control_flow.branch.if.condition.change" ]
753,910
753,909
u013408661
cpp
p02949
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define fi first #define se second typedef pair<ll, ll> P; #define Mod 1000000007 using VP = vector<P>; using VVP = vector<VP>; using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>; #define INF 1000000000000 struct edge { ll from, to, cost; }; edge es[5050]; ll d[2525]; ll V, E; ll ttt = 0; void bellmanford(ll s) { for (ll i = 0; i < V; i++) d[i] = INF; d[s] = 0; ll cnt = 0; while (true) { bool update = false; cnt++; for (int i = 0; i < E; i++) { edge e = es[i]; if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; update = true; if (cnt > V * 4 && e.to == V - 1) { ttt = -1; return; } if (cnt > V * 4) { return; } } } if (!update) break; } } int main() { ll i, j; ll n, m, p; cin >> n >> m >> p; V = n; E = m; for (i = 0; i < m; i++) { ll a, b, c; cin >> a >> b >> c; a--; b--; es[i] = {a, b, p - c}; } bellmanford(0); if (ttt == -1) cout << -1 << endl; else cout << max(0ll, -d[n - 1]) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define fi first #define se second typedef pair<ll, ll> P; #define Mod 1000000007 using VP = vector<P>; using VVP = vector<VP>; using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>; #define INF 1000000000000 struct edge { ll from, to, cost; }; edge es[5050]; ll d[2525]; ll V, E; ll ttt = 0; void bellmanford(ll s) { for (ll i = 0; i < V; i++) d[i] = INF; d[s] = 0; ll cnt = 0; while (true) { bool update = false; cnt++; for (int i = 0; i < E; i++) { edge e = es[i]; if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; update = true; if (cnt > V * 3 && e.to == V - 1) { ttt = -1; return; } if (cnt > V * 6) { return; } } } if (!update) break; } } int main() { ll i, j; ll n, m, p; cin >> n >> m >> p; V = n; E = m; for (i = 0; i < m; i++) { ll a, b, c; cin >> a >> b >> c; a--; b--; es[i] = {a, b, p - c}; } bellmanford(0); if (ttt == -1) cout << -1 << endl; else cout << max(0ll, -d[n - 1]) << endl; return 0; }
[ "literal.number.change", "control_flow.branch.if.condition.change" ]
753,911
753,912
u586567203
cpp
p02949
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = double; #define fi first #define se second #define pb push_back #define all(v) (v).begin(), (v).end() #define siz(v) (ll)(v).size() #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repi(i, x, n) for (ll i = x; i < (ll)(n); i++) typedef pair<int, int> P; typedef pair<ll, ll> PL; const ll mod = 1000000007; const ll INF = 10000000000000099; vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1}; ll BF(ll s, vector<vector<PL>> &v, ll V) { vector<ll> d(V, INF); d[s] = 0; ll cnt = 0, pofv; bool update = false; while (1) { update = false; for (int i = 0; i < V; i++) { for (int j = 0; j < siz(v[i]); j++) { if (d[i] != INF && d[v[i][j].fi] > d[i] + v[i][j].se) { update = true; d[v[i][j].fi] = d[i] + v[i][j].se; } } } if (!update) break; cnt++; if (V - 1 == cnt) { pofv = d[V - 1]; } else if (2 * V == cnt) { if (d[V - 1] != pofv) { return INF; } else { return d[V - 1]; } } } return d[V - 1]; } ll n, m, p, ans; vector<vector<PL>> v(2500, vector<PL>(0)); signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> m >> p; ll a, b, c; rep(i, n) { cin >> a >> b >> c; a--; b--; v.at(a).pb({b, -(c - p)}); } ans = BF(0, v, n); if (ans == INF) { cout << -1 << endl; } else { cout << max(-ans, 0ll) << endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = double; #define fi first #define se second #define pb push_back #define all(v) (v).begin(), (v).end() #define siz(v) (ll)(v).size() #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repi(i, x, n) for (ll i = x; i < (ll)(n); i++) typedef pair<int, int> P; typedef pair<ll, ll> PL; const ll mod = 1000000007; const ll INF = 10000000000000099; vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1}; ll BF(ll s, vector<vector<PL>> &v, ll V) { vector<ll> d(V, INF); d[s] = 0; ll cnt = 0, pofv; bool update = false; while (1) { update = false; for (int i = 0; i < V; i++) { for (int j = 0; j < siz(v[i]); j++) { if (d[i] != INF && d[v[i][j].fi] > d[i] + v[i][j].se) { update = true; d[v[i][j].fi] = d[i] + v[i][j].se; } } } if (!update) break; cnt++; if (V - 1 == cnt) { pofv = d[V - 1]; } else if (2 * V == cnt) { if (d[V - 1] != pofv) { return INF; } else { return d[V - 1]; } } } return d[V - 1]; } ll n, m, p, ans; vector<vector<PL>> v(2510, vector<PL>(0)); signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> m >> p; ll a, b, c; rep(i, m) { cin >> a >> b >> c; a--; b--; v.at(a).pb({b, -(c - p)}); } ans = BF(0, v, n); if (ans == INF) { cout << -1 << endl; } else { cout << max(-ans, 0ll) << endl; } }
[ "literal.number.change", "call.arguments.change" ]
753,915
753,916
u317711717
cpp
p02949
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using P = pair<int, int>; using PL = pair<ll, ll>; using vp = vector<P>; using vpl = vector<PL>; template <typename T> constexpr auto inf = numeric_limits<T>::max() / 2; constexpr int INF = inf<int>, MOD = 1000000007; constexpr ll LINF = inf<ll>; #define _ol3(_1, _2, _3, name, ...) name #define _rep(i, n) _repi(i, 0, n) #define _repi(i, a, b) for (int i = a, i##_l = (b); i < i##_l; ++i) #define REP(...) _ol3(__VA_ARGS__, _repi, _rep, )(__VA_ARGS__) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define REPA(i, v) REP(i, v.size()) #define all(v) (v).begin(), (v).end() #define bit(n) (1ll << (n)) #define uniq(v) \ sort(all(v)); \ v.erase(unique(all(v)), v.end()) #define F first #define S second #define endl '\n' #define cho(n, a, b) cout << ((n) ? a : b) << endl void YES(int n) { cho(n, "YES", "NO"); } void Yes(int n) { cho(n, "Yes", "No"); } void Poss(int n) { cho(n, "Possible", "Impossible"); } void _print(ostream &s) {} template <class T, class... U> void _print(ostream &s, T &&t, U &&...u) { s << t << (sizeof...(u) ? ' ' : '\n'); _print(s, u...); } template <class... T> void print(T &&...t) { _print(cout, t...); } #ifndef LOCAL struct osd { template <class T> osd &operator<<(const T &t) { return *this; } }; osd cer_; #define dprint(...) #define cerr cer_ #else template <class... T> void dprint(T &&...t) { _print(cerr, t...); } #endif 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 (a > b) a = b; } template <class T> ostream &operator<<(ostream &o, const vector<T> &v) { for (auto &&i : v) o << i << ' '; return o; } template <class T> istream &operator>>(istream &i, vector<T> &v) { for (T &j : v) i >> j; return i; } template <class T, class U> ostream &operator<<(ostream &o, const pair<T, U> &p) { return o << p.F << ' ' << p.S; } template <class T, class U> istream &operator>>(istream &i, pair<T, U> &p) { return i >> p.F >> p.S; } template <class T> ostream &operator<<(ostream &o, const set<T> &v) { for (auto &&i : v) o << i << ' '; return o; } template <class T> ostream &operator<<(ostream &o, const multiset<T> &v) { for (auto &&i : v) o << i << ' '; return o; } template <class T> vector<T> &operator<<(vector<T> &v, const T &t) { v.push_back(t); return v; } template <class T> set<T> &operator<<(set<T> &v, const T &t) { v.insert(t); return v; } template <class T> multiset<T> &operator<<(multiset<T> &v, const T &t) { v.insert(t); return v; } using len_type = ll; struct Edge { int to; len_type cost; }; vector<vector<Edge>> graph; void bellman_ford(int start, vector<len_type> &dist) { const int n = graph.size(); fill(all(dist), inf<len_type>); dist.resize(n); dist = vector<len_type>(n, inf<len_type>); dist[start] = 0; REP(i, n) { REP(v, n) { REPA(k, graph[v]) { Edge e = graph[v][k]; if (dist[v] != inf<len_type> && dist[e.to] > dist[v] + e.cost) { dist[e.to] = dist[v] + e.cost; if (i == n - 1) dist[e.to] = -inf<len_type>; // return true; // inf } } } } } int main() { cin.tie(0); ios::sync_with_stdio(0); int n, m, p; cin >> n >> m >> p; graph.resize(n); REP(i, m) { int a, b, c; cin >> a >> b >> c; graph[a - 1].push_back({b - 1, (ll)(-c + p)}); } vl d(n); bellman_ford(0, d); dprint(d); if (d[n - 1] == -inf<len_type>) d[n - 1] = 1; else if (d[n - 1] > 0) d[n - 1] = 0; cout << -d[n - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using P = pair<int, int>; using PL = pair<ll, ll>; using vp = vector<P>; using vpl = vector<PL>; template <typename T> constexpr auto inf = numeric_limits<T>::max() / 2; constexpr int INF = inf<int>, MOD = 1000000007; constexpr ll LINF = inf<ll>; #define _ol3(_1, _2, _3, name, ...) name #define _rep(i, n) _repi(i, 0, n) #define _repi(i, a, b) for (int i = a, i##_l = (b); i < i##_l; ++i) #define REP(...) _ol3(__VA_ARGS__, _repi, _rep, )(__VA_ARGS__) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define REPA(i, v) REP(i, v.size()) #define all(v) (v).begin(), (v).end() #define bit(n) (1ll << (n)) #define uniq(v) \ sort(all(v)); \ v.erase(unique(all(v)), v.end()) #define F first #define S second #define endl '\n' #define cho(n, a, b) cout << ((n) ? a : b) << endl void YES(int n) { cho(n, "YES", "NO"); } void Yes(int n) { cho(n, "Yes", "No"); } void Poss(int n) { cho(n, "Possible", "Impossible"); } void _print(ostream &s) {} template <class T, class... U> void _print(ostream &s, T &&t, U &&...u) { s << t << (sizeof...(u) ? ' ' : '\n'); _print(s, u...); } template <class... T> void print(T &&...t) { _print(cout, t...); } #ifndef LOCAL struct osd { template <class T> osd &operator<<(const T &t) { return *this; } }; osd cer_; #define dprint(...) #define cerr cer_ #else template <class... T> void dprint(T &&...t) { _print(cerr, t...); } #endif 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 (a > b) a = b; } template <class T> ostream &operator<<(ostream &o, const vector<T> &v) { for (auto &&i : v) o << i << ' '; return o; } template <class T> istream &operator>>(istream &i, vector<T> &v) { for (T &j : v) i >> j; return i; } template <class T, class U> ostream &operator<<(ostream &o, const pair<T, U> &p) { return o << p.F << ' ' << p.S; } template <class T, class U> istream &operator>>(istream &i, pair<T, U> &p) { return i >> p.F >> p.S; } template <class T> ostream &operator<<(ostream &o, const set<T> &v) { for (auto &&i : v) o << i << ' '; return o; } template <class T> ostream &operator<<(ostream &o, const multiset<T> &v) { for (auto &&i : v) o << i << ' '; return o; } template <class T> vector<T> &operator<<(vector<T> &v, const T &t) { v.push_back(t); return v; } template <class T> set<T> &operator<<(set<T> &v, const T &t) { v.insert(t); return v; } template <class T> multiset<T> &operator<<(multiset<T> &v, const T &t) { v.insert(t); return v; } using len_type = ll; struct Edge { int to; len_type cost; }; vector<vector<Edge>> graph; void bellman_ford(int start, vector<len_type> &dist) { const int n = graph.size(); fill(all(dist), inf<len_type>); dist.resize(n); dist = vector<len_type>(n, inf<len_type>); dist[start] = 0; REP(i, 2 * n) { REP(v, n) { REPA(k, graph[v]) { Edge e = graph[v][k]; if (dist[v] != inf<len_type> && dist[e.to] > dist[v] + e.cost) { dist[e.to] = dist[v] + e.cost; if (i >= n - 1) dist[e.to] = -inf<len_type>; // return true; // inf } } } } } int main() { cin.tie(0); ios::sync_with_stdio(0); int n, m, p; cin >> n >> m >> p; graph.resize(n); REP(i, m) { int a, b, c; cin >> a >> b >> c; graph[a - 1].push_back({b - 1, (ll)(-c + p)}); } vl d(n); bellman_ford(0, d); dprint(d); if (d[n - 1] == -inf<len_type>) d[n - 1] = 1; else if (d[n - 1] > 0) d[n - 1] = 0; cout << -d[n - 1] << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
753,917
753,918
u014847113
cpp
p02949
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using P = pair<int, int>; using PL = pair<ll, ll>; using vp = vector<P>; using vpl = vector<PL>; template <typename T> constexpr auto inf = numeric_limits<T>::max() / 2; constexpr int INF = inf<int>, MOD = 1000000007; constexpr ll LINF = inf<ll>; #define _ol3(_1, _2, _3, name, ...) name #define _rep(i, n) _repi(i, 0, n) #define _repi(i, a, b) for (int i = a, i##_l = (b); i < i##_l; ++i) #define REP(...) _ol3(__VA_ARGS__, _repi, _rep, )(__VA_ARGS__) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define REPA(i, v) REP(i, v.size()) #define all(v) (v).begin(), (v).end() #define bit(n) (1ll << (n)) #define uniq(v) \ sort(all(v)); \ v.erase(unique(all(v)), v.end()) #define F first #define S second #define endl '\n' #define cho(n, a, b) cout << ((n) ? a : b) << endl void YES(int n) { cho(n, "YES", "NO"); } void Yes(int n) { cho(n, "Yes", "No"); } void Poss(int n) { cho(n, "Possible", "Impossible"); } void _print(ostream &s) {} template <class T, class... U> void _print(ostream &s, T &&t, U &&...u) { s << t << (sizeof...(u) ? ' ' : '\n'); _print(s, u...); } template <class... T> void print(T &&...t) { _print(cout, t...); } #ifndef LOCAL struct osd { template <class T> osd &operator<<(const T &t) { return *this; } }; osd cer_; #define dprint(...) #define cerr cer_ #else template <class... T> void dprint(T &&...t) { _print(cerr, t...); } #endif 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 (a > b) a = b; } template <class T> ostream &operator<<(ostream &o, const vector<T> &v) { for (auto &&i : v) o << i << ' '; return o; } template <class T> istream &operator>>(istream &i, vector<T> &v) { for (T &j : v) i >> j; return i; } template <class T, class U> ostream &operator<<(ostream &o, const pair<T, U> &p) { return o << p.F << ' ' << p.S; } template <class T, class U> istream &operator>>(istream &i, pair<T, U> &p) { return i >> p.F >> p.S; } template <class T> ostream &operator<<(ostream &o, const set<T> &v) { for (auto &&i : v) o << i << ' '; return o; } template <class T> ostream &operator<<(ostream &o, const multiset<T> &v) { for (auto &&i : v) o << i << ' '; return o; } template <class T> vector<T> &operator<<(vector<T> &v, const T &t) { v.push_back(t); return v; } template <class T> set<T> &operator<<(set<T> &v, const T &t) { v.insert(t); return v; } template <class T> multiset<T> &operator<<(multiset<T> &v, const T &t) { v.insert(t); return v; } using len_type = ll; struct Edge { int to; len_type cost; }; vector<vector<Edge>> graph; void bellman_ford(int start, vector<len_type> &dist) { const int n = graph.size(); fill(all(dist), inf<len_type>); dist.resize(n); dist = vector<len_type>(n, inf<len_type>); dist[start] = 0; REP(i, 2 * n) { REP(v, n) { REPA(k, graph[v]) { Edge e = graph[v][k]; if (dist[v] != inf<len_type> && dist[e.to] > dist[v] + e.cost) { dist[e.to] = dist[v] + e.cost; if (i == n - 1) dist[e.to] = -inf<len_type>; // return true; // inf } } } } } int main() { cin.tie(0); ios::sync_with_stdio(0); int n, m, p; cin >> n >> m >> p; graph.resize(n); REP(i, m) { int a, b, c; cin >> a >> b >> c; graph[a - 1].push_back({b - 1, (ll)(-c + p)}); } vl d(n); bellman_ford(0, d); dprint(d); if (d[n - 1] == -inf<len_type>) d[n - 1] = 1; else if (d[n - 1] > 0) d[n - 1] = 0; cout << -d[n - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using P = pair<int, int>; using PL = pair<ll, ll>; using vp = vector<P>; using vpl = vector<PL>; template <typename T> constexpr auto inf = numeric_limits<T>::max() / 2; constexpr int INF = inf<int>, MOD = 1000000007; constexpr ll LINF = inf<ll>; #define _ol3(_1, _2, _3, name, ...) name #define _rep(i, n) _repi(i, 0, n) #define _repi(i, a, b) for (int i = a, i##_l = (b); i < i##_l; ++i) #define REP(...) _ol3(__VA_ARGS__, _repi, _rep, )(__VA_ARGS__) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define REPA(i, v) REP(i, v.size()) #define all(v) (v).begin(), (v).end() #define bit(n) (1ll << (n)) #define uniq(v) \ sort(all(v)); \ v.erase(unique(all(v)), v.end()) #define F first #define S second #define endl '\n' #define cho(n, a, b) cout << ((n) ? a : b) << endl void YES(int n) { cho(n, "YES", "NO"); } void Yes(int n) { cho(n, "Yes", "No"); } void Poss(int n) { cho(n, "Possible", "Impossible"); } void _print(ostream &s) {} template <class T, class... U> void _print(ostream &s, T &&t, U &&...u) { s << t << (sizeof...(u) ? ' ' : '\n'); _print(s, u...); } template <class... T> void print(T &&...t) { _print(cout, t...); } #ifndef LOCAL struct osd { template <class T> osd &operator<<(const T &t) { return *this; } }; osd cer_; #define dprint(...) #define cerr cer_ #else template <class... T> void dprint(T &&...t) { _print(cerr, t...); } #endif 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 (a > b) a = b; } template <class T> ostream &operator<<(ostream &o, const vector<T> &v) { for (auto &&i : v) o << i << ' '; return o; } template <class T> istream &operator>>(istream &i, vector<T> &v) { for (T &j : v) i >> j; return i; } template <class T, class U> ostream &operator<<(ostream &o, const pair<T, U> &p) { return o << p.F << ' ' << p.S; } template <class T, class U> istream &operator>>(istream &i, pair<T, U> &p) { return i >> p.F >> p.S; } template <class T> ostream &operator<<(ostream &o, const set<T> &v) { for (auto &&i : v) o << i << ' '; return o; } template <class T> ostream &operator<<(ostream &o, const multiset<T> &v) { for (auto &&i : v) o << i << ' '; return o; } template <class T> vector<T> &operator<<(vector<T> &v, const T &t) { v.push_back(t); return v; } template <class T> set<T> &operator<<(set<T> &v, const T &t) { v.insert(t); return v; } template <class T> multiset<T> &operator<<(multiset<T> &v, const T &t) { v.insert(t); return v; } using len_type = ll; struct Edge { int to; len_type cost; }; vector<vector<Edge>> graph; void bellman_ford(int start, vector<len_type> &dist) { const int n = graph.size(); fill(all(dist), inf<len_type>); dist.resize(n); dist = vector<len_type>(n, inf<len_type>); dist[start] = 0; REP(i, 2 * n) { REP(v, n) { REPA(k, graph[v]) { Edge e = graph[v][k]; if (dist[v] != inf<len_type> && dist[e.to] > dist[v] + e.cost) { dist[e.to] = dist[v] + e.cost; if (i >= n - 1) dist[e.to] = -inf<len_type>; // return true; // inf } } } } } int main() { cin.tie(0); ios::sync_with_stdio(0); int n, m, p; cin >> n >> m >> p; graph.resize(n); REP(i, m) { int a, b, c; cin >> a >> b >> c; graph[a - 1].push_back({b - 1, (ll)(-c + p)}); } vl d(n); bellman_ford(0, d); dprint(d); if (d[n - 1] == -inf<len_type>) d[n - 1] = 1; else if (d[n - 1] > 0) d[n - 1] = 0; cout << -d[n - 1] << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
753,919
753,918
u014847113
cpp
p02949
#include "bits/stdc++.h" #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = int(a), i##_len = (b); i < i##_len; ++i) #define MSVC_UNKO(x) x #define rep(...) \ MSVC_UNKO(_overload3(__VA_ARGS__, repi, _rep, _rep)(__VA_ARGS__)) #define all(c) c.begin(), c.end() #define mp make_pair #define write(x) cout << (x) << '\n' using namespace std; typedef long long ll; template <class T> using vv = vector<vector<T>>; template <class T> auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); } template <class T1, class T2> bool chmax(T1 &a, const T2 &b) { return a < b ? a = b, 1 : 0; } template <class T1, class T2> bool chmin(T1 &a, const T2 &b) { return b < a ? a = b, 1 : 0; } constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60; struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; } aaaa; int N, M, P; vector<vector<pair<ll, int>>> graph; vector<ll> dist; vector<vector<int>> igraph; vector<bool> visited; void dfs(int v) { visited[v] = true; for (int u : igraph[v]) { if (!visited[u]) { dfs(u); } } } bool spfa(int s) { dist.assign(N, LINF); dist[s] = 0; queue<int> que; que.push(s); vector<bool> in_queue(N); vector<int> cnt_update(N, 0); cnt_update[s]++; while (!que.empty()) { int v = que.front(); que.pop(); in_queue[v] = false; for (auto &e : graph[v]) { if (dist[v] + e.first < dist[e.second]) { dist[e.second] = dist[v] + e.first; if (!in_queue[e.second]) { que.push(e.second); in_queue[e.second] = true; cnt_update[e.second]++; if (cnt_update[e.second] == 2 * N && e.second == N - 1) { return true; } if (cnt_update[e.second] == 2 * N) { if (visited[e.second]) { return true; } else { return false; } } } } } } return false; } int main() { cin >> N >> M >> P; graph.resize(N); igraph.resize(N); rep(i, M) { int a, b, c; cin >> a >> b >> c; a--; b--; graph[a].emplace_back(P - c, b); igraph[a].push_back(b); } visited.assign(N, false); dfs(N - 1); bool nega_cycle = spfa(0); if (nega_cycle) { write(-1); } else { write(max(0LL, -dist[N - 1])); } }
#include "bits/stdc++.h" #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = int(a), i##_len = (b); i < i##_len; ++i) #define MSVC_UNKO(x) x #define rep(...) \ MSVC_UNKO(_overload3(__VA_ARGS__, repi, _rep, _rep)(__VA_ARGS__)) #define all(c) c.begin(), c.end() #define mp make_pair #define write(x) cout << (x) << '\n' using namespace std; typedef long long ll; template <class T> using vv = vector<vector<T>>; template <class T> auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); } template <class T1, class T2> bool chmax(T1 &a, const T2 &b) { return a < b ? a = b, 1 : 0; } template <class T1, class T2> bool chmin(T1 &a, const T2 &b) { return b < a ? a = b, 1 : 0; } constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60; struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; } aaaa; int N, M, P; vector<vector<pair<ll, int>>> graph; vector<ll> dist; vector<vector<int>> igraph; vector<bool> visited; void dfs(int v) { visited[v] = true; for (int u : igraph[v]) { if (!visited[u]) { dfs(u); } } } bool spfa(int s) { dist.assign(N, LINF); dist[s] = 0; queue<int> que; que.push(s); vector<bool> in_queue(N); vector<int> cnt_update(N, 0); cnt_update[s]++; while (!que.empty()) { int v = que.front(); que.pop(); in_queue[v] = false; for (auto &e : graph[v]) { if (dist[v] + e.first < dist[e.second]) { dist[e.second] = dist[v] + e.first; if (!in_queue[e.second]) { que.push(e.second); in_queue[e.second] = true; cnt_update[e.second]++; if (cnt_update[e.second] == 2 * N && e.second == N - 1) { return true; } if (cnt_update[e.second] == 4 * N) { if (visited[e.second]) { return true; } else { return false; } } } } } } return false; } int main() { cin >> N >> M >> P; graph.resize(N); igraph.resize(N); rep(i, M) { int a, b, c; cin >> a >> b >> c; a--; b--; graph[a].emplace_back(P - c, b); igraph[b].push_back(a); } visited.assign(N, false); dfs(N - 1); bool nega_cycle = spfa(0); if (nega_cycle) { write(-1); } else { write(max(0LL, -dist[N - 1])); } }
[ "literal.number.change", "control_flow.branch.if.condition.change", "identifier.change", "variable_access.subscript.index.change", "call.arguments.change" ]
753,923
753,924
u751488284
cpp
p02949
#include <bits/stdc++.h> #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) // const bool debug=true; const bool debug = false; #define DEBUG if (debug == true) using namespace std; typedef long long ll; typedef unsigned long long ull; const ll MOD = 1000000007; const ll cutoff = 10000000000000000; int main(void) { ll n, m, p; cin >> n >> m >> p; ll d[n]; const ll lim = 1LL << 60; ll a[n], b[n], c[n]; bool mat[n][n] = {}; rep(i, n) { d[i] = lim; } rep(i, m) { cin >> a[i] >> b[i] >> c[i]; a[i]--; b[i]--; c[i] -= p; c[i] *= -1; mat[a[i]][b[i]] = true; } d[0] = 0; bool closed[n] = {}; queue<int> que; DEBUG { rep(i, n) { rep(j, n) { cout << mat[i][j] << " "; } cout << endl; } } rep(i, n + 1) { rep(j, m) { if (d[a[j]] != lim && d[b[j]] > d[a[j]] + c[j]) { d[b[j]] = d[a[j]] + c[j]; if (i == n) { closed[b[j]] = true; que.push(b[j]); } } } } DEBUG { rep(i, n) { cout << closed[i] << endl; } } while (!que.empty()) { int cur = que.front(); DEBUG { cout << "front : " << cur << endl; } rep(i, n) { if (mat[cur][i] && !closed[i] && d[cur] <= cutoff) { DEBUG { cout << i << endl; } que.push(i); closed[i] = true; } } que.pop(); } if (closed[n - 1] == true) { cout << -1 << endl; } else { cout << max(0LL, -d[n - 1]) << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) // const bool debug=true; const bool debug = false; #define DEBUG if (debug == true) using namespace std; typedef long long ll; typedef unsigned long long ull; const ll MOD = 1000000007; const ll cutoff = 10000000000000000; int main(void) { ll n, m, p; cin >> n >> m >> p; ll d[n]; const ll lim = 1LL << 60; ll a[m], b[m], c[m]; bool mat[n][n] = {}; rep(i, n) { d[i] = lim; } rep(i, m) { cin >> a[i] >> b[i] >> c[i]; a[i]--; b[i]--; c[i] -= p; c[i] *= -1; mat[a[i]][b[i]] = true; } d[0] = 0; bool closed[n] = {}; queue<int> que; DEBUG { rep(i, n) { rep(j, n) { cout << mat[i][j] << " "; } cout << endl; } } rep(i, n + 1) { rep(j, m) { if (d[a[j]] != lim && d[b[j]] > d[a[j]] + c[j]) { d[b[j]] = d[a[j]] + c[j]; if (i == n) { closed[b[j]] = true; que.push(b[j]); } } } } DEBUG { rep(i, n) { cout << closed[i] << endl; } } while (!que.empty()) { int cur = que.front(); DEBUG { cout << "front : " << cur << endl; } rep(i, n) { if (mat[cur][i] && !closed[i] && d[cur] <= cutoff) { DEBUG { cout << i << endl; } que.push(i); closed[i] = true; } } que.pop(); } if (closed[n - 1] == true) { cout << -1 << endl; } else { cout << max(0LL, -d[n - 1]) << endl; } return 0; }
[ "identifier.change", "variable_declaration.array_dimensions.change" ]
753,929
753,930
u076566148
cpp
p02949
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPr(i, n) for (int i = (n)-1; i >= 0; --i) #define FORq(i, m, n) for (int i = (m); i <= (n); ++i) #define FORqr(i, m, n) for (int i = (n); i >= (m); --i) #define PB push_back #define MP make_pair #define DEBUG printf("%s\n", "debug") #define fst first #define snd second #define SIN(x, S) (S.count(x) != 0) #define M0(x) memset(x, 0, sizeof(x)) #define FILL(x, y) memset(x, y, sizeof(x)) #define MM(x) memset(x, -1, sizeof(x)) #define ALL(x) (x).begin(), (x).end() #define SCD(n) scanf("%d", &n) #define SCD2(m, n) scanf("%d%d", &m, &n) #define SCD3(m, n, k) scanf("%d%d%d", &m, &n, &k) #define SCLLD(n) scanf("%lld", &n) #define SCLLD2(m, n) scanf("%lld%lld", &m, &n) #define SCLLD3(m, n, k) scanf("%lld%lld%lld", &m, &n, &k) using namespace std; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef long long ll; typedef long long integer; /////////////////////////////////////////////// const ll MOD = 1e9 + 7; ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } 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; } /////////////////////////////////////////////// /*(._.)*/ const long long INF = 9223372036854775000; const int VMAX = 3000; const int EMAX = 5000; struct Edge { int from; int to; int cost; }; int main() { // 1 --> N minimum cost ll N, M, P; cin >> N >> M >> P; struct Edge e[EMAX]; long long d[VMAX]; bool negcycle[VMAX] = {}; REP(i, M) { ll a, b, c; cin >> a >> b >> c; e[i].from = b; e[i].to = a; // reverse e[i].cost = -c + P; // -1 } REP(i, VMAX) { d[i] = INF; } d[N] = 0; REP(i, N - 1) { // loop V times --> NEGCYCLE bool update = false; REP(j, M) { int u = e[j].from; int v = e[j].to; ll c = e[j].cost; if ((d[u] + c < d[v]) and (d[u] != INF)) { // s-->uへ現状行けないときを弾く d[v] = d[u] + c; update = true; } } } ll ans = d[1]; REP(i, N) { REP(j, M) { int u = e[j].from; int v = e[j].to; ll c = e[j].cost; if (d[u] == INF) continue; if (d[v] > d[u] + c) { d[v] = d[u] + c; negcycle[v] = true; } if (negcycle[u] == true) { negcycle[v] = true; } } } if (negcycle[N]) { printf("-1"); return 0; } cout << max(0LL, -ans) << endl; return 0; }
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPr(i, n) for (int i = (n)-1; i >= 0; --i) #define FORq(i, m, n) for (int i = (m); i <= (n); ++i) #define FORqr(i, m, n) for (int i = (n); i >= (m); --i) #define PB push_back #define MP make_pair #define DEBUG printf("%s\n", "debug") #define fst first #define snd second #define SIN(x, S) (S.count(x) != 0) #define M0(x) memset(x, 0, sizeof(x)) #define FILL(x, y) memset(x, y, sizeof(x)) #define MM(x) memset(x, -1, sizeof(x)) #define ALL(x) (x).begin(), (x).end() #define SCD(n) scanf("%d", &n) #define SCD2(m, n) scanf("%d%d", &m, &n) #define SCD3(m, n, k) scanf("%d%d%d", &m, &n, &k) #define SCLLD(n) scanf("%lld", &n) #define SCLLD2(m, n) scanf("%lld%lld", &m, &n) #define SCLLD3(m, n, k) scanf("%lld%lld%lld", &m, &n, &k) using namespace std; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef long long ll; typedef long long integer; /////////////////////////////////////////////// const ll MOD = 1e9 + 7; ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } 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; } /////////////////////////////////////////////// /*(._.)*/ const long long INF = 9223372036854775000; const int VMAX = 3000; const int EMAX = 6000; struct Edge { int from; int to; ll cost; }; int main() { // 1 --> N minimum cost ll N, M, P; cin >> N >> M >> P; struct Edge e[EMAX]; long long d[VMAX]; bool negcycle[VMAX] = {}; REP(i, M) { ll a, b, c; cin >> a >> b >> c; e[i].from = b; e[i].to = a; // reverse e[i].cost = -c + P; // -1 } REP(i, VMAX) { d[i] = INF; } d[N] = 0; REP(i, N - 1) { // loop V times --> NEGCYCLE bool update = false; REP(j, M) { int u = e[j].from; int v = e[j].to; ll c = e[j].cost; if ((d[u] + c < d[v]) and (d[u] != INF)) { // s-->uへ現状行けないときを弾く d[v] = d[u] + c; update = true; } } } ll ans = d[1]; REP(i, N) { REP(j, M) { int u = e[j].from; int v = e[j].to; ll c = e[j].cost; if (d[u] == INF) continue; if (d[v] > d[u] + c) { d[v] = d[u] + c; negcycle[v] = true; } if (negcycle[u] == true) { negcycle[v] = true; } } } if (negcycle[1]) { printf("-1"); return 0; } cout << max(0LL, -ans) << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "identifier.replace.remove", "literal.replace.add", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
753,932
753,933
u236433947
cpp
p02949
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPr(i, n) for (int i = (n)-1; i >= 0; --i) #define FORq(i, m, n) for (int i = (m); i <= (n); ++i) #define FORqr(i, m, n) for (int i = (n); i >= (m); --i) #define PB push_back #define MP make_pair #define DEBUG printf("%s\n", "debug") #define fst first #define snd second #define SIN(x, S) (S.count(x) != 0) #define M0(x) memset(x, 0, sizeof(x)) #define FILL(x, y) memset(x, y, sizeof(x)) #define MM(x) memset(x, -1, sizeof(x)) #define ALL(x) (x).begin(), (x).end() #define SCD(n) scanf("%d", &n) #define SCD2(m, n) scanf("%d%d", &m, &n) #define SCD3(m, n, k) scanf("%d%d%d", &m, &n, &k) #define SCLLD(n) scanf("%lld", &n) #define SCLLD2(m, n) scanf("%lld%lld", &m, &n) #define SCLLD3(m, n, k) scanf("%lld%lld%lld", &m, &n, &k) using namespace std; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef long long ll; typedef long long integer; /////////////////////////////////////////////// const ll MOD = 1e9 + 7; ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } 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; } /////////////////////////////////////////////// /*(._.)*/ const long long INF = 9223372036854775000; const int VMAX = 3000; const int EMAX = 6000; struct Edge { int from; int to; int cost; }; int main() { // 1 --> N minimum cost ll N, M, P; cin >> N >> M >> P; struct Edge e[EMAX]; long long d[VMAX]; bool negcycle[VMAX] = {}; REP(i, M) { ll a, b, c; cin >> a >> b >> c; e[i].from = b; e[i].to = a; // reverse e[i].cost = -c + P; // -1 } REP(i, VMAX) { d[i] = INF; } d[N] = 0; REP(i, N - 1) { // loop V times --> NEGCYCLE bool update = false; REP(j, M) { int u = e[j].from; int v = e[j].to; int c = e[j].cost; if ((d[u] + c < d[v]) and (d[u] != INF)) { // s-->uへ現状行けないときを弾く d[v] = d[u] + c; update = true; } } } ll ans = d[1]; REP(i, N) { REP(j, M) { int u = e[j].from; int v = e[j].to; int c = e[j].cost; if (d[u] == INF) continue; if (d[v] > d[u] + c) { d[v] = d[u] + c; negcycle[v] = true; } if (negcycle[u] == true) { negcycle[v] = true; } } } if (negcycle[N]) { printf("-1"); return 0; } cout << max(0LL, -ans) << endl; return 0; }
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPr(i, n) for (int i = (n)-1; i >= 0; --i) #define FORq(i, m, n) for (int i = (m); i <= (n); ++i) #define FORqr(i, m, n) for (int i = (n); i >= (m); --i) #define PB push_back #define MP make_pair #define DEBUG printf("%s\n", "debug") #define fst first #define snd second #define SIN(x, S) (S.count(x) != 0) #define M0(x) memset(x, 0, sizeof(x)) #define FILL(x, y) memset(x, y, sizeof(x)) #define MM(x) memset(x, -1, sizeof(x)) #define ALL(x) (x).begin(), (x).end() #define SCD(n) scanf("%d", &n) #define SCD2(m, n) scanf("%d%d", &m, &n) #define SCD3(m, n, k) scanf("%d%d%d", &m, &n, &k) #define SCLLD(n) scanf("%lld", &n) #define SCLLD2(m, n) scanf("%lld%lld", &m, &n) #define SCLLD3(m, n, k) scanf("%lld%lld%lld", &m, &n, &k) using namespace std; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef long long ll; typedef long long integer; /////////////////////////////////////////////// const ll MOD = 1e9 + 7; ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } 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; } /////////////////////////////////////////////// /*(._.)*/ const long long INF = 9223372036854775000; const int VMAX = 3000; const int EMAX = 6000; struct Edge { int from; int to; ll cost; }; int main() { // 1 --> N minimum cost ll N, M, P; cin >> N >> M >> P; struct Edge e[EMAX]; long long d[VMAX]; bool negcycle[VMAX] = {}; REP(i, M) { ll a, b, c; cin >> a >> b >> c; e[i].from = b; e[i].to = a; // reverse e[i].cost = -c + P; // -1 } REP(i, VMAX) { d[i] = INF; } d[N] = 0; REP(i, N - 1) { // loop V times --> NEGCYCLE bool update = false; REP(j, M) { int u = e[j].from; int v = e[j].to; ll c = e[j].cost; if ((d[u] + c < d[v]) and (d[u] != INF)) { // s-->uへ現状行けないときを弾く d[v] = d[u] + c; update = true; } } } ll ans = d[1]; REP(i, N) { REP(j, M) { int u = e[j].from; int v = e[j].to; ll c = e[j].cost; if (d[u] == INF) continue; if (d[v] > d[u] + c) { d[v] = d[u] + c; negcycle[v] = true; } if (negcycle[u] == true) { negcycle[v] = true; } } } if (negcycle[1]) { printf("-1"); return 0; } cout << max(0LL, -ans) << endl; return 0; }
[ "variable_declaration.type.change", "identifier.replace.remove", "literal.replace.add", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
753,934
753,933
u236433947
cpp
p02949
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPr(i, n) for (int i = (n)-1; i >= 0; --i) #define FORq(i, m, n) for (int i = (m); i <= (n); ++i) #define FORqr(i, m, n) for (int i = (n); i >= (m); --i) #define PB push_back #define MP make_pair #define DEBUG printf("%s\n", "debug") #define fst first #define snd second #define SIN(x, S) (S.count(x) != 0) #define M0(x) memset(x, 0, sizeof(x)) #define FILL(x, y) memset(x, y, sizeof(x)) #define MM(x) memset(x, -1, sizeof(x)) #define ALL(x) (x).begin(), (x).end() #define SCD(n) scanf("%d", &n) #define SCD2(m, n) scanf("%d%d", &m, &n) #define SCD3(m, n, k) scanf("%d%d%d", &m, &n, &k) #define SCLLD(n) scanf("%lld", &n) #define SCLLD2(m, n) scanf("%lld%lld", &m, &n) #define SCLLD3(m, n, k) scanf("%lld%lld%lld", &m, &n, &k) using namespace std; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef long long ll; typedef long long integer; /////////////////////////////////////////////// const ll MOD = 1e9 + 7; ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } 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; } /////////////////////////////////////////////// /*(._.)*/ const long long INF = 9223372036854775000; const int VMAX = 3000; const int EMAX = 5000; struct Edge { int from; int to; int cost; }; int main() { // 1 --> N minimum cost ll N, M, P; cin >> N >> M >> P; struct Edge e[EMAX]; long long d[VMAX]; bool negcycle[VMAX] = {}; REP(i, M) { ll a, b, c; cin >> a >> b >> c; e[i].from = b; e[i].to = a; // reverse e[i].cost = -c + P; // -1 } REP(i, VMAX) { d[i] = INF; } d[N] = 0; REP(i, N - 1) { // loop V times --> NEGCYCLE bool update = false; REP(j, M) { int u = e[j].from; int v = e[j].to; int c = e[j].cost; if ((d[u] + c < d[v]) and (d[u] != INF)) { // s-->uへ現状行けないときを弾く d[v] = d[u] + c; update = true; } } } ll ans = d[1]; REP(i, N) { REP(j, M) { int u = e[j].from; int v = e[j].to; int c = e[j].cost; if (d[u] == INF) continue; if (d[v] > d[u] + c) { d[v] = d[u] + c; negcycle[v] = true; } if (negcycle[u] == true) { negcycle[v] = true; } } } if (negcycle[N]) { printf("-1"); return 0; } cout << max(0LL, -ans) << endl; return 0; }
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPr(i, n) for (int i = (n)-1; i >= 0; --i) #define FORq(i, m, n) for (int i = (m); i <= (n); ++i) #define FORqr(i, m, n) for (int i = (n); i >= (m); --i) #define PB push_back #define MP make_pair #define DEBUG printf("%s\n", "debug") #define fst first #define snd second #define SIN(x, S) (S.count(x) != 0) #define M0(x) memset(x, 0, sizeof(x)) #define FILL(x, y) memset(x, y, sizeof(x)) #define MM(x) memset(x, -1, sizeof(x)) #define ALL(x) (x).begin(), (x).end() #define SCD(n) scanf("%d", &n) #define SCD2(m, n) scanf("%d%d", &m, &n) #define SCD3(m, n, k) scanf("%d%d%d", &m, &n, &k) #define SCLLD(n) scanf("%lld", &n) #define SCLLD2(m, n) scanf("%lld%lld", &m, &n) #define SCLLD3(m, n, k) scanf("%lld%lld%lld", &m, &n, &k) using namespace std; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef long long ll; typedef long long integer; /////////////////////////////////////////////// const ll MOD = 1e9 + 7; ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } 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; } /////////////////////////////////////////////// /*(._.)*/ const long long INF = 9223372036854775000; const int VMAX = 3000; const int EMAX = 6000; struct Edge { int from; int to; ll cost; }; int main() { // 1 --> N minimum cost ll N, M, P; cin >> N >> M >> P; struct Edge e[EMAX]; long long d[VMAX]; bool negcycle[VMAX] = {}; REP(i, M) { ll a, b, c; cin >> a >> b >> c; e[i].from = b; e[i].to = a; // reverse e[i].cost = -c + P; // -1 } REP(i, VMAX) { d[i] = INF; } d[N] = 0; REP(i, N - 1) { // loop V times --> NEGCYCLE bool update = false; REP(j, M) { int u = e[j].from; int v = e[j].to; ll c = e[j].cost; if ((d[u] + c < d[v]) and (d[u] != INF)) { // s-->uへ現状行けないときを弾く d[v] = d[u] + c; update = true; } } } ll ans = d[1]; REP(i, N) { REP(j, M) { int u = e[j].from; int v = e[j].to; ll c = e[j].cost; if (d[u] == INF) continue; if (d[v] > d[u] + c) { d[v] = d[u] + c; negcycle[v] = true; } if (negcycle[u] == true) { negcycle[v] = true; } } } if (negcycle[1]) { printf("-1"); return 0; } cout << max(0LL, -ans) << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "variable_declaration.type.change", "identifier.replace.remove", "literal.replace.add", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
753,935
753,933
u236433947
cpp
p02949
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPr(i, n) for (int i = (n)-1; i >= 0; --i) #define FORq(i, m, n) for (int i = (m); i <= (n); ++i) #define FORqr(i, m, n) for (int i = (n); i >= (m); --i) #define PB push_back #define MP make_pair #define DEBUG printf("%s\n", "debug") #define fst first #define snd second #define SIN(x, S) (S.count(x) != 0) #define M0(x) memset(x, 0, sizeof(x)) #define FILL(x, y) memset(x, y, sizeof(x)) #define MM(x) memset(x, -1, sizeof(x)) #define ALL(x) (x).begin(), (x).end() #define SCD(n) scanf("%d", &n) #define SCD2(m, n) scanf("%d%d", &m, &n) #define SCD3(m, n, k) scanf("%d%d%d", &m, &n, &k) #define SCLLD(n) scanf("%lld", &n) #define SCLLD2(m, n) scanf("%lld%lld", &m, &n) #define SCLLD3(m, n, k) scanf("%lld%lld%lld", &m, &n, &k) using namespace std; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef long long ll; typedef long long integer; /////////////////////////////////////////////// const ll MOD = 1e9 + 7; ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } 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; } /////////////////////////////////////////////// /*(._.)*/ const long long INF = 9223372036854775000; const int VMAX = 3000; const int EMAX = 5000; struct Edge { int from; int to; int cost; }; int main() { // 1 --> N minimum cost ll N, M, P; cin >> N >> M >> P; struct Edge e[EMAX]; long long d[VMAX]; bool negcycle[VMAX] = {}; REP(i, M) { ll a, b, c; cin >> a >> b >> c; e[i].from = b; e[i].to = a; // reverse e[i].cost = -c + P; // -1 } REP(i, VMAX) { d[i] = INF; } d[N] = 0; REP(i, N - 1) { // loop V times --> NEGCYCLE bool update = false; REP(j, M) { int u = e[j].from; int v = e[j].to; ll c = e[j].cost; if ((d[u] + c < d[v]) and (d[u] != INF)) { // s-->uへ現状行けないときを弾く d[v] = d[u] + c; update = true; } } } ll ans = d[1]; REP(i, N) { REP(j, M) { int u = e[j].from; int v = e[j].to; ll c = e[j].cost; if (d[u] == INF) continue; if (d[v] > d[u] + c) { d[v] = d[u] + c; negcycle[v] = true; } if (negcycle[u] == true) { negcycle[v] = true; } } } if (negcycle[N]) { printf("-1"); return 0; } cout << max(0LL, -ans) << endl; return 0; }
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPr(i, n) for (int i = (n)-1; i >= 0; --i) #define FORq(i, m, n) for (int i = (m); i <= (n); ++i) #define FORqr(i, m, n) for (int i = (n); i >= (m); --i) #define PB push_back #define MP make_pair #define DEBUG printf("%s\n", "debug") #define fst first #define snd second #define SIN(x, S) (S.count(x) != 0) #define M0(x) memset(x, 0, sizeof(x)) #define FILL(x, y) memset(x, y, sizeof(x)) #define MM(x) memset(x, -1, sizeof(x)) #define ALL(x) (x).begin(), (x).end() #define SCD(n) scanf("%d", &n) #define SCD2(m, n) scanf("%d%d", &m, &n) #define SCD3(m, n, k) scanf("%d%d%d", &m, &n, &k) #define SCLLD(n) scanf("%lld", &n) #define SCLLD2(m, n) scanf("%lld%lld", &m, &n) #define SCLLD3(m, n, k) scanf("%lld%lld%lld", &m, &n, &k) using namespace std; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef long long ll; typedef long long integer; /////////////////////////////////////////////// const ll MOD = 1e9 + 7; ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } 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; } /////////////////////////////////////////////// /*(._.)*/ const long long INF = 9223372036854775000; const int VMAX = 3000; const int EMAX = 5000; struct Edge { int from; int to; int cost; }; int main() { // 1 --> N minimum cost ll N, M, P; cin >> N >> M >> P; struct Edge e[EMAX]; long long d[VMAX]; bool negcycle[VMAX] = {}; REP(i, M) { ll a, b, c; cin >> a >> b >> c; e[i].from = b; e[i].to = a; // reverse e[i].cost = -c + P; // -1 } REP(i, VMAX) { d[i] = INF; } d[N] = 0; REP(i, N - 1) { // loop V times --> NEGCYCLE bool update = false; REP(j, M) { int u = e[j].from; int v = e[j].to; int c = e[j].cost; if ((d[u] + c < d[v]) and (d[u] != INF)) { // s-->uへ現状行けないときを弾く d[v] = d[u] + c; update = true; } } } ll ans = d[1]; REP(i, N) { REP(j, M) { int u = e[j].from; int v = e[j].to; int c = e[j].cost; if (d[u] == INF) continue; if (d[v] > d[u] + c) { d[v] = d[u] + c; negcycle[v] = true; } if (negcycle[u] == true) { negcycle[v] = true; } } } if (negcycle[1]) { printf("-1"); return 0; } cout << max(0LL, -ans) << endl; return 0; }
[ "variable_declaration.type.change", "identifier.replace.remove", "literal.replace.add", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
753,932
753,936
u236433947
cpp