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 |
|---|---|---|---|---|---|---|---|
p03054 | #include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define REP(i, l, n) for (int i = (l), i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main() {
int h, w, n;
cin >> h >> w >> n;
int x, y;
cin >> x >> y;
string s, t;
cin >> s >> t;
int f = 0;
int ny = y;
REP(i, 0, n) {
if (s[i] == 'L') {
ny--;
}
if (ny <= 0) {
f = 1;
}
if (t[i] == 'R') {
ny = min(ny + 1, w);
}
if (ny <= 0) {
f = 1;
}
}
ny = y;
REP(i, 0, n) {
if (s[i] == 'R') {
ny++;
}
if (ny > w) {
f = 1;
}
if (t[i] == 'L') {
ny = max(ny - 1, 1);
}
if (ny > w) {
f = 1;
}
}
int nx = x;
REP(i, 0, n) {
if (s[i] == 'U') {
nx--;
}
if (nx <= 0) {
f = 1;
}
if (t[i] == 'D') {
nx = min(nx + 1, 1);
}
if (nx <= 0) {
f = 1;
}
}
nx = x;
REP(i, 0, n) {
if (s[i] == 'D') {
nx++;
}
if (nx > x) {
f = 1;
}
if (t[i] == 'U') {
nx = max(nx - 1, 1);
}
if (nx > x) {
f = 1;
}
}
if (f == 1) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
} | #include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define REP(i, l, n) for (int i = (l), i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main() {
int h, w, n;
cin >> h >> w >> n;
int x, y;
cin >> x >> y;
string s, t;
cin >> s >> t;
int f = 0;
int ny = y;
REP(i, 0, n) {
if (s[i] == 'L') {
ny--;
}
if (ny <= 0) {
f = 1;
}
if (t[i] == 'R') {
ny = min(ny + 1, w);
}
if (ny <= 0) {
f = 1;
}
}
ny = y;
REP(i, 0, n) {
if (s[i] == 'R') {
ny++;
}
if (ny > w) {
f = 1;
}
if (t[i] == 'L') {
ny = max(ny - 1, 1);
}
if (ny > w) {
f = 1;
}
}
int nx = x;
REP(i, 0, n) {
if (s[i] == 'U') {
nx--;
}
if (nx <= 0) {
f = 1;
}
if (t[i] == 'D') {
nx = min(nx + 1, h);
}
if (nx <= 0) {
f = 1;
}
}
nx = x;
REP(i, 0, n) {
if (s[i] == 'D') {
nx++;
}
if (nx > h) {
f = 1;
}
if (t[i] == 'U') {
nx = max(nx - 1, 1);
}
if (nx > h) {
f = 1;
}
}
if (f == 1) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
} | [
"assignment.value.change",
"identifier.replace.add",
"literal.replace.remove",
"call.arguments.change",
"identifier.change",
"control_flow.branch.if.condition.change"
] | 869,548 | 869,546 | u639426108 | cpp |
p03054 | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define INF 100000000000
#define MAX 200001
#define MOD 1000000007
int main() {
int H, W, N;
cin >> H >> W >> N;
int sr, sc;
cin >> sr >> sc;
string S, T;
cin >> S >> T;
int w_l = 1;
int w_r = W;
int h_u = 1;
int h_d = H;
int flag = 0;
for (int i = N - 1; i >= 0; i--) {
if (i != N - 1) {
if (T[i] == 'R')
w_l = max(1, w_l - 1);
if (T[i] == 'L')
w_r = min(W, w_r + 1);
if (T[i] == 'U')
h_d = min(H, h_d + 1);
if (T[i] == 'D')
h_u = max(1, h_u - 1);
}
if (S[i] == 'R')
w_r--;
if (S[i] == 'L')
w_l++;
if (S[i] == 'U')
h_u++;
if (S[i] == 'D')
h_d--;
if (w_r < w_l or h_d < h_u) {
flag = 1;
break;
}
}
if (w_r > sc or sc > w_l or h_u > sr or sr > h_d)
flag = 1;
if (flag)
cout << "NO" << endl;
else
cout << "YES" << endl;
} | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define INF 100000000000
#define MAX 200001
#define MOD 1000000007
int main() {
int H, W, N;
cin >> H >> W >> N;
int sr, sc;
cin >> sr >> sc;
string S, T;
cin >> S >> T;
int w_l = 1;
int w_r = W;
int h_u = 1;
int h_d = H;
int flag = 0;
for (int i = N - 1; i >= 0; i--) {
if (i != N - 1) {
if (T[i] == 'R')
w_l = max(1, w_l - 1);
if (T[i] == 'L')
w_r = min(W, w_r + 1);
if (T[i] == 'U')
h_d = min(H, h_d + 1);
if (T[i] == 'D')
h_u = max(1, h_u - 1);
}
if (S[i] == 'R')
w_r--;
if (S[i] == 'L')
w_l++;
if (S[i] == 'U')
h_u++;
if (S[i] == 'D')
h_d--;
if (w_r < w_l or h_d < h_u) {
flag = 1;
break;
}
}
if (w_r < sc or sc < w_l or h_u > sr or sr > h_d)
flag = 1;
if (flag)
cout << "NO" << endl;
else
cout << "YES" << endl;
} | [
"misc.opposites",
"expression.operator.compare.change",
"assignment.variable.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 869,556 | 869,557 | u266874640 | cpp |
p03054 | #include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) \
for (lint i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
for (lint i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <typename T1, typename T2>
pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) {
return make_pair(l.first + r.first, l.second + r.second);
}
template <typename T1, typename T2>
pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) {
return make_pair(l.first - r.first, l.second - r.second);
}
const lint MOD = 998244353, INF = 1e18;
lint H, W, N, sx, sy;
string s1, s2;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cin >> H >> W >> N;
cin >> sy >> sx;
cin >> s1 >> s2;
map<char, lint> outline;
outline['U'] = 0;
outline['D'] = 0;
outline['L'] = 0;
outline['R'] = 0;
REP(i, N) {
if (s2[i] == 'R')
s2[i] = 'L';
if (s2[i] == 'L')
s2[i] = 'R';
if (s2[i] == 'D')
s2[i] = 'U';
if (s2[i] == 'U')
s2[i] = 'D';
}
IREP(i, N) {
outline[s2[i]] = max(outline[s2[i]] - 1, 0ll);
outline[s1[i]]++;
if (outline['U'] + outline['D'] >= H || outline['R'] + outline['L'] >= W) {
cout << "NO" << endl;
return 0;
}
}
if (sx <= outline['L'] || sy <= outline['U'] || sx >= W - outline['R'] ||
sy >= H - outline['D']) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
}
| #include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) \
for (lint i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
for (lint i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <typename T1, typename T2>
pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) {
return make_pair(l.first + r.first, l.second + r.second);
}
template <typename T1, typename T2>
pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) {
return make_pair(l.first - r.first, l.second - r.second);
}
const lint MOD = 998244353, INF = 1e18;
lint H, W, N, sx, sy;
string s1, s2;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cin >> H >> W >> N;
cin >> sy >> sx;
cin >> s1 >> s2;
map<char, lint> outline;
outline['U'] = 0;
outline['D'] = 0;
outline['L'] = 0;
outline['R'] = 0;
REP(i, N) {
if (s2[i] == 'R')
s2[i] = 'L';
else if (s2[i] == 'L')
s2[i] = 'R';
else if (s2[i] == 'D')
s2[i] = 'U';
else if (s2[i] == 'U')
s2[i] = 'D';
}
IREP(i, N) {
outline[s2[i]] = max(outline[s2[i]] - 1, 0ll);
outline[s1[i]]++;
if (outline['U'] + outline['D'] >= H || outline['R'] + outline['L'] >= W) {
cout << "NO" << endl;
return 0;
}
}
if (sx <= outline['L'] || sy <= outline['U'] || sx > W - outline['R'] ||
sy > H - outline['D']) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
}
| [
"control_flow.branch.else_if.replace.add",
"control_flow.branch.if.replace.remove",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 869,558 | 869,559 | u554988565 | cpp |
p03054 | #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;
typedef long double ld;
typedef vector<ld> vld;
typedef vector<bool> vb;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()
template <class T> void chmin(T &a, T b) { a = min(a, b); }
template <class T> void chmax(T &a, T b) { a = max(a, b); }
constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);
void solve() {
ll h, w, n, r, c;
cin >> h >> w >> n >> r >> c;
string s, t;
cin >> s >> t;
bool ans = true;
ll cur = r;
for (ll i = 0; i < n; i++) {
if (s[i] == 'U')
cur--;
if (cur == 0)
ans = false;
if (t[i] == 'D' && cur < h)
cur++;
}
cur = r;
for (ll i = 0; i < n; i++) {
if (s[i] == 'D')
cur++;
if (cur == h + 1)
ans = false;
if (t[i] == 'U' && cur > 1)
cur--;
}
cur = c;
for (ll i = 0; i < n; i++) {
if (s[i] == 'L')
cur--;
if (cur == 0)
ans = false;
if (t[i] == 'R' && cur < w)
cur++;
}
cur = r;
for (ll i = 0; i < n; i++) {
if (s[i] == 'R')
cur++;
if (cur == w + 1)
ans = false;
if (t[i] == 'L' && cur > 1)
cur--;
}
cout << (ans ? "YES" : "NO") << endl;
return;
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
solve();
} | #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;
typedef long double ld;
typedef vector<ld> vld;
typedef vector<bool> vb;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()
template <class T> void chmin(T &a, T b) { a = min(a, b); }
template <class T> void chmax(T &a, T b) { a = max(a, b); }
constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);
void solve() {
ll h, w, n, r, c;
cin >> h >> w >> n >> r >> c;
string s, t;
cin >> s >> t;
bool ans = true;
ll cur = r;
for (ll i = 0; i < n; i++) {
if (s[i] == 'U')
cur--;
if (cur == 0)
ans = false;
if (t[i] == 'D' && cur < h)
cur++;
}
cur = r;
for (ll i = 0; i < n; i++) {
if (s[i] == 'D')
cur++;
if (cur == h + 1)
ans = false;
if (t[i] == 'U' && cur > 1)
cur--;
}
cur = c;
for (ll i = 0; i < n; i++) {
if (s[i] == 'L')
cur--;
if (cur == 0)
ans = false;
if (t[i] == 'R' && cur < w)
cur++;
}
cur = c;
for (ll i = 0; i < n; i++) {
if (s[i] == 'R')
cur++;
if (cur == w + 1)
ans = false;
if (t[i] == 'L' && cur > 1)
cur--;
}
cout << (ans ? "YES" : "NO") << endl;
return;
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
solve();
} | [
"assignment.value.change",
"identifier.change"
] | 869,562 | 869,563 | u489108157 | cpp |
p03054 | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef long double ld;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define F first
#define S second
const int mx = 100010;
const ll mod = 1e9 + 7;
int main() {
int h, w, n;
cin >> h >> w >> n;
int p, q;
cin >> q >> p;
string s, t;
cin >> s >> t;
int pos = p, cur = p;
rep(i, n) {
if (s[i] == 'R') {
cur++;
pos = max(pos, cur);
}
if (t[i] == 'L' && 1 < cur)
cur--;
}
if (w < pos) {
cout << "NO" << endl;
return 0;
}
pos = p, cur = p;
rep(i, n) {
if (s[i] == 'L') {
cur--;
pos = min(pos, cur);
}
if (t[i] == 'L' && cur < w)
cur++;
}
if (pos <= 0) {
cout << "NO" << endl;
return 0;
}
pos = q, cur = q;
rep(i, n) {
if (s[i] == 'D') {
cur++;
pos = max(pos, cur);
}
if (t[i] == 'U' && 1 < cur)
cur--;
}
if (w < pos) {
cout << "NO" << endl;
return 0;
}
pos = q, cur = q;
rep(i, n) {
if (s[i] == 'U') {
cur--;
pos = min(pos, cur);
}
if (t[i] == 'D' && cur < h)
cur++;
}
if (pos <= 0) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef long double ld;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define F first
#define S second
const int mx = 100010;
const ll mod = 1e9 + 7;
int main() {
int h, w, n;
cin >> h >> w >> n;
int p, q;
cin >> q >> p;
string s, t;
cin >> s >> t;
int pos = p, cur = p;
rep(i, n) {
if (s[i] == 'R') {
cur++;
pos = max(pos, cur);
}
if (t[i] == 'L' && 1 < cur)
cur--;
}
if (w < pos) {
cout << "NO" << endl;
return 0;
}
pos = p, cur = p;
rep(i, n) {
if (s[i] == 'L') {
cur--;
pos = min(pos, cur);
}
if (t[i] == 'R' && cur < w)
cur++;
}
if (pos <= 0) {
cout << "NO" << endl;
return 0;
}
pos = q, cur = q;
rep(i, n) {
if (s[i] == 'D') {
cur++;
pos = max(pos, cur);
}
if (t[i] == 'U' && 1 < cur)
cur--;
}
if (h < pos) {
cout << "NO" << endl;
return 0;
}
pos = q, cur = q;
rep(i, n) {
if (s[i] == 'U') {
cur--;
pos = min(pos, cur);
}
if (t[i] == 'D' && cur < h)
cur++;
}
if (pos <= 0) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
return 0;
} | [
"literal.string.change",
"control_flow.branch.if.condition.change",
"identifier.change"
] | 869,572 | 869,573 | u980909653 | cpp |
p03054 | #include <queue>
#include <stdio.h>
using namespace std;
typedef long long ll;
int main(void) {
ll i, j, k, h, w, n, r, c, now;
scanf("%lld%lld%lld%lld%lld", &h, &w, &n, &r, &c);
char s[n + 10], t[n + 10], d[5] = "RLUD", dr[5] = "LRDU";
ll f[4] = {w + 1 - c, c, h + 1 - r, r}, fr[4] = {c, w + 1 - c, r, h + 1 - r};
bool flg[n];
for (i = 0; i < n; ++i)
flg[i] = false;
scanf("%s%s", s, t);
for (i = 0; i < 4; ++i) {
priority_queue<ll> q;
now = f[i];
for (j = 0; j < n; ++j) {
if (s[j] == d[i])
now--;
if (!now) {
if (q.empty()) {
printf("NO");
return 0;
}
flg[q.top()] = true;
q.pop();
now++;
}
if (t[j] == dr[i])
q.push(j);
}
now = fr[i];
for (j = 0; j < n; ++j) {
if (s[j] == d[i])
now++;
if (t[j] == dr[i] && flg[j])
now--;
if (!now) {
printf("NO");
return 0;
}
}
}
printf("YES");
return 0;
} | #include <queue>
#include <stdio.h>
using namespace std;
typedef long long ll;
int main(void) {
ll i, j, k, h, w, n, r, c, now;
scanf("%lld%lld%lld%lld%lld", &h, &w, &n, &r, &c);
char s[n + 10], t[n + 10], d[5] = "RLDU", dr[5] = "LRUD";
ll f[4] = {w + 1 - c, c, h + 1 - r, r}, fr[4] = {c, w + 1 - c, r, h + 1 - r};
bool flg[n];
for (i = 0; i < n; ++i)
flg[i] = false;
scanf("%s%s", s, t);
for (i = 0; i < 4; ++i) {
priority_queue<ll> q;
now = f[i];
for (j = 0; j < n; ++j) {
if (s[j] == d[i])
now--;
if (!now) {
if (q.empty()) {
printf("NO");
return 0;
}
flg[q.top()] = true;
q.pop();
now++;
}
if (t[j] == dr[i])
q.push(j);
}
now = fr[i];
for (j = 0; j < n; ++j) {
if (s[j] == d[i])
now++;
if (t[j] == dr[i] && flg[j])
now--;
if (!now) {
printf("NO");
return 0;
}
}
}
printf("YES");
return 0;
} | [
"literal.string.change",
"variable_declaration.value.change"
] | 869,585 | 869,586 | u440920318 | cpp |
p03054 | #include <bits/stdc++.h>
using namespace std;
int main() {
int H, W, N;
cin >> H >> W >> N;
int r, c;
cin >> r >> c;
string s, t;
cin >> s >> t;
bool x = true;
int a = r;
for (int i = 0; i < N; i++) {
if (s.at(i) == 'U')
a--;
if (a <= 0)
x = false;
if (t.at(i) == 'D') {
if (a < H)
a++;
}
}
int a1 = r;
for (int i = 0; i < N; i++) {
if (s.at(i) == 'D')
a1++;
if (H < a1)
x = false;
if (t.at(i) == 'U') {
if (0 < a1)
a1--;
}
}
int a2 = c;
for (int i = 0; i < N; i++) {
if (s.at(i) == 'R')
a2++;
if (W < a2)
x = false;
if (t.at(i) == 'L') {
if (0 < a2)
a2--;
}
}
int a3 = c;
for (int i = 0; i < N; i++) {
if (s.at(i) == 'L')
a3--;
if (a3 <= 0)
x = false;
if (t.at(i) == 'R') {
if (a3 < W)
a3++;
}
}
if (x)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int H, W, N;
cin >> H >> W >> N;
int r, c;
cin >> r >> c;
string s, t;
cin >> s >> t;
bool x = true;
int a = r;
for (int i = 0; i < N; i++) {
if (s.at(i) == 'U')
a--;
if (a <= 0)
x = false;
if (t.at(i) == 'D') {
if (a < H)
a++;
}
}
int a1 = r;
for (int i = 0; i < N; i++) {
if (s.at(i) == 'D')
a1++;
if (H < a1)
x = false;
if (t.at(i) == 'U') {
if (1 < a1)
a1--;
}
}
int a2 = c;
for (int i = 0; i < N; i++) {
if (s.at(i) == 'R')
a2++;
if (W < a2)
x = false;
if (t.at(i) == 'L') {
if (1 < a2)
a2--;
}
}
int a3 = c;
for (int i = 0; i < N; i++) {
if (s.at(i) == 'L')
a3--;
if (a3 <= 0)
x = false;
if (t.at(i) == 'R') {
if (a3 < W)
a3++;
}
}
if (x)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
} | [
"literal.number.change",
"control_flow.branch.if.condition.change"
] | 869,607 | 869,608 | u101018317 | cpp |
p03054 | #include <algorithm>
#include <iostream>
#include <string>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1e9 + 7, INF = 1e9;
int main(void) {
int h, w, n, si, sj, i, pi1, pi2, pj1, pj2;
string s, t;
scanf("%d%d%d%d%d", &h, &w, &n, &si, &sj);
cin >> s >> t;
pi1 = 1;
pi2 = h + 1;
pj1 = 1;
pj2 = w + 1;
for (i = n - 1; i >= 0; i--) {
if (t[i] == 'L')
pj2 = min(w + 1, pj2 + 1);
if (t[i] == 'R')
pj1 = max(1, pj1 - 1);
if (t[i] == 'U')
pi2 = min(h + 1, pi2 + 1);
if (t[i] == 'D')
pi1 = max(1, pi1 - 1);
if (s[i] == 'L')
pj1 = min(w, pj1 + 1);
if (s[i] == 'R')
pj2 = max(2, pj2 - 1);
if (s[i] == 'U')
pi1 = min(h, pi1 + 1);
if (s[i] == 'D')
pi2 = max(2, pi2 - 1);
if (pi1 >= pi2 || pj1 >= pj2) {
printf("NO\n");
return 0;
}
}
if (pi1 <= si && si < pi2 && pj1 <= sj && sj < pj2) {
printf("YES\n");
} else {
printf("NO\n");
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <string>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1e9 + 7, INF = 1e9;
int main(void) {
int h, w, n, si, sj, i, pi1, pi2, pj1, pj2;
string s, t;
scanf("%d%d%d%d%d", &h, &w, &n, &si, &sj);
cin >> s >> t;
pi1 = 1;
pi2 = h + 1;
pj1 = 1;
pj2 = w + 1;
for (i = n - 1; i >= 0; i--) {
if (t[i] == 'L')
pj2 = min(w + 1, pj2 + 1);
if (t[i] == 'R')
pj1 = max(1, pj1 - 1);
if (t[i] == 'U')
pi2 = min(h + 1, pi2 + 1);
if (t[i] == 'D')
pi1 = max(1, pi1 - 1);
if (s[i] == 'L')
pj1 = min(w + 1, pj1 + 1);
if (s[i] == 'R')
pj2 = max(1, pj2 - 1);
if (s[i] == 'U')
pi1 = min(h + 1, pi1 + 1);
if (s[i] == 'D')
pi2 = max(1, pi2 - 1);
if (pi1 >= pi2 || pj1 >= pj2) {
printf("NO\n");
return 0;
}
}
if (pi1 <= si && si < pi2 && pj1 <= sj && sj < pj2) {
printf("YES\n");
} else {
printf("NO\n");
}
return 0;
} | [
"assignment.change",
"literal.number.change",
"assignment.value.change",
"call.arguments.change"
] | 869,623 | 869,622 | u088895504 | cpp |
p03054 | #include <bits/stdc++.h>
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const array<pair<int, int>, 4> fd{make_pair(1, 0), make_pair(-1, 0),
make_pair(0, 1), make_pair(0, -1)};
signed main() {
int h, w, n, sr, sc;
string s, t;
cin >> h >> w >> n >> sr >> sc >> s >> t;
int rest = sr;
rep(i, n) {
if (s[i] == 'U')
rest--;
if (!rest) {
cout << "No" << endl;
return 0;
}
if (t[i] == 'D' && rest < h)
rest++;
}
rest = sc;
rep(i, n) {
if (s[i] == 'L')
rest--;
if (!rest) {
cout << "No" << endl;
return 0;
}
if (t[i] == 'R' && rest < w)
rest++;
}
rest = h - sr + 1;
rep(i, n) {
if (s[i] == 'D')
rest--;
if (!rest) {
cout << "No" << endl;
return 0;
}
if (t[i] == 'U' && rest < h)
rest++;
}
rest = w - sc + 1;
rep(i, n) {
if (s[i] == 'R')
rest--;
if (!rest) {
cout << "No" << endl;
return 0;
}
if (t[i] == 'L' && rest < w)
rest++;
}
cout << "Yes" << endl;
}
| #include <bits/stdc++.h>
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const array<pair<int, int>, 4> fd{make_pair(1, 0), make_pair(-1, 0),
make_pair(0, 1), make_pair(0, -1)};
signed main() {
int h, w, n, sr, sc;
string s, t;
cin >> h >> w >> n >> sr >> sc >> s >> t;
int rest = sr;
rep(i, n) {
if (s[i] == 'U')
rest--;
if (!rest) {
cout << "NO" << endl;
return 0;
}
if (t[i] == 'D' && rest < h)
rest++;
}
rest = sc;
rep(i, n) {
if (s[i] == 'L')
rest--;
if (!rest) {
cout << "NO" << endl;
return 0;
}
if (t[i] == 'R' && rest < w)
rest++;
}
rest = h - sr + 1;
rep(i, n) {
if (s[i] == 'D')
rest--;
if (!rest) {
cout << "NO" << endl;
return 0;
}
if (t[i] == 'U' && rest < h)
rest++;
}
rest = w - sc + 1;
rep(i, n) {
if (s[i] == 'R')
rest--;
if (!rest) {
cout << "NO" << endl;
return 0;
}
if (t[i] == 'L' && rest < w)
rest++;
}
cout << "YES" << endl;
}
| [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 869,630 | 869,631 | u317754719 | cpp |
p03054 | #include <bits/stdc++.h>
using namespace std;
// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout << d << endl;
#define coutd(d) cout << std::setprecision(10) << d << endl;
#define cinline(n) getline(cin, n);
#define replace_all(s, b, a) replace(s.begin(), s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll, ll, ll>>;
using vb = vector<bool>;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const ll INF = 1e15;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll h, w, n;
cin >> h >> w >> n;
ll sy, sx;
cin >> sy >> sx;
sy--, sx--;
string s, t;
cin >> s >> t;
ll l = 0, r = w;
if (s[n - 1] == 'L')
l++;
if (s[n - 1] == 'R')
r--;
for (ll i = n - 2; i >= 0; i--) {
if (t[i] == 'L')
r = min(r + 1, w);
else if (t[i] == 'R')
l = min(l - 1, 0LL);
if (s[i] == 'L')
l++;
else if (s[i] == 'R')
r--;
if (l >= r) {
cout << "NO" << endl;
return 0;
}
}
if (sx < l || r <= sx) {
cout << "NO" << endl;
return 0;
}
l = 0, r = h;
if (s[n - 1] == 'U')
l++;
if (s[n - 1] == 'D')
r--;
for (ll i = n - 2; i >= 0; i--) {
if (t[i] == 'U')
r = min(r + 1, h);
else if (t[i] == 'D')
l = min(l - 1, 0LL);
if (s[i] == 'U')
l++;
else if (s[i] == 'D')
r--;
if (l >= r) {
cout << "NO" << endl;
return 0;
}
}
if (sy < l || r <= sy) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout << d << endl;
#define coutd(d) cout << std::setprecision(10) << d << endl;
#define cinline(n) getline(cin, n);
#define replace_all(s, b, a) replace(s.begin(), s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll, ll, ll>>;
using vb = vector<bool>;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const ll INF = 1e15;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll h, w, n;
cin >> h >> w >> n;
ll sy, sx;
cin >> sy >> sx;
sy--, sx--;
string s, t;
cin >> s >> t;
ll l = 0, r = w;
if (s[n - 1] == 'L')
l++;
if (s[n - 1] == 'R')
r--;
for (ll i = n - 2; i >= 0; i--) {
if (t[i] == 'L')
r = min(r + 1, w);
else if (t[i] == 'R')
l = max(l - 1, 0LL);
if (s[i] == 'L')
l++;
else if (s[i] == 'R')
r--;
if (l >= r) {
cout << "NO" << endl;
return 0;
}
}
if (sx < l || r <= sx) {
cout << "NO" << endl;
return 0;
}
l = 0, r = h;
if (s[n - 1] == 'U')
l++;
if (s[n - 1] == 'D')
r--;
for (ll i = n - 2; i >= 0; i--) {
if (t[i] == 'U')
r = min(r + 1, h);
else if (t[i] == 'D')
l = max(l - 1, 0LL);
if (s[i] == 'U')
l++;
else if (s[i] == 'D')
r--;
if (l >= r) {
cout << "NO" << endl;
return 0;
}
}
if (sy < l || r <= sy) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
}
| [
"misc.opposites",
"assignment.value.change",
"identifier.change",
"call.function.change"
] | 869,634 | 869,635 | u530107518 | cpp |
p03054 | #include <bits/stdc++.h>
using namespace std;
// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout << d << endl;
#define coutd(d) cout << std::setprecision(10) << d << endl;
#define cinline(n) getline(cin, n);
#define replace_all(s, b, a) replace(s.begin(), s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll, ll, ll>>;
using vb = vector<bool>;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const ll INF = 1e15;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll h, w, n;
cin >> h >> w >> n;
ll sy, sx;
cin >> sy >> sx;
sy--, sx--;
string s, t;
cin >> s >> t;
ll l = 0, r = w;
if (s[n - 1] == 'L')
l++;
if (s[n - 1] == 'R')
r--;
for (ll i = n - 2; i >= 0; i--) {
if (t[i] == 'L')
r = min(r + 1, w);
else if (t[i] == 'R')
l = min(l - 1, 0LL);
if (s[i] == 'L')
l++;
else if (s[i] == 'R')
r--;
if (l >= r) {
cout << "NO" << endl;
return 0;
}
}
if (sx < l || r <= sx) {
cout << "NO" << endl;
return 0;
}
l = 0, r = h;
if (s[n - 1] == 'U')
l++;
if (s[n - 1] == 'D')
r--;
for (ll i = n - 2; i >= 0; i--) {
if (t[i] == 'U')
r = min(r + 1, h);
else if (t[i] == 'D')
l = min(l - 1, 0LL);
if (s[i] == 'U')
l++;
else if (s[i] == 'D')
r++;
if (l >= r) {
cout << "NO" << endl;
return 0;
}
}
if (sy < l || r <= sy) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout << d << endl;
#define coutd(d) cout << std::setprecision(10) << d << endl;
#define cinline(n) getline(cin, n);
#define replace_all(s, b, a) replace(s.begin(), s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll, ll, ll>>;
using vb = vector<bool>;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const ll INF = 1e15;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll h, w, n;
cin >> h >> w >> n;
ll sy, sx;
cin >> sy >> sx;
sy--, sx--;
string s, t;
cin >> s >> t;
ll l = 0, r = w;
if (s[n - 1] == 'L')
l++;
if (s[n - 1] == 'R')
r--;
for (ll i = n - 2; i >= 0; i--) {
if (t[i] == 'L')
r = min(r + 1, w);
else if (t[i] == 'R')
l = max(l - 1, 0LL);
if (s[i] == 'L')
l++;
else if (s[i] == 'R')
r--;
if (l >= r) {
cout << "NO" << endl;
return 0;
}
}
if (sx < l || r <= sx) {
cout << "NO" << endl;
return 0;
}
l = 0, r = h;
if (s[n - 1] == 'U')
l++;
if (s[n - 1] == 'D')
r--;
for (ll i = n - 2; i >= 0; i--) {
if (t[i] == 'U')
r = min(r + 1, h);
else if (t[i] == 'D')
l = max(l - 1, 0LL);
if (s[i] == 'U')
l++;
else if (s[i] == 'D')
r--;
if (l >= r) {
cout << "NO" << endl;
return 0;
}
}
if (sy < l || r <= sy) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
}
| [
"misc.opposites",
"assignment.value.change",
"identifier.change",
"call.function.change"
] | 869,636 | 869,635 | u530107518 | cpp |
p03054 | #include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define REP(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define REPS(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define RREP(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define RREPS(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define BIT(n) ((int)(1) << (n))
#define ALL(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> pii;
typedef pair<double, double> dop;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
aaa() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
};
} aaaaaaa;
signed main() {
int h, w, n;
cin >> h >> w >> n;
int stx, sty;
cin >> stx >> sty;
stx--;
sty--;
std::string s, t;
cin >> s >> t;
int llim, rlim, ulim, dlim;
ulim = 0;
llim = 0;
dlim = h - 1;
rlim = w - 1;
for (int i = n - 1; i >= 0; i--) {
if (i < n - 1) {
if (t[i] == 'U') {
dlim = min(h - 1, rlim + 1);
} else if (t[i] == 'D') {
ulim = max((int)0, llim - 1);
} else if (t[i] == 'L') {
rlim = min(w - 1, dlim + 1);
} else if (t[i] == 'R') {
llim = max((int)0, ulim - 1);
}
}
if (s[i] == 'U') {
ulim++;
} else if (s[i] == 'D') {
dlim--;
} else if (s[i] == 'L') {
llim++;
} else if (s[i] == 'R') {
rlim--;
}
if (llim > rlim || ulim > dlim) {
rlim = -1;
break;
}
}
if (sty >= llim && sty <= rlim && stx >= ulim && stx <= dlim) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
} | #include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define REP(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define REPS(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define RREP(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define RREPS(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define BIT(n) ((int)(1) << (n))
#define ALL(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> pii;
typedef pair<double, double> dop;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
aaa() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
};
} aaaaaaa;
signed main() {
int h, w, n;
cin >> h >> w >> n;
int stx, sty;
cin >> stx >> sty;
stx--;
sty--;
std::string s, t;
cin >> s >> t;
int llim, rlim, ulim, dlim;
ulim = 0;
llim = 0;
dlim = h - 1;
rlim = w - 1;
for (int i = n - 1; i >= 0; i--) {
if (i < n - 1) {
if (t[i] == 'U') {
dlim = min(h - 1, dlim + 1);
} else if (t[i] == 'D') {
ulim = max((int)0, ulim - 1);
} else if (t[i] == 'L') {
rlim = min(w - 1, rlim + 1);
} else if (t[i] == 'R') {
llim = max((int)0, llim - 1);
}
}
if (s[i] == 'U') {
ulim++;
} else if (s[i] == 'D') {
dlim--;
} else if (s[i] == 'L') {
llim++;
} else if (s[i] == 'R') {
rlim--;
}
if (llim > rlim || ulim > dlim) {
rlim = -1;
break;
}
}
if (sty >= llim && sty <= rlim && stx >= ulim && stx <= dlim) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
} | [
"assignment.value.change",
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 869,658 | 869,659 | u068654145 | cpp |
p03054 | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#define _USE_MATH_DEFINES
#include <functional>
#include <math.h>
using namespace std;
#define rep(i, x) for (ll i = 0; i < x; i++)
#define repn(i, x) for (ll i = 1; i <= x; i++)
typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000001;
ll max(ll a, ll b) {
if (a > b) {
return a;
}
return b;
}
ll min(ll a, ll b) {
if (a > b) {
return b;
}
return a;
}
ll gcd(ll a, ll b) {
if (b == 0) {
return a;
}
if (a < b) {
return gcd(b, a);
}
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
struct edge {
ll ind;
ll fr;
ll to;
ll d;
};
///////////////////////////
ll H, W, N, sr, sc;
bool ch(vector<ll> a, vector<ll> b, ll L, ll s) {
vector<ll> c(2 * N + 1);
repn(i, N) {
c[2 * i - 1] = b[N + 1 - i];
c[2 * i] = a[N + 1 - i];
}
ll le = 1;
ll ri = L;
for (ll i = 2; i <= 2 * N; i++) {
if (i % 2 == 0) {
if (c[i] == 1) {
ri--;
}
if (c[i] == -1) {
le++;
}
}
if (i % 2 == 1) {
if (c[i] == 1) {
le = max(le - 1, 1);
}
if (c[i] == -1) {
ri = max(ri + 1, L);
}
}
if (le > ri) {
return false;
}
}
if (s < le || s > ri) {
return false;
}
return true;
}
int main() {
cin >> H >> W >> N >> sr >> sc;
string S, T;
cin >> S >> T;
vector<ll> a(N + 1, 0), b(N + 1, 0), c(N + 1, 0), d(N + 1, 0);
repn(i, N) {
if (S[i - 1] == 'D') {
a[i] = 1;
}
if (S[i - 1] == 'U') {
a[i] = -1;
}
if (S[i - 1] == 'R') {
c[i] = 1;
}
if (S[i - 1] == 'L') {
c[i] = -1;
}
if (T[i - 1] == 'D') {
b[i] = 1;
}
if (T[i - 1] == 'U') {
b[i] = -1;
}
if (T[i - 1] == 'R') {
d[i] = 1;
}
if (T[i - 1] == 'L') {
d[i] = -1;
}
}
if (ch(a, b, H, sr) && ch(c, d, W, sc)) {
cout << "YES";
} else {
cout << "NO";
}
system("PAUSE");
}
| #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#define _USE_MATH_DEFINES
#include <functional>
#include <math.h>
using namespace std;
#define rep(i, x) for (ll i = 0; i < x; i++)
#define repn(i, x) for (ll i = 1; i <= x; i++)
typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000001;
ll max(ll a, ll b) {
if (a > b) {
return a;
}
return b;
}
ll min(ll a, ll b) {
if (a > b) {
return b;
}
return a;
}
ll gcd(ll a, ll b) {
if (b == 0) {
return a;
}
if (a < b) {
return gcd(b, a);
}
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
struct edge {
ll ind;
ll fr;
ll to;
ll d;
};
///////////////////////////
ll H, W, N, sr, sc;
bool ch(vector<ll> a, vector<ll> b, ll L, ll s) {
vector<ll> c(2 * N + 1);
repn(i, N) {
c[2 * i - 1] = b[N + 1 - i];
c[2 * i] = a[N + 1 - i];
}
ll le = 1;
ll ri = L;
for (ll i = 2; i <= 2 * N; i++) {
if (i % 2 == 0) {
if (c[i] == 1) {
ri--;
}
if (c[i] == -1) {
le++;
}
}
if (i % 2 == 1) {
if (c[i] == 1) {
le = max(le - 1, 1);
}
if (c[i] == -1) {
ri = min(ri + 1, L);
}
}
if (le > ri) {
return false;
}
}
if (s < le || s > ri) {
return false;
}
return true;
}
int main() {
cin >> H >> W >> N >> sr >> sc;
string S, T;
cin >> S >> T;
vector<ll> a(N + 1, 0), b(N + 1, 0), c(N + 1, 0), d(N + 1, 0);
repn(i, N) {
if (S[i - 1] == 'D') {
a[i] = 1;
}
if (S[i - 1] == 'U') {
a[i] = -1;
}
if (S[i - 1] == 'R') {
c[i] = 1;
}
if (S[i - 1] == 'L') {
c[i] = -1;
}
if (T[i - 1] == 'D') {
b[i] = 1;
}
if (T[i - 1] == 'U') {
b[i] = -1;
}
if (T[i - 1] == 'R') {
d[i] = 1;
}
if (T[i - 1] == 'L') {
d[i] = -1;
}
}
if (ch(a, b, H, sr) && ch(c, d, W, sc)) {
cout << "YES";
} else {
cout << "NO";
}
system("PAUSE");
}
| [
"misc.opposites",
"assignment.value.change",
"identifier.change",
"call.function.change"
] | 869,660 | 869,661 | u004411048 | cpp |
p03054 | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#define _USE_MATH_DEFINES
#include <functional>
#include <math.h>
using namespace std;
#define rep(i, x) for (ll i = 0; i < x; i++)
#define repn(i, x) for (ll i = 1; i <= x; i++)
typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000001;
ll max(ll a, ll b) {
if (a > b) {
return a;
}
return b;
}
ll min(ll a, ll b) {
if (a > b) {
return b;
}
return a;
}
ll gcd(ll a, ll b) {
if (b == 0) {
return a;
}
if (a < b) {
return gcd(b, a);
}
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
struct edge {
ll ind;
ll fr;
ll to;
ll d;
};
///////////////////////////
ll H, W, N, sr, sc;
bool ch(vector<ll> a, vector<ll> b, ll L, ll s) {
vector<ll> c(2 * N + 1);
repn(i, N) {
c[2 * i - 1] = b[N + 1 - i];
c[2 * i] = a[N + 1 - i];
}
ll le = 1;
ll ri = L;
for (ll i = 2; i <= 2 * N; i++) {
if (i % 2 == 0) {
if (c[i] == 1) {
ri--;
}
if (c[i] == -1) {
le++;
}
}
if (i % 2 == 1) {
if (c[i] == 1) {
le = max(le - 1, 1);
}
if (c[i] == -1) {
ri = max(ri + 1, L);
}
}
if (le > ri) {
return false;
}
}
if (s < le || s > ri) {
return false;
}
return true;
}
int main() {
cin >> H >> W >> N >> sr >> sc;
string S, T;
cin >> S >> T;
vector<ll> a(N + 1, 0), b(N + 1, 0), c(N + 1, 0), d(N + 1, 0);
repn(i, N) {
if (S[i - 1] == 'U') {
a[i] = 1;
}
if (S[i - 1] == 'D') {
a[i] = -1;
}
if (S[i - 1] == 'R') {
c[i] = 1;
}
if (S[i - 1] == 'L') {
c[i] = -1;
}
if (T[i - 1] == 'U') {
b[i] = 1;
}
if (T[i - 1] == 'D') {
b[i] = -1;
}
if (T[i - 1] == 'R') {
d[i] = 1;
}
if (T[i - 1] == 'L') {
d[i] = -1;
}
}
if (ch(a, b, H, sr) && ch(c, d, W, sc)) {
cout << "YES";
} else {
cout << "NO";
}
system("PAUSE");
}
| #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#define _USE_MATH_DEFINES
#include <functional>
#include <math.h>
using namespace std;
#define rep(i, x) for (ll i = 0; i < x; i++)
#define repn(i, x) for (ll i = 1; i <= x; i++)
typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000001;
ll max(ll a, ll b) {
if (a > b) {
return a;
}
return b;
}
ll min(ll a, ll b) {
if (a > b) {
return b;
}
return a;
}
ll gcd(ll a, ll b) {
if (b == 0) {
return a;
}
if (a < b) {
return gcd(b, a);
}
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
struct edge {
ll ind;
ll fr;
ll to;
ll d;
};
///////////////////////////
ll H, W, N, sr, sc;
bool ch(vector<ll> a, vector<ll> b, ll L, ll s) {
vector<ll> c(2 * N + 1);
repn(i, N) {
c[2 * i - 1] = b[N + 1 - i];
c[2 * i] = a[N + 1 - i];
}
ll le = 1;
ll ri = L;
for (ll i = 2; i <= 2 * N; i++) {
if (i % 2 == 0) {
if (c[i] == 1) {
ri--;
}
if (c[i] == -1) {
le++;
}
}
if (i % 2 == 1) {
if (c[i] == 1) {
le = max(le - 1, 1);
}
if (c[i] == -1) {
ri = min(ri + 1, L);
}
}
if (le > ri) {
return false;
}
}
if (s < le || s > ri) {
return false;
}
return true;
}
int main() {
cin >> H >> W >> N >> sr >> sc;
string S, T;
cin >> S >> T;
vector<ll> a(N + 1, 0), b(N + 1, 0), c(N + 1, 0), d(N + 1, 0);
repn(i, N) {
if (S[i - 1] == 'D') {
a[i] = 1;
}
if (S[i - 1] == 'U') {
a[i] = -1;
}
if (S[i - 1] == 'R') {
c[i] = 1;
}
if (S[i - 1] == 'L') {
c[i] = -1;
}
if (T[i - 1] == 'D') {
b[i] = 1;
}
if (T[i - 1] == 'U') {
b[i] = -1;
}
if (T[i - 1] == 'R') {
d[i] = 1;
}
if (T[i - 1] == 'L') {
d[i] = -1;
}
}
if (ch(a, b, H, sr) && ch(c, d, W, sc)) {
cout << "YES";
} else {
cout << "NO";
}
system("PAUSE");
}
| [
"misc.opposites",
"assignment.value.change",
"identifier.change",
"call.function.change",
"literal.string.change",
"control_flow.branch.if.condition.change"
] | 869,662 | 869,661 | u004411048 | cpp |
p03054 | #include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, x) for (ll i = 0; i < (int)(x); i++)
#define reps(i, x) for (ll i = 1; i <= (int)(x); i++)
#define rrep(i, x) for (ll i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (ll i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
typedef long long ll;
typedef std::pair<ll, ll> P;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
using namespace std;
int main() {
ll h, w, n;
cin >> h >> w >> n;
ll sr, sc;
cin >> sr >> sc;
string s, t;
cin >> s >> t;
ll up = 0;
ll dp = 0;
ll rp = 0;
ll lp = 0;
ll us = sr - 1;
ll ds = h - sr;
ll rs = w - sc;
ll ls = sc - 1;
rep(i, n) {
if (s[i] == 'U') {
up++;
ds++;
}
if (s[i] == 'D') {
dp++;
us++;
}
if (s[i] == 'R') {
rp++;
ls++;
}
if (s[i] == 'L') {
lp++;
rs++;
}
if (up >= sr || lp >= sc || dp >= h - sr + 1 || rp >= w - sc + 1) {
cout << "NO";
return 0;
}
if (t[i] == 'U' && us > 0) {
dp--;
us--;
ds++;
}
if (t[i] == 'D' && ds > 0) {
up--;
ds--;
us++;
}
if (t[i] == 'R' && rs > 0) {
lp--;
rs--;
ls++;
}
if (t[i] == 'L' && ls > 0) {
rp--;
ls--;
rs++;
}
}
cout << "Yes";
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, x) for (ll i = 0; i < (int)(x); i++)
#define reps(i, x) for (ll i = 1; i <= (int)(x); i++)
#define rrep(i, x) for (ll i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (ll i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
typedef long long ll;
typedef std::pair<ll, ll> P;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
using namespace std;
int main() {
ll h, w, n;
cin >> h >> w >> n;
ll sr, sc;
cin >> sr >> sc;
string s, t;
cin >> s >> t;
ll up = 0;
ll dp = 0;
ll rp = 0;
ll lp = 0;
ll us = sr - 1;
ll ds = h - sr;
ll rs = w - sc;
ll ls = sc - 1;
rep(i, n) {
if (s[i] == 'U') {
up++;
ds++;
}
if (s[i] == 'D') {
dp++;
us++;
}
if (s[i] == 'R') {
rp++;
ls++;
}
if (s[i] == 'L') {
lp++;
rs++;
}
if (up >= sr || lp >= sc || dp >= h - sr + 1 || rp >= w - sc + 1) {
cout << "NO";
return 0;
}
if (t[i] == 'U' && us > 0) {
dp--;
us--;
ds++;
}
if (t[i] == 'D' && ds > 0) {
up--;
ds--;
us++;
}
if (t[i] == 'R' && rs > 0) {
lp--;
rs--;
ls++;
}
if (t[i] == 'L' && ls > 0) {
rp--;
ls--;
rs++;
}
}
cout << "YES";
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 869,378 | 869,379 | u150255544 | cpp |
p03054 | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int inf = 1LL << 60;
const int mod = 1e9 + 7;
const double eps = 1e-9;
/*{
}*/
int h, w, n;
bool check(int x, int y) { return 1 <= x and x <= w and 1 <= y and y <= h; }
signed main() {
cin >> h >> w >> n;
int sx, sy;
cin >> sy >> sx;
string s, t;
cin >> s >> t;
int x1 = sx, y1 = sy;
int x2 = sx, y2 = sy;
rep(i, 0, n) {
x1 += s[i] == 'R';
if (!check(x1, sy)) {
cout << "NO" << endl;
return 0;
}
x1 = max(1LL, x1 - (t[i] == 'L'));
x2 -= s[i] == 'L';
if (!check(x2, sy)) {
cout << "NO" << endl;
return 0;
}
x2 = min(w, x2 + (t[i] == 'R'));
y1 += s[i] == 'D';
if (!check(sx, y1)) {
cout << "NO" << endl;
return 0;
}
y1 = max(1LL, y1 - (t[i] == 'U'));
y2 -= s[i] == 'U';
if (!check(sx, y2)) {
cout << "NO" << endl;
return 0;
}
x2 = min(h, y2 + (t[i] == 'D'));
}
cout << "YES" << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int inf = 1LL << 60;
const int mod = 1e9 + 7;
const double eps = 1e-9;
/*{
}*/
int h, w, n;
bool check(int x, int y) { return 1 <= x and x <= w and 1 <= y and y <= h; }
signed main() {
cin >> h >> w >> n;
int sx, sy;
cin >> sy >> sx;
string s, t;
cin >> s >> t;
int x1 = sx, y1 = sy;
int x2 = sx, y2 = sy;
rep(i, 0, n) {
x1 += s[i] == 'R';
if (!check(x1, sy)) {
cout << "NO" << endl;
return 0;
}
x1 = max(1LL, x1 - (t[i] == 'L'));
x2 -= s[i] == 'L';
if (!check(x2, sy)) {
cout << "NO" << endl;
return 0;
}
x2 = min(w, x2 + (t[i] == 'R'));
y1 += s[i] == 'D';
if (!check(sx, y1)) {
cout << "NO" << endl;
return 0;
}
y1 = max(1LL, y1 - (t[i] == 'U'));
y2 -= s[i] == 'U';
if (!check(sx, y2)) {
cout << "NO" << endl;
return 0;
}
y2 = min(h, y2 + (t[i] == 'D'));
}
cout << "YES" << endl;
return 0;
}
| [
"assignment.variable.change",
"identifier.change"
] | 869,388 | 869,389 | u057866967 | cpp |
p03054 | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
int main() {
bool ans = true;
ll h, w, n, komx, komy;
string tak, ao;
cin >> h >> w >> n >> komy >> komx >> tak >> ao;
komx--;
komy--;
ll oku = 0, okd = h - 1, okl = 0, okr = w - 1;
for (int i = n - 1; i >= 0; i--) {
if (oku != 0 && ao[i] == 'D')
oku--;
if (okd != h - 1 && ao[i] == 'U')
okd++;
if (okl != 0 && ao[i] == 'R')
okl--;
if (okr != w - 1 && ao[i] == 'L')
okr++;
if (tak[i] == 'D')
okd--;
if (tak[i] == 'U')
oku++;
if (tak[i] == 'L')
okl++;
if (tak[i] == 'R')
okr--;
if (okd < oku || okr < okl) {
ans = false;
break;
}
}
if (okd < oku || okl < okr)
ans = false;
if (ans && (oku <= komy) && (komy <= okd) && (okl <= komx) && (komx <= okr))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
| #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
int main() {
bool ans = true;
ll h, w, n, komx, komy;
string tak, ao;
cin >> h >> w >> n >> komy >> komx >> tak >> ao;
komx--;
komy--;
ll oku = 0, okd = h - 1, okl = 0, okr = w - 1;
for (int i = n - 1; i >= 0; i--) {
if (oku != 0 && ao[i] == 'D')
oku--;
if (okd != h - 1 && ao[i] == 'U')
okd++;
if (okl != 0 && ao[i] == 'R')
okl--;
if (okr != w - 1 && ao[i] == 'L')
okr++;
if (tak[i] == 'D')
okd--;
if (tak[i] == 'U')
oku++;
if (tak[i] == 'L')
okl++;
if (tak[i] == 'R')
okr--;
if (okd < oku || okr < okl) {
ans = false;
break;
}
}
if (okd < oku || okr < okl)
ans = false;
if (ans && (oku <= komy) && (komy <= okd) && (okl <= komx) && (komx <= okr))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
| [
"expression.operation.binary.remove",
"control_flow.branch.if.condition.change"
] | 869,398 | 869,399 | u938945369 | cpp |
p03054 | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
#define x first
#define y second
ii con(char a) {
if (a == 'D')
return {1, 0};
if (a == 'U')
return {-1, 0};
if (a == 'R')
return {0, 1};
if (a == 'L')
return {0, -1};
}
int h, w, n;
ii sp;
string s, t;
void sub(int &a) {
a--;
if (a < 0)
a = 0;
}
int main() {
cin >> h >> w >> n;
cin >> sp.x >> sp.y;
cin >> s >> t;
bool won = false;
// possible to reach top
int vu = 0, vd = 0, hl = 0, hr = 0;
for (int i = n - 1; i >= 0; i--) {
// start with t[i]
if (t[i] == 'L') {
sub(hr);
} else if (t[i] == 'R') {
sub(hl);
} else if (t[i] == 'U') {
// down
sub(vd);
} else if (t[i] == 'D') {
sub(vu);
}
if (s[i] == 'L') {
hl++;
} else if (s[i] == 'R') {
hr++;
} else if (s[i] == 'U') {
vu++;
} else {
vd++;
}
if (hl + hr == w) {
won = true;
break;
}
if (vu + vd == h) {
won = true;
break;
}
}
if (won) {
cout << "NO" << endl;
} else {
if ((sp.x <= vd || (h - sp.x + 1) <= vu) &&
(sp.y <= hl || (w - sp.y + 1) <= hr)) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
} | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
#define x first
#define y second
ii con(char a) {
if (a == 'D')
return {1, 0};
if (a == 'U')
return {-1, 0};
if (a == 'R')
return {0, 1};
if (a == 'L')
return {0, -1};
}
int h, w, n;
ii sp;
string s, t;
void sub(int &a) {
a--;
if (a < 0)
a = 0;
}
int main() {
cin >> h >> w >> n;
cin >> sp.x >> sp.y;
cin >> s >> t;
bool won = false;
// possible to reach top
int vu = 0, vd = 0, hl = 0, hr = 0;
for (int i = n - 1; i >= 0; i--) {
// start with t[i]
if (t[i] == 'L') {
sub(hr);
} else if (t[i] == 'R') {
sub(hl);
} else if (t[i] == 'U') {
// down
sub(vd);
} else if (t[i] == 'D') {
sub(vu);
}
if (s[i] == 'L') {
hl++;
} else if (s[i] == 'R') {
hr++;
} else if (s[i] == 'U') {
vu++;
} else {
vd++;
}
if (hl + hr == w) {
won = true;
break;
}
if (vu + vd == h) {
won = true;
break;
}
}
if (won) {
cout << "NO" << endl;
} else {
if ((sp.x <= vu || (h - sp.x + 1) <= vd) ||
(sp.y <= hl || (w - sp.y + 1) <= hr)) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
} | [
"identifier.change",
"control_flow.branch.if.condition.change",
"misc.opposites"
] | 869,419 | 869,420 | u924215188 | cpp |
p03054 | #include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
// #define int long long
#define debug(x) cerr << #x << " = " << x << endl
#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); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
const double EPS = 1e-9;
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int h, w, n, sr, sc;
cin >> h >> w >> n >> sr >> sc;
string s, t;
cin >> s >> t;
sr--;
sc--;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
char moji[4] = {'L', 'R', 'U', 'D'};
map<char, char> rev = {{'L', 'R'}, {'R', 'L'}, {'U', 'D'}, {'D', 'U'}};
int revnum[4] = {1, 0, 3, 2};
bool drop = false;
rep(i, 4) {
int x = sr;
int y = sc;
rep(j, n) {
if (s[i] == moji[i]) {
x += dx[i];
y += dy[i];
}
if (x < 0 || x >= h || y < 0 || y >= w) {
drop = true;
break;
}
if (t[i] == rev[moji[i]]) {
int nx = x + dx[revnum[i]];
int ny = y + dy[revnum[i]];
if (nx >= 0 && nx < h && ny >= 0 && ny < w) {
x = nx;
y = ny;
}
}
}
}
if (drop) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
// #define int long long
#define debug(x) cerr << #x << " = " << x << endl
#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); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
const double EPS = 1e-9;
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int h, w, n, sr, sc;
cin >> h >> w >> n >> sr >> sc;
string s, t;
cin >> s >> t;
sr--;
sc--;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
char moji[4] = {'L', 'R', 'U', 'D'};
map<char, char> rev = {{'L', 'R'}, {'R', 'L'}, {'U', 'D'}, {'D', 'U'}};
int revnum[4] = {1, 0, 3, 2};
bool drop = false;
rep(i, 4) {
int x = sr;
int y = sc;
rep(j, n) {
if (s[j] == moji[i]) {
x += dx[i];
y += dy[i];
}
if (x < 0 || x >= h || y < 0 || y >= w) {
drop = true;
break;
}
if (t[j] == rev[moji[i]]) {
int nx = x + dx[revnum[i]];
int ny = y + dy[revnum[i]];
if (nx >= 0 && nx < h && ny >= 0 && ny < w) {
x = nx;
y = ny;
}
}
}
}
if (drop) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
return 0;
}
| [
"identifier.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change",
"literal.string.change",
"io.output.change"
] | 869,422 | 869,423 | u799021348 | cpp |
p03054 | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char **argv) {
int H, W, N, sr, sc;
cin >> H >> W >> N >> sr >> sc;
string S, T;
cin >> S >> T;
int cur = sc - 1;
for (int i = 0; i < N; i++) {
if (S[i] == 'R')
cur++;
if (cur == W) {
cout << "No\n";
return 0;
}
if (T[i] == 'L')
cur = max(cur - 1, 0);
}
cur = sc - 1;
for (int i = 0; i < N; i++) {
if (S[i] == 'L')
cur--;
if (cur == -1) {
cout << "No\n";
return 0;
}
if (T[i] == 'R')
cur = min(cur + 1, W - 1);
}
cur = sr - 1;
for (int i = 0; i < N; i++) {
if (S[i] == 'D')
cur++;
if (cur == H) {
cout << "No\n";
return 0;
}
if (T[i] == 'U')
cur = max(cur - 1, 0);
}
cur = sr - 1;
for (int i = 0; i < N; i++) {
if (S[i] == 'U')
cur--;
if (cur == -1) {
cout << "No\n";
return 0;
}
if (T[i] == 'D')
cur = min(cur + 1, H - 1);
}
cout << "Yes\n";
return 0;
}
| #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char **argv) {
int H, W, N, sr, sc;
cin >> H >> W >> N >> sr >> sc;
string S, T;
cin >> S >> T;
int cur = sc - 1;
for (int i = 0; i < N; i++) {
if (S[i] == 'R')
cur++;
if (cur == W) {
cout << "NO\n";
return 0;
}
if (T[i] == 'L')
cur = max(cur - 1, 0);
}
cur = sc - 1;
for (int i = 0; i < N; i++) {
if (S[i] == 'L')
cur--;
if (cur == -1) {
cout << "NO\n";
return 0;
}
if (T[i] == 'R')
cur = min(cur + 1, W - 1);
}
cur = sr - 1;
for (int i = 0; i < N; i++) {
if (S[i] == 'D')
cur++;
if (cur == H) {
cout << "NO\n";
return 0;
}
if (T[i] == 'U')
cur = max(cur - 1, 0);
}
cur = sr - 1;
for (int i = 0; i < N; i++) {
if (S[i] == 'U')
cur--;
if (cur == -1) {
cout << "NO\n";
return 0;
}
if (T[i] == 'D')
cur = min(cur + 1, H - 1);
}
cout << "YES\n";
return 0;
}
| [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 869,444 | 869,445 | u878657050 | cpp |
p03054 | #include <bits/stdc++.h>
using namespace std;
//#define MOD 1000000007
#define MOD 998244353
#define INF 100000000000000009
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define OREP(i, n) for (int i = 1; i <= (n); ++i)
#define ZREP(i, n) for (int i = 1; i < (n); ++i)
#define YES(s) s ? cout << "YES" << endl : cout << "NO" << endl
#define Yes(s) s ? cout << "Yes" << endl : cout << "No" << endl
#define out(s, t, u) s ? cout << t << endl : cout << u << endl
#define int ll
#define Endl endl
signed main() {
int H, W, N;
int sr, sc;
string S, T;
cin >> H >> W >> N;
cin >> sr >> sc;
cin >> S >> T;
bool NO = false;
// UD=sc,LR=sr;
int now = sc;
REP(i, N) {
// Lに出す
// SはLに振り、TはRに振る
if (S[i] == 'L') {
now--;
}
if (1 > now || now > W) {
NO = true;
}
if (T[i] == 'R' && now != W) {
now++;
}
if (1 > now || now > W) {
NO = true;
}
}
now = sc;
REP(i, N) {
// Rに出す
// SはRに振り、TはLに振る
if (S[i] == 'R') {
now++;
}
if (1 > now || now > W) {
NO = true;
}
if (T[i] == 'L' && now != 1) {
now--;
}
if (1 > now || now > W) {
NO = true;
}
}
//----------ここから横-----------
now = sr;
REP(i, N) {
// Uに出す
// SはUに振り、TはDに振る
if (S[i] == 'U') {
now--;
}
if (1 > now || now > H) {
NO = true;
}
if (T[i] == 'D' && now != H) {
now++;
}
if (1 > now || now > H) {
NO = true;
}
}
now = sr;
REP(i, N) {
// Dに出す
// SはDに振り、TはUに振る
if (S[i] == 'D') {
now++;
}
if (1 > now || now > H) {
NO = true;
}
if (T[i] == 'U' && now != H) {
now--;
}
if (1 > now || now > H) {
NO = true;
}
}
if (NO == true) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
//#define MOD 1000000007
#define MOD 998244353
#define INF 100000000000000009
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define OREP(i, n) for (int i = 1; i <= (n); ++i)
#define ZREP(i, n) for (int i = 1; i < (n); ++i)
#define YES(s) s ? cout << "YES" << endl : cout << "NO" << endl
#define Yes(s) s ? cout << "Yes" << endl : cout << "No" << endl
#define out(s, t, u) s ? cout << t << endl : cout << u << endl
#define int ll
#define Endl endl
signed main() {
int H, W, N;
int sr, sc;
string S, T;
cin >> H >> W >> N;
cin >> sr >> sc;
cin >> S >> T;
bool NO = false;
// UD=sc,LR=sr;
int now = sc;
REP(i, N) {
// Lに出す
// SはLに振り、TはRに振る
if (S[i] == 'L') {
now--;
}
if (1 > now || now > W) {
NO = true;
}
if (T[i] == 'R' && now != W) {
now++;
}
if (1 > now || now > W) {
NO = true;
}
}
now = sc;
REP(i, N) {
// Rに出す
// SはRに振り、TはLに振る
if (S[i] == 'R') {
now++;
}
if (1 > now || now > W) {
NO = true;
}
if (T[i] == 'L' && now != 1) {
now--;
}
if (1 > now || now > W) {
NO = true;
}
}
//----------ここから横-----------
now = sr;
REP(i, N) {
// Uに出す
// SはUに振り、TはDに振る
if (S[i] == 'U') {
now--;
}
if (1 > now || now > H) {
NO = true;
}
if (T[i] == 'D' && now != H) {
now++;
}
if (1 > now || now > H) {
NO = true;
}
}
now = sr;
REP(i, N) {
// Dに出す
// SはDに振り、TはUに振る
if (S[i] == 'D') {
now++;
}
if (1 > now || now > H) {
NO = true;
}
if (T[i] == 'U' && now != 1) {
now--;
}
if (1 > now || now > H) {
NO = true;
}
}
if (NO == true) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
return 0;
}
| [
"identifier.replace.remove",
"literal.replace.add",
"control_flow.branch.if.condition.change"
] | 869,453 | 869,454 | u554953477 | cpp |
p03054 | #include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v = (i)
#define FORE(i, c) for (VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(), (v).end()
#define PII pair<int, int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>
#define debug(x) \
{ cout << #x << " = " << x << endl; }
#define debug2(x, y) \
{ cerr << #x << " = " << x << ", " << #y << " = " << y << endl; }
#define debug3(x, y, z) \
{ \
cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z \
<< " = " << z << endl; \
}
#define debugv(x) \
{ \
{ \
cout << #x << " = "; \
FORE(itt, (x)) cerr << *itt << ", "; \
cerr << endl; \
} \
}
#define debugt(t, n) \
{ \
{ \
cerr << #t << " = "; \
FOR(it, 0, (n)) cerr << t[it] << ", "; \
cerr << endl; \
} \
}
#define make(x) \
int(x); \
scanf("%d", &(x));
#define make2(x, y) \
int(x), (y); \
scanf("%d%d", &(x), &(y));
#define make3(x, y, z) \
int(x), (y), (z); \
scanf("%d%d%d", &(x), &(y), &(z));
#define make4(x, y, z, t) \
int(x), (y), (z), (t); \
scanf("%d%d%d%d", &(x), &(y), &(z), &(t));
#define makev(v, n) \
VI(v); \
FOR(i, 0, (n)) { \
make(a); \
(v).pb(a); \
}
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue
#define read(x) scanf("%d", &(x));
#define read2(x, y) scanf("%d%d", &(x), &(y));
#define read3(x, y, z) scanf("%d%d%d", &(x), &(y), &(z));
#define read4(x, y, z, t) scanf("%d%d%d%d", &(x), &(y), &(z), &(t));
#define readv(v, n) \
FOR(i, 0, (n)) { \
make(a); \
(v).pb(a); \
}
#define jeb() fflush(stdout);
using namespace std;
int mod = 1e9 + 7;
char s[223456];
char t[223456];
int main() {
make3(n, m, k);
make2(x, y);
x--;
y--;
scanf("%s", s);
scanf("%s", t);
int x1 = 0, x2 = m;
int y1 = 0, y2 = n;
bool ok = true;
FORD(i, k - 1, 0) {
if (s[i] == 'L') {
x1++;
} else if (s[i] == 'R') {
x2--;
} else if (s[i] == 'U') {
y1++;
} else if (s[i] == 'D') {
y2--;
}
if (x1 >= x2 || y1 >= y2)
ok = false;
x1 = max(x1, 0);
y1 = max(y1, 0);
x2 = min(x2, m);
y2 = min(y2, n);
if (i == 0)
continue;
if (t[i - 1] == 'L') {
x2++;
} else if (t[i - 1] == 'R') {
x1--;
} else if (t[i - 1] == 'U') {
y2++;
} else if (t[i - 1] == 'D') {
y1--;
}
x1 = max(x1, 0);
y1 = max(y1, 0);
x2 = min(x2, m);
y2 = min(y2, n);
}
if (ok && x1 <= y && y <= x2 && y1 <= x && x <= y2)
printf("YES\n");
else
printf("NO\n");
}
| #include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v = (i)
#define FORE(i, c) for (VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(), (v).end()
#define PII pair<int, int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>
#define debug(x) \
{ cout << #x << " = " << x << endl; }
#define debug2(x, y) \
{ cerr << #x << " = " << x << ", " << #y << " = " << y << endl; }
#define debug3(x, y, z) \
{ \
cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z \
<< " = " << z << endl; \
}
#define debugv(x) \
{ \
{ \
cout << #x << " = "; \
FORE(itt, (x)) cerr << *itt << ", "; \
cerr << endl; \
} \
}
#define debugt(t, n) \
{ \
{ \
cerr << #t << " = "; \
FOR(it, 0, (n)) cerr << t[it] << ", "; \
cerr << endl; \
} \
}
#define make(x) \
int(x); \
scanf("%d", &(x));
#define make2(x, y) \
int(x), (y); \
scanf("%d%d", &(x), &(y));
#define make3(x, y, z) \
int(x), (y), (z); \
scanf("%d%d%d", &(x), &(y), &(z));
#define make4(x, y, z, t) \
int(x), (y), (z), (t); \
scanf("%d%d%d%d", &(x), &(y), &(z), &(t));
#define makev(v, n) \
VI(v); \
FOR(i, 0, (n)) { \
make(a); \
(v).pb(a); \
}
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue
#define read(x) scanf("%d", &(x));
#define read2(x, y) scanf("%d%d", &(x), &(y));
#define read3(x, y, z) scanf("%d%d%d", &(x), &(y), &(z));
#define read4(x, y, z, t) scanf("%d%d%d%d", &(x), &(y), &(z), &(t));
#define readv(v, n) \
FOR(i, 0, (n)) { \
make(a); \
(v).pb(a); \
}
#define jeb() fflush(stdout);
using namespace std;
int mod = 1e9 + 7;
char s[223456];
char t[223456];
int main() {
make3(n, m, k);
make2(x, y);
x--;
y--;
scanf("%s", s);
scanf("%s", t);
int x1 = 0, x2 = m;
int y1 = 0, y2 = n;
bool ok = true;
FORD(i, k - 1, 0) {
if (s[i] == 'L') {
x1++;
} else if (s[i] == 'R') {
x2--;
} else if (s[i] == 'U') {
y1++;
} else if (s[i] == 'D') {
y2--;
}
if (x1 >= x2 || y1 >= y2)
ok = false;
x1 = max(x1, 0);
y1 = max(y1, 0);
x2 = min(x2, m);
y2 = min(y2, n);
if (i == 0)
continue;
if (t[i - 1] == 'L') {
x2++;
} else if (t[i - 1] == 'R') {
x1--;
} else if (t[i - 1] == 'U') {
y2++;
} else if (t[i - 1] == 'D') {
y1--;
}
x1 = max(x1, 0);
y1 = max(y1, 0);
x2 = min(x2, m);
y2 = min(y2, n);
}
if (ok && x1 <= y && y < x2 && y1 <= x && x < y2)
printf("YES\n");
else
printf("NO\n");
}
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 869,459 | 869,460 | u684583379 | cpp |
p03054 | #include <cstdio>
#include <cstring>
#define ran 202202
int n, m, L;
int x, y;
char a[ran], b[ran];
int fa[ran], fb[ran];
bool calc(int st, int lim) {
int l = 1, r = lim;
for (int i = L - 1; i >= 0; i--) {
if (fb[i] == 1 && l > 1)
l--;
if (fb[i] == -1 && r < lim)
r++;
if (fa[i] == -1)
l++;
if (fa[i] == 1)
r--;
if (st < l || r < st)
return false;
}
return l <= st && st <= r;
}
int main() {
scanf("%d%d%d", &n, &m, &L);
scanf("%d%d", &x, &y);
scanf("%s%s", a, b);
bool ans = true;
memset(fa, 0, sizeof fa);
memset(fb, 0, sizeof fb);
for (int i = 0; i < L; i++) {
if (a[i] == 'U')
fa[i] = -1;
if (a[i] == 'D')
fa[i] = 1;
if (b[i] == 'U')
fb[i] = -1;
if (b[i] == 'D')
fb[i] = 1;
}
ans &= calc(x, n);
memset(fa, 0, sizeof fa);
memset(fb, 0, sizeof fb);
for (int i = 0; i < L; i++) {
if (a[i] == 'L')
fa[i] = -1;
if (a[i] == 'R')
fa[i] = 1;
if (b[i] == 'L')
fb[i] = -1;
if (b[i] == 'R')
fb[i] = 1;
}
ans &= calc(y, m);
puts(ans ? "YES" : "NO");
return 0;
} | #include <cstdio>
#include <cstring>
#define ran 202202
int n, m, L;
int x, y;
char a[ran], b[ran];
int fa[ran], fb[ran];
bool calc(int st, int lim) {
int l = 1, r = lim;
for (int i = L - 1; i >= 0; i--) {
if (fb[i] == 1 && l > 1)
l--;
if (fb[i] == -1 && r < lim)
r++;
if (fa[i] == -1)
l++;
if (fa[i] == 1)
r--;
if (l > r)
return false;
}
return l <= st && st <= r;
}
int main() {
scanf("%d%d%d", &n, &m, &L);
scanf("%d%d", &x, &y);
scanf("%s%s", a, b);
bool ans = true;
memset(fa, 0, sizeof fa);
memset(fb, 0, sizeof fb);
for (int i = 0; i < L; i++) {
if (a[i] == 'U')
fa[i] = -1;
if (a[i] == 'D')
fa[i] = 1;
if (b[i] == 'U')
fb[i] = -1;
if (b[i] == 'D')
fb[i] = 1;
}
ans &= calc(x, n);
memset(fa, 0, sizeof fa);
memset(fb, 0, sizeof fb);
for (int i = 0; i < L; i++) {
if (a[i] == 'L')
fa[i] = -1;
if (a[i] == 'R')
fa[i] = 1;
if (b[i] == 'L')
fb[i] = -1;
if (b[i] == 'R')
fb[i] = 1;
}
ans &= calc(y, m);
puts(ans ? "YES" : "NO");
return 0;
} | [
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove",
"control_flow.branch.if.condition.change"
] | 869,488 | 869,489 | u534772498 | cpp |
p03054 | #include <bits/stdc++.h>
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
template <typename T> constexpr bool chmax(T &a, const T b) {
if (a >= b)
return false;
a = b;
return true;
}
template <typename T> constexpr bool chmin(T &a, const T b) {
if (a <= b)
return false;
a = b;
return true;
}
/*-------------------------------------------*/
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
int h, w, n;
cin >> h >> w >> n;
int L = 0, R = w + 1, U = 0, D = h + 1;
int x, y;
cin >> x >> y;
string s, t;
cin >> s >> t;
for (int i = n - 1; i >= 0; i--) {
if (t[i] == 'L' && R <= w)
R++;
if (t[i] == 'R' && 1 <= L)
L--;
if (t[i] == 'U' && D <= h)
D++;
if (t[i] == 'D' && 1 <= U)
U--;
if (s[i] == 'L')
L++;
if (s[i] == 'R')
R--;
if (s[i] == 'U')
U++;
if (s[i] == 'D')
D--;
if (w <= L || R <= 1 || h <= U || D <= 1) {
cout << "No\n";
return 0;
}
}
cout << (L < y && y < R && U < x && x < D ? "Yes\n" : "No\n");
return 0;
} | #include <bits/stdc++.h>
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
template <typename T> constexpr bool chmax(T &a, const T b) {
if (a >= b)
return false;
a = b;
return true;
}
template <typename T> constexpr bool chmin(T &a, const T b) {
if (a <= b)
return false;
a = b;
return true;
}
/*-------------------------------------------*/
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
int h, w, n;
cin >> h >> w >> n;
int L = 0, R = w + 1, U = 0, D = h + 1;
int x, y;
cin >> x >> y;
string s, t;
cin >> s >> t;
for (int i = n - 1; i >= 0; i--) {
if (t[i] == 'L' && R <= w)
R++;
if (t[i] == 'R' && 1 <= L)
L--;
if (t[i] == 'U' && D <= h)
D++;
if (t[i] == 'D' && 1 <= U)
U--;
if (s[i] == 'L')
L++;
if (s[i] == 'R')
R--;
if (s[i] == 'U')
U++;
if (s[i] == 'D')
D--;
if (w <= L || R <= 1 || h <= U || D <= 1) {
cout << "NO\n";
return 0;
}
}
cout << (L < y && y < R && U < x && x < D ? "YES\n" : "NO\n");
return 0;
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 869,675 | 869,676 | u047554023 | cpp |
p03054 | #include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define ll long long
using namespace std;
long long MOD = 1000000007;
template <typename T> void cout_vec(vector<T> &vec) {
for (int i = 0; i < vec.size(); i++) {
if (i != 0) {
cout << ' ';
}
cout << vec[i];
}
cout << endl;
}
int main() {
int H, W, N;
cin >> H >> W >> N;
int sr, sc;
cin >> sr >> sc;
string S, T;
cin >> S >> T;
vector<vector<int>> dpLR(N + 1, vector<int>(2, 0));
dpLR[N] = {1, W};
vector<vector<int>> dpUD(N + 1, vector<int>(2, 0));
dpUD[N] = {1, H};
for (int i = N; i > 0; i--) {
if (T[i - 1] == 'L') {
dpLR[i][1] = min(W, dpLR[i][1] + 1);
} else if (T[i - 1] == 'R') {
dpLR[i][0] = max(1, dpLR[i][0] - 1);
} else if (T[i - 1] == 'U') {
dpUD[i][1] = min(H, dpUD[i][1] + 1);
} else if (T[i - 1] == 'D') {
dpUD[i][0] = max(1, dpUD[i][0] - 1);
}
if (S[i - 1] == 'L') {
dpLR[i - 1][0] = dpLR[i][0] + 1;
dpLR[i - 1][1] = dpLR[i][1];
dpUD[i - 1] = dpUD[i];
} else if (S[i - 1] == 'R') {
dpLR[i - 1][1] = dpLR[i][1] - 1;
dpLR[i - 1][0] = dpLR[i][0];
dpUD[i - 1] = dpUD[i];
} else if (S[i - 1] == 'U') {
dpUD[i - 1][0] = dpUD[i][0] + 1;
dpUD[i - 1][1] = dpUD[i][1];
dpLR[i - 1] = dpLR[i];
} else if (S[i - 1] == 'D') {
dpUD[i - 1][1] = dpUD[i][1] - 1;
dpUD[i - 1][0] = dpUD[i][0];
dpLR[i - 1] = dpLR[i];
}
// cout << i << ' ' << endl;;
// cout_vec(dpLR[i-1]);
// cout_vec(dpUD[i-1]);
if (dpLR[i - 1][0] > dpLR[i - 1][1]) {
cout << "No" << endl;
return 0;
} else if (dpUD[i - 1][0] > dpUD[i - 1][1]) {
cout << "No" << endl;
return 0;
}
}
if (dpLR[0][0] <= sc && sc <= dpLR[0][1] && dpUD[0][0] <= sr &&
sr << dpUD[0][1]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define ll long long
using namespace std;
long long MOD = 1000000007;
template <typename T> void cout_vec(vector<T> &vec) {
for (int i = 0; i < vec.size(); i++) {
if (i != 0) {
cout << ' ';
}
cout << vec[i];
}
cout << endl;
}
int main() {
int H, W, N;
cin >> H >> W >> N;
int sr, sc;
cin >> sr >> sc;
string S, T;
cin >> S >> T;
vector<vector<int>> dpLR(N + 1, vector<int>(2, 0));
dpLR[N] = {1, W};
vector<vector<int>> dpUD(N + 1, vector<int>(2, 0));
dpUD[N] = {1, H};
for (int i = N; i > 0; i--) {
if (T[i - 1] == 'L') {
dpLR[i][1] = min(W, dpLR[i][1] + 1);
} else if (T[i - 1] == 'R') {
dpLR[i][0] = max(1, dpLR[i][0] - 1);
} else if (T[i - 1] == 'U') {
dpUD[i][1] = min(H, dpUD[i][1] + 1);
} else if (T[i - 1] == 'D') {
dpUD[i][0] = max(1, dpUD[i][0] - 1);
}
if (S[i - 1] == 'L') {
dpLR[i - 1][0] = dpLR[i][0] + 1;
dpLR[i - 1][1] = dpLR[i][1];
dpUD[i - 1] = dpUD[i];
} else if (S[i - 1] == 'R') {
dpLR[i - 1][1] = dpLR[i][1] - 1;
dpLR[i - 1][0] = dpLR[i][0];
dpUD[i - 1] = dpUD[i];
} else if (S[i - 1] == 'U') {
dpUD[i - 1][0] = dpUD[i][0] + 1;
dpUD[i - 1][1] = dpUD[i][1];
dpLR[i - 1] = dpLR[i];
} else if (S[i - 1] == 'D') {
dpUD[i - 1][1] = dpUD[i][1] - 1;
dpUD[i - 1][0] = dpUD[i][0];
dpLR[i - 1] = dpLR[i];
}
// cout << i << ' ' << endl;;
// cout_vec(dpLR[i-1]);
// cout_vec(dpUD[i-1]);
if (dpLR[i - 1][0] > dpLR[i - 1][1]) {
cout << "NO" << endl;
return 0;
} else if (dpUD[i - 1][0] > dpUD[i - 1][1]) {
cout << "NO" << endl;
return 0;
}
}
if (dpLR[0][0] <= sc && sc <= dpLR[0][1] && dpUD[0][0] <= sr &&
sr <= dpUD[0][1]) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change",
"control_flow.branch.if.condition.change"
] | 869,692 | 869,691 | u658993896 | cpp |
p03054 | #include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main() {
int h, w, n;
cin >> h >> w >> n;
int sr, sc;
cin >> sr >> sc;
--sr;
--sc;
string s, t;
cin >> s >> t;
int l = 0, r = w - 1, u = 0, d = h - 1;
if (s[n - 1] == 'L') {
l = 1;
} else if (s[n - 1] == 'R') {
r = w - 2;
} else if (s[n - 1] == 'U') {
u = 1;
} else {
d = h - 2;
}
for (int i = n - 2; i >= 0; i--) {
if (t[i] == 'L') {
r = min(r + 1, w - 1);
} else if (t[i] == 'R') {
l = max(l - 1, 0);
} else if (t[i] == 'U') {
u = min(d + 1, h - 1);
} else {
d = max(u - 1, 0);
}
if (s[i] == 'L') {
l = l + 1;
} else if (s[i] == 'R') {
r = r - 1;
} else if (s[i] == 'U') {
u = u + 1;
} else {
d = d - 1;
}
if (l > r || u > d) {
cout << "NO" << endl;
return 0;
}
}
if (sc >= l && sc <= r && sr >= u && sr <= d) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main() {
int h, w, n;
cin >> h >> w >> n;
int sr, sc;
cin >> sr >> sc;
--sr;
--sc;
string s, t;
cin >> s >> t;
int l = 0, r = w - 1, u = 0, d = h - 1;
if (s[n - 1] == 'L') {
l = 1;
} else if (s[n - 1] == 'R') {
r = w - 2;
} else if (s[n - 1] == 'U') {
u = 1;
} else {
d = h - 2;
}
for (int i = n - 2; i >= 0; i--) {
if (t[i] == 'L') {
r = min(r + 1, w - 1);
} else if (t[i] == 'R') {
l = max(l - 1, 0);
} else if (t[i] == 'U') {
d = min(d + 1, h - 1);
} else {
u = max(u - 1, 0);
}
if (s[i] == 'L') {
l = l + 1;
} else if (s[i] == 'R') {
r = r - 1;
} else if (s[i] == 'U') {
u = u + 1;
} else {
d = d - 1;
}
if (l > r || u > d) {
cout << "NO" << endl;
return 0;
}
}
if (sc >= l && sc <= r && sr >= u && sr <= d) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
} | [
"assignment.variable.change",
"identifier.change"
] | 869,693 | 869,694 | u313766957 | cpp |
p03054 | #include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main() {
int h, w, n;
cin >> h >> w >> n;
int sr, sc;
cin >> sr >> sc;
--sr;
--sc;
string s, t;
cin >> s >> t;
int l = 0, r = w - 1, u = 0, d = h - 1;
if (s[n - 1] == 'L') {
l = 1;
} else if (s[n - 1] == 'R') {
r = w - 2;
} else if (s[n - 1] == 'U') {
u = 1;
} else {
d = h - 2;
}
for (int i = n - 2; i >= 0; i--) {
if (t[i] == 'L') {
r = min(r + 1, w - 1);
} else if (t[i] == 'R') {
l = max(l - 1, 0);
} else if (t[i] == 'U') {
u = min(d + 1, h - 1);
} else {
d = max(u - 1, 0);
}
if (s[i] == 'L') {
l = l + 1;
} else if (s[i] == 'R') {
r = r - 1;
} else if (s[i] == 'U') {
u = u + 1;
} else {
d = d - 1;
}
if (l > r && u > d) {
cout << "NO" << endl;
return 0;
}
}
if (sc >= l && sc <= r && sr >= u && sr <= d) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main() {
int h, w, n;
cin >> h >> w >> n;
int sr, sc;
cin >> sr >> sc;
--sr;
--sc;
string s, t;
cin >> s >> t;
int l = 0, r = w - 1, u = 0, d = h - 1;
if (s[n - 1] == 'L') {
l = 1;
} else if (s[n - 1] == 'R') {
r = w - 2;
} else if (s[n - 1] == 'U') {
u = 1;
} else {
d = h - 2;
}
for (int i = n - 2; i >= 0; i--) {
if (t[i] == 'L') {
r = min(r + 1, w - 1);
} else if (t[i] == 'R') {
l = max(l - 1, 0);
} else if (t[i] == 'U') {
d = min(d + 1, h - 1);
} else {
u = max(u - 1, 0);
}
if (s[i] == 'L') {
l = l + 1;
} else if (s[i] == 'R') {
r = r - 1;
} else if (s[i] == 'U') {
u = u + 1;
} else {
d = d - 1;
}
if (l > r || u > d) {
cout << "NO" << endl;
return 0;
}
}
if (sc >= l && sc <= r && sr >= u && sr <= d) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
} | [
"assignment.variable.change",
"identifier.change",
"misc.opposites",
"control_flow.branch.if.condition.change"
] | 869,695 | 869,694 | u313766957 | cpp |
p03054 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int h, w, n, x, y;
char a[maxn], b[maxn];
void no() {
puts("NO");
exit(0);
}
int main() {
scanf("%d%d%d", &h, &w, &n);
scanf("%d%d", &x, &y);
scanf("%s%s", a + 1, b + 1);
int s = 1, t = w;
for (int i = n; i; --i) {
if (b[i] == 'L')
t = min(t + 1, w);
if (b[i] == 'R')
s = max(t - 1, 1);
if (a[i] == 'L')
++s;
if (a[i] == 'R')
--t;
if (s > t)
no();
}
if (y > t || y < s)
no();
s = 1, t = h;
for (int i = n; i; --i) {
if (b[i] == 'U')
t = min(t + 1, h);
if (b[i] == 'D')
s = max(t - 1, 1);
if (a[i] == 'U')
++s;
if (a[i] == 'D')
--t;
if (s > t)
no();
}
if (x > t || x < s)
no();
puts("YES");
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int h, w, n, x, y;
char a[maxn], b[maxn];
void no() {
puts("NO");
exit(0);
}
int main() {
scanf("%d%d%d", &h, &w, &n);
scanf("%d%d", &x, &y);
scanf("%s%s", a + 1, b + 1);
int s = 1, t = w;
for (int i = n; i; --i) {
if (b[i] == 'L')
t = min(t + 1, w);
if (b[i] == 'R')
s = max(s - 1, 1);
if (a[i] == 'L')
++s;
if (a[i] == 'R')
--t;
if (s > t)
no();
}
if (y > t || y < s)
no();
s = 1, t = h;
for (int i = n; i; --i) {
if (b[i] == 'U')
t = min(t + 1, h);
if (b[i] == 'D')
s = max(s - 1, 1);
if (a[i] == 'U')
++s;
if (a[i] == 'D')
--t;
if (s > t)
no();
}
if (x > t || x < s)
no();
puts("YES");
return 0;
}
| [
"assignment.value.change",
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 869,696 | 869,697 | u915913072 | cpp |
p03054 | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define MOD 1000000007
#define MOD2 998244353
#define int long long
//#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &A) {
for (int i = 0; i < A.size(); i++)
os << A[i] << " ";
os << endl;
return os;
}
template <> ostream &operator<<(ostream &os, const vector<vector<int>> &A) {
int N = A.size();
int M;
if (N > 0)
M = A[0].size();
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
os << A[i][j] << " ";
os << endl;
}
return os;
}
typedef pair<int, int> pii;
typedef long long ll;
struct edge {
int from, to, d, c;
edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
from = _from;
to = _to;
d = _d;
c = _c;
}
bool operator<(const edge &rhs) const {
return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
}
};
struct aabb {
int x1, y1, x2, y2;
aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};
typedef vector<edge> edges;
typedef vector<edges> graph;
struct flow {
int to, cap, rev, cost;
flow(int to = 0, int cap = 0, int rev = 0, int cost = 0)
: to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector<vector<flow>> flows;
const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);
int pow2(int n) { return 1 << n; }
template <typename T, typename U> bool chmin(T &x, const U &y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template <typename T, typename U> bool chmax(T &x, const U &y) {
if (x < y) {
x = y;
return true;
}
return false;
}
struct initializer {
initializer() { cout << fixed << setprecision(11); }
};
initializer _____;
int N, M, K, T, Q, H, W;
signed main() {
cin >> H >> W >> N;
int sr, sc;
cin >> sr >> sc;
string S, T;
cin >> S >> T;
string ans = "Yes";
char d[] = {'L', 'U', 'R', 'D'};
rep(k, 4) {
int r = sr, c = sc;
rep(i, N) {
if (S[i] == d[k]) {
r += di[k];
c += dj[k];
if (r < 1 || r > H || c < 1 || c > W)
ans = "No";
}
if (T[i] == d[(k + 2) % 4]) {
if (0 < r - di[k] && r - di[k] <= H && 0 < c - dj[k] &&
c - dj[k] <= W) {
r -= di[k];
c -= dj[k];
}
}
}
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define MOD 1000000007
#define MOD2 998244353
#define int long long
//#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &A) {
for (int i = 0; i < A.size(); i++)
os << A[i] << " ";
os << endl;
return os;
}
template <> ostream &operator<<(ostream &os, const vector<vector<int>> &A) {
int N = A.size();
int M;
if (N > 0)
M = A[0].size();
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
os << A[i][j] << " ";
os << endl;
}
return os;
}
typedef pair<int, int> pii;
typedef long long ll;
struct edge {
int from, to, d, c;
edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
from = _from;
to = _to;
d = _d;
c = _c;
}
bool operator<(const edge &rhs) const {
return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
}
};
struct aabb {
int x1, y1, x2, y2;
aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};
typedef vector<edge> edges;
typedef vector<edges> graph;
struct flow {
int to, cap, rev, cost;
flow(int to = 0, int cap = 0, int rev = 0, int cost = 0)
: to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector<vector<flow>> flows;
const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);
int pow2(int n) { return 1 << n; }
template <typename T, typename U> bool chmin(T &x, const U &y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template <typename T, typename U> bool chmax(T &x, const U &y) {
if (x < y) {
x = y;
return true;
}
return false;
}
struct initializer {
initializer() { cout << fixed << setprecision(11); }
};
initializer _____;
int N, M, K, T, Q, H, W;
signed main() {
cin >> H >> W >> N;
int sr, sc;
cin >> sr >> sc;
string S, T;
cin >> S >> T;
string ans = "YES";
char d[] = {'L', 'U', 'R', 'D'};
rep(k, 4) {
int r = sr, c = sc;
rep(i, N) {
if (S[i] == d[k]) {
r += di[k];
c += dj[k];
if (r < 1 || r > H || c < 1 || c > W)
ans = "NO";
}
if (T[i] == d[(k + 2) % 4]) {
if (0 < r - di[k] && r - di[k] <= H && 0 < c - dj[k] &&
c - dj[k] <= W) {
r -= di[k];
c -= dj[k];
}
}
}
}
cout << ans << endl;
return 0;
} | [
"literal.string.change",
"literal.string.case.change",
"variable_declaration.value.change",
"assignment.value.change"
] | 869,713 | 869,714 | u537874719 | cpp |
p03054 | #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long int lli;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
#define N_MAX 200000
#define MOD 1000000007
int N;
bool func(int width, int pos, char *S, char *T) {
int left = 1, right = width;
for (int i = N - 1; i >= 0; i--) {
if ('L' == T[i - 1]) {
right = min(width, right + 1);
} else if ('R' == T[i - 1]) {
left = max(1, left - 1);
}
if ('L' == S[i]) {
left++;
} else if ('R' == S[i]) {
right--;
}
if (left > right) {
return false;
}
}
if (left <= pos && pos <= right) {
return true;
}
return false;
}
void change(char *S) {
for (int i = 0; i < N; i++) {
if ('L' == S[i]) {
S[i] = 'U';
} else if ('R' == S[i]) {
S[i] = 'D';
} else if ('U' == S[i]) {
S[i] = 'L';
} else if ('D' == S[i]) {
S[i] = 'R';
}
}
return;
}
void solv() {
int H, W;
scanf("%d%d%d", &H, &W, &N);
pair<int, int> start;
scanf("%d%d", &start.first, &start.second);
char S[N_MAX + 10], T[N_MAX + 10];
scanf("%s%s", S, T);
if (!func(W, start.second, S, T)) {
printf("NO");
return;
}
change(S);
change(T);
if (!func(H, start.first, S, T)) {
printf("NO");
}
printf("YES");
return;
}
int main() {
FILE *fin = NULL, *fout = NULL;
// fin = freopen("input.txt", "r", stdin);
// fout = freopen("output.txt", "w", stdout);
solv();
// finalize
if (NULL != fin)
fclose(fin);
if (NULL != fout)
fclose(fout);
return 0;
} | #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long int lli;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
#define N_MAX 200000
#define MOD 1000000007
int N;
bool func(int width, int pos, char *S, char *T) {
int left = 1, right = width;
for (int i = N - 1; i >= 0; i--) {
if ('L' == T[i]) {
right = min(width, right + 1);
} else if ('R' == T[i]) {
left = max(1, left - 1);
}
if ('L' == S[i]) {
left++;
} else if ('R' == S[i]) {
right--;
}
if (left > right) {
return false;
}
}
if (left <= pos && pos <= right) {
return true;
}
return false;
}
void change(char *S) {
for (int i = 0; i < N; i++) {
if ('L' == S[i]) {
S[i] = 'U';
} else if ('R' == S[i]) {
S[i] = 'D';
} else if ('U' == S[i]) {
S[i] = 'L';
} else if ('D' == S[i]) {
S[i] = 'R';
}
}
return;
}
void solv() {
int H, W;
scanf("%d%d%d", &H, &W, &N);
pair<int, int> start;
scanf("%d%d", &start.first, &start.second);
char S[N_MAX + 10], T[N_MAX + 10];
scanf("%s%s", S, T);
if (!func(W, start.second, S, T)) {
printf("NO");
return;
}
change(S);
change(T);
if (!func(H, start.first, S, T)) {
printf("NO");
return;
}
printf("YES");
return;
}
int main() {
FILE *fin = NULL, *fout = NULL;
// fin = freopen("input.txt", "r", stdin);
// fout = freopen("output.txt", "w", stdout);
solv();
// finalize
if (NULL != fin)
fclose(fin);
if (NULL != fout)
fclose(fout);
return 0;
} | [
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove",
"control_flow.return.add"
] | 869,717 | 869,716 | u103357948 | cpp |
p03054 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> P;
int main() {
int h, w, n, sr, sc;
string s, t;
cin >> h >> w >> n >> sr >> sc >> s >> t;
int x = 1;
int xr = sr, xc = sc;
rep(i, n) {
if (s[i] == 'U')
xr--;
if (xr <= 0 || xr > h || xc <= 0 || xc > w)
x = 0;
if (t[i] == 'D' && xr != h)
xr++;
}
xr = sr, xc = sc;
rep(i, n) {
if (s[i] == 'D')
xr++;
if (xr <= 0 || xr > h || xc <= 0 || xc > w)
x = 0;
if (t[i] == 'U' && xr != 1)
xr--;
}
xr = sr, xc = sc;
rep(i, n) {
if (s[i] == 'R')
xc++;
if (xr <= 0 || xr > h || xc <= 0 || xc > w)
x = 0;
if (t[i] == 'L' && xc != 1)
xc--;
}
xr = sr, xc = sc;
rep(i, n) {
if (s[i] == 'L')
xc--;
if (xr <= 0 || xr > h || xc <= 0 || xc > w)
x = 0;
if (t[i] == 'R' && xc != w)
xc++;
}
if (x)
cout << "Yes"
<< "\n";
else
cout << "No"
<< "\n";
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> P;
int main() {
int h, w, n, sr, sc;
string s, t;
cin >> h >> w >> n >> sr >> sc >> s >> t;
int x = 1;
int xr = sr, xc = sc;
rep(i, n) {
if (s[i] == 'U')
xr--;
if (xr <= 0 || xr > h || xc <= 0 || xc > w)
x = 0;
if (t[i] == 'D' && xr != h)
xr++;
}
xr = sr, xc = sc;
rep(i, n) {
if (s[i] == 'D')
xr++;
if (xr <= 0 || xr > h || xc <= 0 || xc > w)
x = 0;
if (t[i] == 'U' && xr != 1)
xr--;
}
xr = sr, xc = sc;
rep(i, n) {
if (s[i] == 'R')
xc++;
if (xr <= 0 || xr > h || xc <= 0 || xc > w)
x = 0;
if (t[i] == 'L' && xc != 1)
xc--;
}
xr = sr, xc = sc;
rep(i, n) {
if (s[i] == 'L')
xc--;
if (xr <= 0 || xr > h || xc <= 0 || xc > w)
x = 0;
if (t[i] == 'R' && xc != w)
xc++;
}
if (x)
cout << "YES"
<< "\n";
else
cout << "NO"
<< "\n";
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 869,722 | 869,723 | u441296840 | cpp |
p03054 | #include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x, y, h, w) x >= 0 && x < h &&y >= 0 && y < w
//#define int long long
// using ll = long long;
using P = pair<int, int>;
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
const int INF = 1e+9;
const double EPS = 1e-9;
const int MOD = 1000000007;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
signed main() {
int h, w, n, sx, sy;
string s, t;
cin >> h >> w >> n >> sx >> sy >> s >> t;
sx--;
sy--;
int xmin = 0, xmax = h, ymin = 0, ymax = w;
for (int i = n - 1; i >= 0; i--) {
if (t[i] == 'U')
xmax = min(h, xmax + 1);
else if (t[i] == 'D')
xmin = max(0, xmin - 1);
else if (t[i] == 'L')
ymax = max(w, ymax + 1);
else if (t[i] == 'R')
ymin = max(0, ymin - 1);
if (s[i] == 'U')
xmin++;
else if (s[i] == 'D')
xmax--;
else if (s[i] == 'L')
ymin++;
else if (s[i] == 'R')
ymax--;
if (xmin >= xmax || ymin >= ymax) {
NO();
return 0;
}
}
if (xmin <= sx && sx < xmax && ymin <= sy && sy < ymax)
YES();
else
NO();
}
| #include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x, y, h, w) x >= 0 && x < h &&y >= 0 && y < w
//#define int long long
// using ll = long long;
using P = pair<int, int>;
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
const int INF = 1e+9;
const double EPS = 1e-9;
const int MOD = 1000000007;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
signed main() {
int h, w, n, sx, sy;
string s, t;
cin >> h >> w >> n >> sx >> sy >> s >> t;
sx--;
sy--;
int xmin = 0, xmax = h, ymin = 0, ymax = w;
for (int i = n - 1; i >= 0; i--) {
if (t[i] == 'U')
xmax = min(h, xmax + 1);
else if (t[i] == 'D')
xmin = max(0, xmin - 1);
else if (t[i] == 'L')
ymax = min(w, ymax + 1);
else if (t[i] == 'R')
ymin = max(0, ymin - 1);
if (s[i] == 'U')
xmin++;
else if (s[i] == 'D')
xmax--;
else if (s[i] == 'L')
ymin++;
else if (s[i] == 'R')
ymax--;
if (xmin >= xmax || ymin >= ymax) {
NO();
return 0;
}
}
if (xmin <= sx && sx < xmax && ymin <= sy && sy < ymax)
YES();
else
NO();
}
| [
"misc.opposites",
"assignment.value.change",
"identifier.change",
"call.function.change"
] | 869,734 | 869,735 | u456611841 | cpp |
p03054 | //
// main.cpp
//
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
template <typename T> vector<T> make_vec_nd(T init, size_t size) {
return vector<T>(size, init);
}
template <typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
auto inner = make_vec_nd(init, rest...);
return vector<decltype(inner)>(size, inner);
}
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define rrep(i, a, b) for (ll i = a - 1; i >= b; i--)
int main() {
ll H, W, N;
cin >> H >> W >> N;
ll sx, sy;
cin >> sy >> sx;
sx--;
sy--;
string S, T;
cin >> S >> T;
struct I {
ll l;
ll r;
ll u;
ll d;
};
I is_no;
T.pop_back();
ll n = S.size() + T.size();
rep(i, 0, n) {
if (i % 2 == 0) {
char c = S.back();
S.pop_back();
if (c == 'L') {
is_no.l++;
} else if (c == 'R') {
is_no.r++;
} else if (c == 'U') {
is_no.u++;
} else {
is_no.d++;
}
} else {
char c = T.back();
T.pop_back();
if (c == 'L') {
is_no.r--;
} else if (c == 'R') {
is_no.l--;
} else if (c == 'U') {
is_no.d--;
} else {
is_no.u--;
}
}
is_no.l = max((ll)0, min(W, is_no.l));
is_no.r = max((ll)0, min(W, is_no.r));
is_no.u = max((ll)0, min(H, is_no.u));
is_no.d = max((ll)0, min(H, is_no.d));
if (is_no.l + is_no.r >= W || is_no.u + is_no.d >= H) {
cout << "NO" << endl;
return 0;
}
// cout << i << ": " << is_no.l << " " << is_no.r << " " << is_no.u << " "
// << is_no.d << endl;
}
if (sx < is_no.l || sy < is_no.u || W - sx - 1 < is_no.r ||
H - sy - 1 < is_no.d) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
| //
// main.cpp
//
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
template <typename T> vector<T> make_vec_nd(T init, size_t size) {
return vector<T>(size, init);
}
template <typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
auto inner = make_vec_nd(init, rest...);
return vector<decltype(inner)>(size, inner);
}
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define rrep(i, a, b) for (ll i = a - 1; i >= b; i--)
int main() {
ll H, W, N;
cin >> H >> W >> N;
ll sx, sy;
cin >> sy >> sx;
sx--;
sy--;
string S, T;
cin >> S >> T;
struct I {
ll l;
ll r;
ll u;
ll d;
};
I is_no = {};
T.pop_back();
ll n = S.size() + T.size();
rep(i, 0, n) {
if (i % 2 == 0) {
char c = S.back();
S.pop_back();
if (c == 'L') {
is_no.l++;
} else if (c == 'R') {
is_no.r++;
} else if (c == 'U') {
is_no.u++;
} else {
is_no.d++;
}
} else {
char c = T.back();
T.pop_back();
if (c == 'L') {
is_no.r--;
} else if (c == 'R') {
is_no.l--;
} else if (c == 'U') {
is_no.d--;
} else {
is_no.u--;
}
}
is_no.l = max((ll)0, min(W, is_no.l));
is_no.r = max((ll)0, min(W, is_no.r));
is_no.u = max((ll)0, min(H, is_no.u));
is_no.d = max((ll)0, min(H, is_no.d));
if (is_no.l + is_no.r >= W || is_no.u + is_no.d >= H) {
cout << "NO" << endl;
return 0;
}
// cout << i << ": " << is_no.l << " " << is_no.r << " " << is_no.u << " "
// << is_no.d << endl;
}
if (sx < is_no.l || sy < is_no.u || W - sx - 1 < is_no.r ||
H - sy - 1 < is_no.d) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
| [
"variable_declaration.value.change"
] | 869,736 | 869,737 | u578938637 | cpp |
p03054 | #include <bits/stdc++.h>
using namespace std;
int main() {
int H, W, N;
cin >> H >> W >> N;
int sr, sc;
cin >> sr >> sc;
string S, T;
cin >> S >> T;
int L = 0;
int R = W;
int U = 0;
int D = H;
for (int i = N - 1; i >= 0; i--) {
char C = T.at(i);
if (i < N - 1) {
if ('U' == C) {
D++;
D = min(D, H);
} else if ('D' == C) {
U++;
U = max(U, 0);
} else if ('L' == C) {
R++;
R = min(R, W);
} else {
L--;
L = max(L, 0);
}
}
C = S.at(i);
if ('U' == C) {
U++;
} else if ('D' == C) {
D--;
} else if ('L' == C) {
L++;
} else {
R--;
}
if ((U == D) || (L == R)) {
cout << "NO" << endl;
return 0;
}
}
if ((sr > U) && (sr <= D) && (sc > L) && (sc <= R)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int H, W, N;
cin >> H >> W >> N;
int sr, sc;
cin >> sr >> sc;
string S, T;
cin >> S >> T;
int L = 0;
int R = W;
int U = 0;
int D = H;
for (int i = N - 1; i >= 0; i--) {
char C = T.at(i);
if (i < N - 1) {
if ('U' == C) {
D++;
D = min(D, H);
} else if ('D' == C) {
U--;
U = max(U, 0);
} else if ('L' == C) {
R++;
R = min(R, W);
} else {
L--;
L = max(L, 0);
}
}
C = S.at(i);
if ('U' == C) {
U++;
} else if ('D' == C) {
D--;
} else if ('L' == C) {
L++;
} else {
R--;
}
if ((U == D) || (L == R)) {
cout << "NO" << endl;
return 0;
}
}
if ((sr > U) && (sr <= D) && (sc > L) && (sc <= R)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
| [] | 869,763 | 869,764 | u216849520 | cpp |
p03054 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, j) for (int i = 0; i < j; i++)
#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;
typedef vector<pii> vpii;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;
int h, w, n, sr, sc;
string s, t;
cin >> h >> w >> n >> sr >> sc >> s >> t;
sr--;
sc--;
bool isok = true;
int left = 0, right = w;
if (s.back() == 'L')
left++;
if (s.back() == 'R')
right--;
for (int i = n - 2; i >= 0; i--) {
if (t[i] == 'L')
right = min(right + 1, w);
if (t[i] == 'R')
left = max(left - 1, 0);
if (s[i] == 'L')
left++;
if (s[i] == 'R')
right--;
if (left >= right)
isok = false;
}
if (!isok or sc < left or right <= sc) {
cout << "NO" << endl;
return 0;
}
left = 0, right = h;
if (s.back() == 'U')
left++;
if (s.back() == 'D')
right--;
for (int i = n - 2; i >= 0; i--) {
if (t[i] == 'U')
right = min(right + 1, h);
if (t[i] == 'D')
left = max(left - 1, 0);
if (s[i] == 'U')
left++;
if (s[i] == 'D')
right--;
if (left >= right)
isok = false;
}
if (!isok or sc < left or right <= sc) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, j) for (int i = 0; i < j; i++)
#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;
typedef vector<pii> vpii;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;
int h, w, n, sr, sc;
string s, t;
cin >> h >> w >> n >> sr >> sc >> s >> t;
sr--;
sc--;
bool isok = true;
int left = 0, right = w;
if (s.back() == 'L')
left++;
if (s.back() == 'R')
right--;
for (int i = n - 2; i >= 0; i--) {
if (t[i] == 'L')
right = min(right + 1, w);
if (t[i] == 'R')
left = max(left - 1, 0);
if (s[i] == 'L')
left++;
if (s[i] == 'R')
right--;
if (left >= right)
isok = false;
}
if (!isok or sc < left or right <= sc) {
cout << "NO" << endl;
return 0;
}
left = 0, right = h;
if (s.back() == 'U')
left++;
if (s.back() == 'D')
right--;
for (int i = n - 2; i >= 0; i--) {
if (t[i] == 'U')
right = min(right + 1, h);
if (t[i] == 'D')
left = max(left - 1, 0);
if (s[i] == 'U')
left++;
if (s[i] == 'D')
right--;
if (left >= right)
isok = false;
}
if (!isok or sr < left or right <= sr) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
return 0;
}
| [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 869,765 | 869,766 | u463697306 | cpp |
p03054 | #define _USE_MATH_DEFINES
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
int H;
int W;
int N;
cin >> H >> W >> N;
int sr;
int sc;
cin >> sr >> sc;
string S;
string T;
cin >> S;
cin >> T;
int right_remove = W + 1;
int left_remove = 0;
int up_remove = 0;
int down_remove = H + 1;
for (int i = N - 1; i >= 0; i--) {
if (right_remove == W + 1) {
if (S[i] == 'R') {
right_remove = W;
}
} else {
if (S[i] == 'R' && T[i] != 'L') {
right_remove--;
} else if (S[i] != 'R' && T[i] == 'L' && right_remove < W + 1) {
right_remove++;
}
}
if (left_remove == 0) {
if (S[i] == 'L') {
left_remove = 1;
}
} else {
if (S[i] == 'L' && T[i] != 'R') {
left_remove++;
} else if (S[i] != 'L' && T[i] == 'R' && left_remove > 0) {
left_remove--;
}
}
if (left_remove + 1 >= right_remove) {
break;
}
if (up_remove == 0) {
if (S[i] == 'U') {
up_remove = 1;
}
} else {
if (S[i] == 'U' && T[i] != 'D') {
up_remove++;
} else if (S[i] != 'U' && T[i] == 'D' && up_remove > 0) {
up_remove--;
}
}
if (down_remove == H + 1 && S[i] == 'D') {
down_remove = H;
} else {
if (S[i] == 'D' && T[i] != 'U') {
down_remove--;
} else if (S[i] != 'D' && T[i] == 'U' && down_remove < H + 1) {
down_remove++;
}
}
if (down_remove + 1 >= up_remove) {
break;
}
}
if (up_remove < sr && sr < down_remove && left_remove < sc &&
sc < right_remove) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
} | #define _USE_MATH_DEFINES
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
int H;
int W;
int N;
cin >> H >> W >> N;
int sr;
int sc;
cin >> sr >> sc;
string S;
string T;
cin >> S;
cin >> T;
int right_remove = W + 1;
int left_remove = 0;
int up_remove = 0;
int down_remove = H + 1;
for (int i = N - 1; i >= 0; i--) {
if (right_remove == W + 1) {
if (S[i] == 'R') {
right_remove = W;
}
} else {
if (S[i] == 'R' && T[i] != 'L') {
right_remove--;
} else if (S[i] != 'R' && T[i] == 'L' && right_remove < W + 1) {
right_remove++;
}
}
if (left_remove == 0) {
if (S[i] == 'L') {
left_remove = 1;
}
} else {
if (S[i] == 'L' && T[i] != 'R') {
left_remove++;
} else if (S[i] != 'L' && T[i] == 'R' && left_remove > 0) {
left_remove--;
}
}
if (left_remove + 1 >= right_remove) {
break;
}
if (up_remove == 0) {
if (S[i] == 'U') {
up_remove = 1;
}
} else {
if (S[i] == 'U' && T[i] != 'D') {
up_remove++;
} else if (S[i] != 'U' && T[i] == 'D' && up_remove > 0) {
up_remove--;
}
}
if (down_remove == H + 1 && S[i] == 'D') {
down_remove = H;
} else {
if (S[i] == 'D' && T[i] != 'U') {
down_remove--;
} else if (S[i] != 'D' && T[i] == 'U' && down_remove < H + 1) {
down_remove++;
}
}
if (up_remove + 1 >= down_remove) {
break;
}
}
if (up_remove < sr && sr < down_remove && left_remove < sc &&
sc < right_remove) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
} | [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 869,772 | 869,773 | u623349537 | cpp |
p03054 | #include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
signed main() {
int h, w, n;
cin >> h >> w >> n;
string s, t;
int sr, sc;
cin >> sr >> sc;
cin >> s >> t;
int fl = false;
string tak = "LRUD";
string aok = "RLDU";
for (int k = 0; k < 4; k++) {
int cr = sr, cc = sc;
for (int i = 0; i < n; i++) {
if (s[i] == tak[k]) {
if (s[i] == 'L') {
cc--;
}
if (s[i] == 'R') {
cc++;
}
if (s[i] == 'U') {
cr--;
}
if (s[i] == 'D') {
cr++;
}
if (cc < 0 || cc > w || cr < 0 || cr > h) {
cout << "NO" << endl;
return 0;
}
}
if (t[i] == aok[k]) {
if (t[i] == 'L' && cc >= 2) {
cc--;
}
if (t[i] == 'R' && cc <= w - 1) {
cc++;
}
if (t[i] == 'U' && cr >= 2) {
cr--;
}
if (t[i] == 'D' && cr <= h - 1) {
cr++;
}
}
}
}
cout << "YES" << endl;
return 0;
} | #include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
signed main() {
int h, w, n;
cin >> h >> w >> n;
string s, t;
int sr, sc;
cin >> sr >> sc;
cin >> s >> t;
int fl = false;
string tak = "LRUD";
string aok = "RLDU";
for (int k = 0; k < 4; k++) {
int cr = sr, cc = sc;
for (int i = 0; i < n; i++) {
if (s[i] == tak[k]) {
if (s[i] == 'L') {
cc--;
}
if (s[i] == 'R') {
cc++;
}
if (s[i] == 'U') {
cr--;
}
if (s[i] == 'D') {
cr++;
}
if (cc <= 0 || cc > w || cr <= 0 || cr > h) {
cout << "NO" << endl;
return 0;
}
}
if (t[i] == aok[k]) {
if (t[i] == 'L' && cc >= 2) {
cc--;
}
if (t[i] == 'R' && cc <= w - 1) {
cc++;
}
if (t[i] == 'U' && cr >= 2) {
cr--;
}
if (t[i] == 'D' && cr <= h - 1) {
cr++;
}
}
}
}
cout << "YES" << endl;
return 0;
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 869,780 | 869,781 | u335590796 | cpp |
p03054 | #include <bits/stdc++.h>
using namespace std;
int main() {
int H, W, N, sr, sc;
cin >> H >> W >> N;
cin >> sr >> sc;
string S, T;
cin >> S;
cin >> T;
bool awin = false;
int bwinl = 1;
int bwinr = W;
int bwinu = 1;
int bwind = H;
for (int i = N - 1; i >= 0; i--) {
if (T[i] == 'R')
bwinl = max(bwinl - 1, 1);
if (T[i] == 'L')
bwinl = min(bwinr + 1, W);
if (T[i] == 'U')
bwinl = min(bwind + 1, H);
if (T[i] == 'D')
bwinl = max(bwinu - 1, 1);
if (S[i] == 'R')
bwinr--;
if (S[i] == 'L')
bwinl++;
if (S[i] == 'U')
bwinu++;
if (S[i] == 'D')
bwind--;
if (bwinr < bwinl)
awin = true;
if (bwind < bwinu)
awin = true;
}
if (!awin && bwinl <= sc && sc <= bwinr && bwinu <= sr && sr <= bwind)
cout << "YES" << endl;
else
cout << "NO" << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int H, W, N, sr, sc;
cin >> H >> W >> N;
cin >> sr >> sc;
string S, T;
cin >> S;
cin >> T;
bool awin = false;
int bwinl = 1;
int bwinr = W;
int bwinu = 1;
int bwind = H;
for (int i = N - 1; i >= 0; i--) {
if (T[i] == 'R')
bwinl = max(bwinl - 1, 1);
if (T[i] == 'L')
bwinr = min(bwinr + 1, W);
if (T[i] == 'U')
bwind = min(bwind + 1, H);
if (T[i] == 'D')
bwinu = max(bwinu - 1, 1);
if (S[i] == 'R')
bwinr--;
if (S[i] == 'L')
bwinl++;
if (S[i] == 'U')
bwinu++;
if (S[i] == 'D')
bwind--;
if (bwinr < bwinl)
awin = true;
if (bwind < bwinu)
awin = true;
}
if (!awin && bwinl <= sc && sc <= bwinr && bwinu <= sr && sr <= bwind)
cout << "YES" << endl;
else
cout << "NO" << endl;
} | [
"assignment.variable.change",
"identifier.change"
] | 869,782 | 869,783 | u548834738 | cpp |
p03054 | #include <bits/stdc++.h>
using namespace std;
int main() {
int H, W, N, sr, sc;
cin >> H >> W >> N;
cin >> sr >> sc;
string S, T;
cin >> S;
cin >> T;
bool awin = false;
int bwinl = 1;
int bwinr = W;
int bwinu = 1;
int bwind = H;
for (int i = N - 1; i >= 0; i--) {
if (T[i] == 'R')
bwinl = max(bwinl - 1, 1);
if (T[i] == 'L')
bwinl = min(bwinr + 1, W);
if (T[i] == 'U')
bwinl = min(bwind + 1, H);
if (T[i] == 'D')
bwinl = max(bwinu - 1, 1);
if (S[i] == 'R')
bwinr--;
if (S[i] == 'L')
bwinl++;
if (S[i] == 'U')
bwinu++;
if (S[i] == 'D')
bwind--;
if (bwinr < bwinl)
awin = true;
if (bwind < bwinr)
awin = true;
}
if (!awin && bwinl <= sc && sc <= bwinr && bwinu <= sr && sr <= bwind)
cout << "YES" << endl;
else
cout << "NO" << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int H, W, N, sr, sc;
cin >> H >> W >> N;
cin >> sr >> sc;
string S, T;
cin >> S;
cin >> T;
bool awin = false;
int bwinl = 1;
int bwinr = W;
int bwinu = 1;
int bwind = H;
for (int i = N - 1; i >= 0; i--) {
if (T[i] == 'R')
bwinl = max(bwinl - 1, 1);
if (T[i] == 'L')
bwinr = min(bwinr + 1, W);
if (T[i] == 'U')
bwind = min(bwind + 1, H);
if (T[i] == 'D')
bwinu = max(bwinu - 1, 1);
if (S[i] == 'R')
bwinr--;
if (S[i] == 'L')
bwinl++;
if (S[i] == 'U')
bwinu++;
if (S[i] == 'D')
bwind--;
if (bwinr < bwinl)
awin = true;
if (bwind < bwinu)
awin = true;
}
if (!awin && bwinl <= sc && sc <= bwinr && bwinu <= sr && sr <= bwind)
cout << "YES" << endl;
else
cout << "NO" << endl;
} | [
"assignment.variable.change",
"identifier.change",
"control_flow.branch.if.condition.change"
] | 869,784 | 869,783 | u548834738 | cpp |
p03054 | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string.h>
#include <unordered_map>
#include <vector>
using namespace std;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
const ll INF = 1e9;
const ll MOD = 1000000007; // 1e9 + 7
int main(int argc, char **argv) {
int H, W, N;
cin >> H >> W >> N;
int sr, sc;
cin >> sr >> sc;
--sr;
--sc;
string S, T;
cin >> S;
cin >> T;
// At first, check left-right.
int left = 0,
right = W - 1; // If piece is in [left, right] before the step, it is ok.
if (S[N - 1] == 'L') {
++left;
} // shrink
if (S[N - 1] == 'R') {
--right;
} // shrink
// W >= 2, so it is ok here.
for (int i = N - 2; i >= 0; --i) {
if (T[i] == 'L') {
right = min(right + 1, W);
} // expand
if (T[i] == 'R') {
left = max(left - 1, 0);
} // expand
if (S[i] == 'L') {
++left;
} // shrink
if (S[i] == 'R') {
--right;
} // shrink
if (left > right) { // Bad
cout << "NO" << endl;
return 0;
}
}
if (sc < left || right < sc) { // Bad
cout << "NO" << endl;
return 0;
}
// Next, check up-down.
int up = 0,
down = H - 1; // If piece is in [up, down] before the step, it is ok.
if (S[N - 1] == 'U') {
++up;
} // shrink
if (S[N - 1] == 'D') {
--down;
} // shrink
// W >= 2, so it is ok here.
for (int i = N - 2; i >= 0; --i) {
if (T[i] == 'U') {
down = min(down + 1, W);
} // expand
if (T[i] == 'D') {
up = max(up - 1, 0);
} // expand
if (S[i] == 'U') {
++up;
} // shrink
if (S[i] == 'D') {
--down;
} // shrink
if (up > down) { // Bad
cout << "NO" << endl;
return 0;
}
}
if (sr < up || down < sr) { // Bad
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string.h>
#include <unordered_map>
#include <vector>
using namespace std;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
const ll INF = 1e9;
const ll MOD = 1000000007; // 1e9 + 7
int main(int argc, char **argv) {
int H, W, N;
cin >> H >> W >> N;
int sr, sc;
cin >> sr >> sc;
--sr;
--sc;
string S, T;
cin >> S;
cin >> T;
// At first, check left-right.
int left = 0,
right = W - 1; // If piece is in [left, right] before the step, it is ok.
if (S[N - 1] == 'L') {
++left;
} // shrink
if (S[N - 1] == 'R') {
--right;
} // shrink
// W >= 2, so it is ok here.
for (int i = N - 2; i >= 0; --i) {
if (T[i] == 'L') {
right = min(right + 1, W - 1);
} // expand
if (T[i] == 'R') {
left = max(left - 1, 0);
} // expand
if (S[i] == 'L') {
++left;
} // shrink
if (S[i] == 'R') {
--right;
} // shrink
if (left > right) { // Bad
cout << "NO" << endl;
return 0;
}
}
if (sc < left || right < sc) { // Bad
cout << "NO" << endl;
return 0;
}
// Next, check up-down.
int up = 0,
down = H - 1; // If piece is in [up, down] before the step, it is ok.
if (S[N - 1] == 'U') {
++up;
} // shrink
if (S[N - 1] == 'D') {
--down;
} // shrink
// W >= 2, so it is ok here.
for (int i = N - 2; i >= 0; --i) {
if (T[i] == 'U') {
down = min(down + 1, H - 1);
} // expand
if (T[i] == 'D') {
up = max(up - 1, 0);
} // expand
if (S[i] == 'U') {
++up;
} // shrink
if (S[i] == 'D') {
--down;
} // shrink
if (up > down) { // Bad
cout << "NO" << endl;
return 0;
}
}
if (sr < up || down < sr) { // Bad
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
}
| [
"assignment.change",
"assignment.value.change",
"call.arguments.change"
] | 869,785 | 869,786 | u328294851 | cpp |
p03054 | #include <bits/stdc++.h>
using namespace std;
struct Benri {
Benri() {
std::cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
}
} benri;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
constexpr long long MOD = 1000000007;
// constexpr long long MOD = 998244353;
constexpr double EPS = 1e-10;
constexpr int INF = 1001001001;
// constexpr ll INF = 1001001001001001001ll;
int H, W, N;
int ix, iy;
string S, T;
bool solve() {
// left, right
int left = 0, right = W;
if (S[N - 1] == 'L')
++left;
if (S[N - 1] == 'R')
--right;
for (int i = N - 2; i >= 0; --i) {
if (T[i] == 'L')
right = min(right + 1, W);
else if (T[i] == 'R')
left = max(0, left - 1);
if (S[i] == 'L')
left = left + 1;
else if (S[i] == 'R')
right = right - 1;
if (left >= right)
return false;
}
if (iy < left || iy >= right)
return false;
// up, down
left = 0, right = H;
if (S[N - 1] == 'U')
++left;
if (S[N - 1] == 'D')
--right;
for (int i = N - 2; i >= 0; --i) {
if (T[i] == 'U')
right = min(right + 1, H);
else if (T[i] == 'D')
left = max(0, left - 1);
if (S[i] == 'U')
left = left + 1;
else if (S[i] == 'D')
right = right - 1;
if (left >= right)
return false;
}
if (ix < left || ix >= right)
return false;
return true;
}
int main() {
while (cin >> H >> W >> N >> ix >> iy >> S >> T) {
--ix, --iy;
cout << (solve() ? "Yes" : "No") << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
struct Benri {
Benri() {
std::cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
}
} benri;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
constexpr long long MOD = 1000000007;
// constexpr long long MOD = 998244353;
constexpr double EPS = 1e-10;
constexpr int INF = 1001001001;
// constexpr ll INF = 1001001001001001001ll;
int H, W, N;
int ix, iy;
string S, T;
bool solve() {
// left, right
int left = 0, right = W;
if (S[N - 1] == 'L')
++left;
if (S[N - 1] == 'R')
--right;
for (int i = N - 2; i >= 0; --i) {
if (T[i] == 'L')
right = min(right + 1, W);
else if (T[i] == 'R')
left = max(0, left - 1);
if (S[i] == 'L')
left = left + 1;
else if (S[i] == 'R')
right = right - 1;
if (left >= right)
return false;
}
if (iy < left || iy >= right)
return false;
// up, down
left = 0, right = H;
if (S[N - 1] == 'U')
++left;
if (S[N - 1] == 'D')
--right;
for (int i = N - 2; i >= 0; --i) {
if (T[i] == 'U')
right = min(right + 1, H);
else if (T[i] == 'D')
left = max(0, left - 1);
if (S[i] == 'U')
left = left + 1;
else if (S[i] == 'D')
right = right - 1;
if (left >= right)
return false;
}
if (ix < left || ix >= right)
return false;
return true;
}
int main() {
while (cin >> H >> W >> N >> ix >> iy >> S >> T) {
--ix, --iy;
cout << (solve() ? "YES" : "NO") << endl;
}
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 869,787 | 869,788 | u073486874 | cpp |
p03054 | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define repl(i, s, n) for (int i = s; i <= n; ++i)
#define rer(i, l, u) for (int(i) = (int)(l); (i) <= (int)(u); ++(i))
#define reu(i, l, u) for (int(i) = (int)(l); (i) < (int)(u); ++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r, v) auto r = (v)
#else
#define aut(r, v) __typeof(v) r = (v)
#endif
#define each(it, o) for (aut(it, (o).begin()); it != (o).end(); ++it)
#define ktya(x) sort(all(x))
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair((x), (y))
#define mset(m, v) memset(m, v, sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a, b) (a > b ? b : a)
#define maxd(a, b) (a > b ? a : b)
#define PI (acos(-1))
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
typedef long long ll;
typedef pair<int, ll> pill;
typedef pair<ll, int> plli;
typedef pair<double, int> pdi;
template <typename T, typename U> inline void amin(T &x, U y) {
if (y < x)
x = y;
}
template <typename T, typename U> inline void amax(T &x, U y) {
if (x < y)
x = y;
}
typedef complex<double> P;
// ll MOD = 1000000007;
ll MOD = 998244353;
typedef ll Weight;
struct Edge {
int src, dst;
Weight weight;
};
bool operator<(const Edge &e, const Edge &f) {
return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
e.src != f.src ? e.src < f.src
: e.dst < f.dst;
}
typedef vector<Edge> Edges;
vector<pair<ll, pii>> data;
int H, W, N;
int p1[2][214514] = {0};
int p2[2][214514] = {0};
int memor, memol;
bool calc(int dir, int memo, int st) {
bool flag = true;
int lef = -1, rig = memo;
for (int i = N - 1; i >= 0; i--) {
if (p2[dir][i] > 0) {
lef = max(-1, lef - 1);
} else if (p2[dir][i] < 0) {
rig = min(N, rig + 1);
}
if (p1[dir][i] > 0) {
rig -= 1;
} else if (p1[dir][i] < 0) {
lef += 1;
}
// cout<<lef<<" "<<rig<<endl;
if (lef == N)
flag = false;
if (rig == -1)
flag = false;
if (rig - lef <= 1)
flag = false;
}
if (rig <= st)
flag = false;
if (lef >= st)
flag = false;
// cout<<lef<<" "<<rig<<endl;
return flag;
}
int main() {
cin >> H >> W >> N;
int stx, sty;
cin >> stx >> sty;
stx--;
sty--;
string ta, ao;
cin >> ta >> ao;
for (int i = N - 1; i >= 0; i--) {
if (ta[i] == 'U')
p1[0][i] = 1;
if (ta[i] == 'D')
p1[0][i] = -1;
if (ta[i] == 'R')
p1[1][i] = 1;
if (ta[i] == 'L')
p1[1][i] = -1;
if (ao[i] == 'U')
p2[0][i] = 1;
if (ao[i] == 'D')
p2[0][i] = -1;
if (ao[i] == 'R')
p2[1][i] = 1;
if (ao[i] == 'L')
p2[1][i] = -1;
}
// calc(0,H,stx);
// calc(1,W,sty);
if (calc(0, H, stx) && calc(1, W, sty))
cout << "YES" << endl;
else
cout << "NO" << endl;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define repl(i, s, n) for (int i = s; i <= n; ++i)
#define rer(i, l, u) for (int(i) = (int)(l); (i) <= (int)(u); ++(i))
#define reu(i, l, u) for (int(i) = (int)(l); (i) < (int)(u); ++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r, v) auto r = (v)
#else
#define aut(r, v) __typeof(v) r = (v)
#endif
#define each(it, o) for (aut(it, (o).begin()); it != (o).end(); ++it)
#define ktya(x) sort(all(x))
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair((x), (y))
#define mset(m, v) memset(m, v, sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a, b) (a > b ? b : a)
#define maxd(a, b) (a > b ? a : b)
#define PI (acos(-1))
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
typedef long long ll;
typedef pair<int, ll> pill;
typedef pair<ll, int> plli;
typedef pair<double, int> pdi;
template <typename T, typename U> inline void amin(T &x, U y) {
if (y < x)
x = y;
}
template <typename T, typename U> inline void amax(T &x, U y) {
if (x < y)
x = y;
}
typedef complex<double> P;
// ll MOD = 1000000007;
ll MOD = 998244353;
typedef ll Weight;
struct Edge {
int src, dst;
Weight weight;
};
bool operator<(const Edge &e, const Edge &f) {
return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
e.src != f.src ? e.src < f.src
: e.dst < f.dst;
}
typedef vector<Edge> Edges;
vector<pair<ll, pii>> data;
int H, W, N;
int p1[2][214514] = {0};
int p2[2][214514] = {0};
int memor, memol;
bool calc(int dir, int memo, int st) {
bool flag = true;
int lef = -1, rig = memo;
for (int i = N - 1; i >= 0; i--) {
if (p2[dir][i] > 0) {
lef = max(-1, lef - 1);
} else if (p2[dir][i] < 0) {
rig = min(memo, rig + 1);
}
if (p1[dir][i] > 0) {
rig -= 1;
} else if (p1[dir][i] < 0) {
lef += 1;
}
// cout<<lef<<" "<<rig<<endl;
if (lef == N)
flag = false;
if (rig == -1)
flag = false;
if (rig - lef <= 1)
flag = false;
}
if (rig <= st)
flag = false;
if (lef >= st)
flag = false;
// cout<<lef<<" "<<rig<<endl;
return flag;
}
int main() {
cin >> H >> W >> N;
int stx, sty;
cin >> stx >> sty;
stx--;
sty--;
string ta, ao;
cin >> ta >> ao;
for (int i = N - 1; i >= 0; i--) {
if (ta[i] == 'U')
p1[0][i] = -1;
if (ta[i] == 'D')
p1[0][i] = 1;
if (ta[i] == 'R')
p1[1][i] = 1;
if (ta[i] == 'L')
p1[1][i] = -1;
if (ao[i] == 'U')
p2[0][i] = -1;
if (ao[i] == 'D')
p2[0][i] = 1;
if (ao[i] == 'R')
p2[1][i] = 1;
if (ao[i] == 'L')
p2[1][i] = -1;
}
// calc(0,H,stx);
// calc(1,W,sty);
if (calc(0, H, stx) && calc(1, W, sty))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
| [
"assignment.value.change",
"identifier.change",
"call.arguments.change",
"expression.operation.unary.arithmetic.add",
"expression.operation.unary.arithmetic.remove"
] | 869,807 | 869,806 | u703999673 | cpp |
p03054 | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
#define go(u) for (int i = head[u], v = e[i].to; i; i = e[i].lst, v = e[i].to)
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = (x << 3) + (x << 1) + ch - 48;
ch = getchar();
}
return x * f;
}
template <typename T> inline bool Max(T &a, T b) {
return a < b ? a = b, 1 : 0;
}
template <typename T> inline bool Min(T &a, T b) {
return a > b ? a = b, 1 : 0;
}
const int N = 2e5 + 7;
int H, W, n, r, c;
char foo[N], bar[N];
bool solve(int R, int s, char add, char sub) {
int l = 1, r = R;
for (int i = n; i; --i) {
if (bar[i] == add)
--l;
if (bar[i] == sub)
++r;
Max(l, 1);
Min(r, n);
if (foo[i] == add)
--r;
if (foo[i] == sub)
++l;
if (l > r)
return 0;
}
return l <= s && s <= r;
}
int main() {
#ifdef fwat
#endif
H = gi(), W = gi(), n = gi();
r = gi(), c = gi();
scanf("%s%s", foo + 1, bar + 1);
puts(solve(H, r, 'D', 'U') && solve(W, c, 'R', 'L') ? "YES" : "NO");
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
#define go(u) for (int i = head[u], v = e[i].to; i; i = e[i].lst, v = e[i].to)
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = (x << 3) + (x << 1) + ch - 48;
ch = getchar();
}
return x * f;
}
template <typename T> inline bool Max(T &a, T b) {
return a < b ? a = b, 1 : 0;
}
template <typename T> inline bool Min(T &a, T b) {
return a > b ? a = b, 1 : 0;
}
const int N = 2e5 + 7;
int H, W, n, r, c;
char foo[N], bar[N];
bool solve(int R, int s, char add, char sub) {
int l = 1, r = R;
for (int i = n; i; --i) {
if (bar[i] == add)
--l;
if (bar[i] == sub)
++r;
Max(l, 1);
Min(r, R);
if (foo[i] == add)
--r;
if (foo[i] == sub)
++l;
if (l > r)
return 0;
}
return l <= s && s <= r;
}
int main() {
#ifdef fwat
#endif
H = gi(), W = gi(), n = gi();
r = gi(), c = gi();
scanf("%s%s", foo + 1, bar + 1);
puts(solve(H, r, 'D', 'U') && solve(W, c, 'R', 'L') ? "YES" : "NO");
return 0;
} | [
"identifier.change",
"call.arguments.change"
] | 869,822 | 869,823 | u543414214 | cpp |
p03054 | #include <bits/stdc++.h>
#define pb push_back
#define FOR(x, to) for (int x = 0; x < (to); x++)
#define F0R(x, in, to) for (int x = (in); x < (to); x++)
#define FORR(x, arr) for (auto &x : arr)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
typedef long long ll;
using namespace std;
ll MOD = 998244353;
typedef pair<int, int> ii;
typedef struct {
int a, b, c;
} iii;
typedef vector<int> vi;
void mosA(vector<int> a) {
for (int i = 0; i < a.size(); i++)
printf("%d ", a[i]);
printf("\n");
}
void mosP(vector<ii> a) {
for (int i = 0; i < a.size(); i++)
printf("%d %d\n", a[i].first, a[i].second);
printf("\n");
}
ll min_especial(ll a, ll b) {
if (a != -1 && b != -1)
return min(a, b);
else
return max(a, b);
}
/*
bool ord(ii a, ii b){
if(a.first == b.first){
return a.second < b.second;
}
return a.first < b.first;
}*/
bool ord(ll a, ll b) { return a > b; }
int ans = 0;
int a, n, nn, w, t, k, m, z, q, l, r, x, b, y;
char A[200005], B[200005];
int main() {
scanf("%d%d%d", &n, &m, &nn);
int f, c;
scanf("%d%d", &f, &c);
scanf(" %s %s", A, B);
for (int i = 0, cont = c; i < nn; i++) {
if (A[i] == 'R')
cont++;
if (cont > m)
return !printf("NO");
if (B[i] == 'L')
cont = max(0, cont - 1);
}
for (int i = 0, cont = c; i < nn; i++) {
if (A[i] == 'L')
cont--;
if (cont < 1)
return !printf("NO");
if (B[i] == 'R')
cont = min(m, cont + 1);
}
for (int i = 0, cont = f; i < nn; i++) {
if (A[i] == 'U')
cont--;
if (cont < 1)
return !printf("NO");
if (B[i] == 'D')
cont = min(n, cont + 1);
}
for (int i = 0, cont = f; i < nn; i++) {
if (A[i] == 'D')
cont++;
if (cont > n)
return !printf("NO");
if (B[i] == 'U')
cont = max(0, cont - 1);
}
return !printf("YES");
}
// REVISATE ESTO:
// - memset(A,-1,SIZEOF()*n)
// - (x-y+MOD)%MOD
// - int o ll? | #include <bits/stdc++.h>
#define pb push_back
#define FOR(x, to) for (int x = 0; x < (to); x++)
#define F0R(x, in, to) for (int x = (in); x < (to); x++)
#define FORR(x, arr) for (auto &x : arr)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
typedef long long ll;
using namespace std;
ll MOD = 998244353;
typedef pair<int, int> ii;
typedef struct {
int a, b, c;
} iii;
typedef vector<int> vi;
void mosA(vector<int> a) {
for (int i = 0; i < a.size(); i++)
printf("%d ", a[i]);
printf("\n");
}
void mosP(vector<ii> a) {
for (int i = 0; i < a.size(); i++)
printf("%d %d\n", a[i].first, a[i].second);
printf("\n");
}
ll min_especial(ll a, ll b) {
if (a != -1 && b != -1)
return min(a, b);
else
return max(a, b);
}
/*
bool ord(ii a, ii b){
if(a.first == b.first){
return a.second < b.second;
}
return a.first < b.first;
}*/
bool ord(ll a, ll b) { return a > b; }
int ans = 0;
int a, n, nn, w, t, k, m, z, q, l, r, x, b, y;
char A[200005], B[200005];
int main() {
scanf("%d%d%d", &n, &m, &nn);
int f, c;
scanf("%d%d", &f, &c);
scanf(" %s %s", A, B);
for (int i = 0, cont = c; i < nn; i++) {
if (A[i] == 'R')
cont++;
// cout<<cont<<endl;
if (cont > m)
return !printf("NO");
if (B[i] == 'L')
cont = max(1, cont - 1);
}
for (int i = 0, cont = c; i < nn; i++) {
if (A[i] == 'L')
cont--;
if (cont < 1)
return !printf("NO");
if (B[i] == 'R')
cont = min(m, cont + 1);
}
for (int i = 0, cont = f; i < nn; i++) {
if (A[i] == 'U')
cont--;
if (cont < 1)
return !printf("NO");
if (B[i] == 'D')
cont = min(n, cont + 1);
}
for (int i = 0, cont = f; i < nn; i++) {
if (A[i] == 'D')
cont++;
if (cont > n)
return !printf("NO");
if (B[i] == 'U')
cont = max(1, cont - 1);
}
return !printf("YES");
}
// REVISATE ESTO:
// - memset(A,-1,SIZEOF()*n)
// - (x-y+MOD)%MOD
// - int o ll? | [
"literal.number.change",
"assignment.value.change",
"call.arguments.change"
] | 869,840 | 869,841 | u204082108 | cpp |
p03054 | #include <bits/stdc++.h>
#define pb push_back
#define FOR(x, to) for (int x = 0; x < (to); x++)
#define F0R(x, in, to) for (int x = (in); x < (to); x++)
#define FORR(x, arr) for (auto &x : arr)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
typedef long long ll;
using namespace std;
ll MOD = 998244353;
typedef pair<int, int> ii;
typedef struct {
int a, b, c;
} iii;
typedef vector<int> vi;
void mosA(vector<int> a) {
for (int i = 0; i < a.size(); i++)
printf("%d ", a[i]);
printf("\n");
}
void mosP(vector<ii> a) {
for (int i = 0; i < a.size(); i++)
printf("%d %d\n", a[i].first, a[i].second);
printf("\n");
}
ll min_especial(ll a, ll b) {
if (a != -1 && b != -1)
return min(a, b);
else
return max(a, b);
}
/*
bool ord(ii a, ii b){
if(a.first == b.first){
return a.second < b.second;
}
return a.first < b.first;
}*/
bool ord(ll a, ll b) { return a > b; }
int ans = 0;
int a, n, nn, w, t, k, m, z, q, l, r, x, b, y;
char A[200005], B[200005];
int main() {
scanf("%d%d%d", &n, &m, &nn);
int f, c;
scanf("%d%d", &f, &c);
scanf(" %s %s", A, B);
for (int i = 0, cont = c; i < nn; i++) {
if (A[i] == 'R')
cont++;
if (cont > m)
return !printf("NO");
if (B[i] == 'L')
cont = max(0, cont - 1);
}
for (int i = 0, cont = c; i < nn; i++) {
if (A[i] == 'L')
cont--;
if (cont < 1)
return !printf("NO");
if (B[i] == 'R')
cont = min(m, cont + 1);
}
for (int i = 0, cont = f; i < nn; i++) {
if (A[i] == 'U')
cont--;
if (cont < 1)
return !printf("NO");
if (B[i] == 'D')
cont = min(m, cont + 1);
}
for (int i = 0, cont = f; i < nn; i++) {
if (A[i] == 'D')
cont++;
if (cont > n)
return !printf("NO");
if (B[i] == 'U')
cont = max(0, cont - 1);
}
return !printf("YES");
}
// REVISATE ESTO:
// - memset(A,-1,SIZEOF()*n)
// - (x-y+MOD)%MOD
// - int o ll? | #include <bits/stdc++.h>
#define pb push_back
#define FOR(x, to) for (int x = 0; x < (to); x++)
#define F0R(x, in, to) for (int x = (in); x < (to); x++)
#define FORR(x, arr) for (auto &x : arr)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
typedef long long ll;
using namespace std;
ll MOD = 998244353;
typedef pair<int, int> ii;
typedef struct {
int a, b, c;
} iii;
typedef vector<int> vi;
void mosA(vector<int> a) {
for (int i = 0; i < a.size(); i++)
printf("%d ", a[i]);
printf("\n");
}
void mosP(vector<ii> a) {
for (int i = 0; i < a.size(); i++)
printf("%d %d\n", a[i].first, a[i].second);
printf("\n");
}
ll min_especial(ll a, ll b) {
if (a != -1 && b != -1)
return min(a, b);
else
return max(a, b);
}
/*
bool ord(ii a, ii b){
if(a.first == b.first){
return a.second < b.second;
}
return a.first < b.first;
}*/
bool ord(ll a, ll b) { return a > b; }
int ans = 0;
int a, n, nn, w, t, k, m, z, q, l, r, x, b, y;
char A[200005], B[200005];
int main() {
scanf("%d%d%d", &n, &m, &nn);
int f, c;
scanf("%d%d", &f, &c);
scanf(" %s %s", A, B);
for (int i = 0, cont = c; i < nn; i++) {
if (A[i] == 'R')
cont++;
// cout<<cont<<endl;
if (cont > m)
return !printf("NO");
if (B[i] == 'L')
cont = max(1, cont - 1);
}
for (int i = 0, cont = c; i < nn; i++) {
if (A[i] == 'L')
cont--;
if (cont < 1)
return !printf("NO");
if (B[i] == 'R')
cont = min(m, cont + 1);
}
for (int i = 0, cont = f; i < nn; i++) {
if (A[i] == 'U')
cont--;
if (cont < 1)
return !printf("NO");
if (B[i] == 'D')
cont = min(n, cont + 1);
}
for (int i = 0, cont = f; i < nn; i++) {
if (A[i] == 'D')
cont++;
if (cont > n)
return !printf("NO");
if (B[i] == 'U')
cont = max(1, cont - 1);
}
return !printf("YES");
}
// REVISATE ESTO:
// - memset(A,-1,SIZEOF()*n)
// - (x-y+MOD)%MOD
// - int o ll? | [
"literal.number.change",
"assignment.value.change",
"call.arguments.change",
"identifier.change"
] | 869,842 | 869,841 | u204082108 | cpp |
p03054 | #include <iomanip>
#include <iostream>
//#include<cstdio>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
int H, W, N;
int Sr, Sc;
string S, T;
int main() {
cin >> H >> W >> N;
cin >> Sr >> Sc;
cin >> S >> T;
int xmin = 1, xmax = H;
int ymin = 1, ymax = W;
for (int i = N - 1; i >= 0; i--) {
if (T[i] == 'U')
xmax = min(H, xmax + 1);
else if (T[i] == 'D')
xmin = max(1, xmin - 1);
if (T[i] == 'L')
ymax = min(W, ymax + 1);
else if (T[i] == 'R')
ymin = max(1, ymin - 1);
// cout << xmin << " " << xmax << " " << ymin << " " << ymax << endl;
if (S[i] == 'U')
xmin++;
else if (S[i] == 'D')
xmax--;
if (S[i] == 'L')
ymin++;
else if (S[i] == 'R')
ymax--;
// cout << xmin << " " << xmax << " " << ymin << " " << ymax << endl;
if (xmin > xmax || ymin > ymax) {
cout << "NO" << endl;
return 0;
}
}
if (xmin <= Sr && Sr <= xmax && ymin <= Sc && Sc <= ymin)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
} | #include <iomanip>
#include <iostream>
//#include<cstdio>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
int H, W, N;
int Sr, Sc;
string S, T;
int main() {
cin >> H >> W >> N;
cin >> Sr >> Sc;
cin >> S >> T;
int xmin = 1, xmax = H;
int ymin = 1, ymax = W;
for (int i = N - 1; i >= 0; i--) {
if (T[i] == 'U')
xmax = min(H, xmax + 1);
else if (T[i] == 'D')
xmin = max(1, xmin - 1);
if (T[i] == 'L')
ymax = min(W, ymax + 1);
else if (T[i] == 'R')
ymin = max(1, ymin - 1);
// cout << xmin << " " << xmax << " " << ymin << " " << ymax << endl;
if (S[i] == 'U')
xmin++;
else if (S[i] == 'D')
xmax--;
if (S[i] == 'L')
ymin++;
else if (S[i] == 'R')
ymax--;
// cout << xmin << " " << xmax << " " << ymin << " " << ymax << endl;
if (xmin > xmax || ymin > ymax) {
cout << "NO" << endl;
return 0;
}
}
if (xmin <= Sr && Sr <= xmax && ymin <= Sc && Sc <= ymax)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
} | [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 869,845 | 869,846 | u534998883 | cpp |
p03054 | #include <cstdio>
#include <string>
using namespace std;
int main() {
int H, W, N, sr, sc;
int i;
scanf("%d %d %d", &H, &W, &N);
char *s = new char[N];
char *t = new char[N];
scanf(" %d %d", &sr, &sc);
scanf(" %s", s);
scanf(" %s", t);
//高橋君が最も移動させられる距離が分かればよい
int L = 0, R = 0, U = 0, D = 0;
for (
i = 0; i < N;
i++) { //高橋君の可能な最大移動量を求める(負のときは青木君が可能な最大移動量になる)
if (s[i] == 'L')
L++;
if (s[i] == 'R')
R++;
if (s[i] == 'U')
U++;
if (s[i] == 'D')
D++;
if (L >= sc || R > H - sc || U >= sr ||
D > W - sr) { //盤面から出すことが可能ならNO
printf("NO");
return 0;
}
if (t[i] == 'L' && sc + R > 1)
R--;
if (t[i] == 'R' && sc - L < H)
L--;
if (t[i] == 'U' && sr + D > 1)
D--;
if (t[i] == 'D' && sr - U < H)
U--;
}
printf("YES");
delete[] s, t;
return 0;
} | #include <cstdio>
#include <string>
using namespace std;
int main() {
int H, W, N, sr, sc;
int i;
scanf("%d %d %d", &H, &W, &N);
char *s = new char[N];
char *t = new char[N];
scanf(" %d %d", &sr, &sc);
scanf(" %s", s);
scanf(" %s", t);
//高橋君が最も移動させられる距離が分かればよい
int L = 0, R = 0, U = 0, D = 0;
for (
i = 0; i < N;
i++) { //高橋君の可能な最大移動量を求める(負のときは青木君が可能な最大移動量になる)
if (s[i] == 'L')
L++;
if (s[i] == 'R')
R++;
if (s[i] == 'U')
U++;
if (s[i] == 'D')
D++;
if (L >= sc || R > W - sc || U >= sr ||
D > H - sr) { //盤面から出すことが可能ならNO
printf("NO");
return 0;
}
if (t[i] == 'L' && sc + R > 1)
R--;
if (t[i] == 'R' && sc - L < H)
L--;
if (t[i] == 'U' && sr + D > 1)
D--;
if (t[i] == 'D' && sr - U < H)
U--;
}
printf("YES");
delete[] s, t;
return 0;
} | [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 869,875 | 869,876 | u203033720 | cpp |
p03054 | #include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
bool judge(vector<int> w_dir, vector<int> w_who, int w, int start) {
int L = 1, R = w;
for (int i = w_dir.size() - 1; i >= 0; i--) {
if (w_who[i] == 1) {
if (w_dir[i] == 1) {
R--;
} else {
L++;
}
} else {
if (w_dir[i] == 1) {
L = max(L - 1, 1);
} else {
R = min(R + 1, w);
}
}
if (R < L) {
return false;
}
}
if (start >= L && start <= R) {
return true;
} else {
return false;
}
}
int main() {
int h, w, n;
cin >> h >> w >> n;
int s_r, s_c;
string S, T;
cin >> s_r >> s_c >> S >> T;
vector<int> w_dir, w_who, h_dir, h_who;
for (int i = 0; i < n; i++) {
switch (S[i]) {
case 'U':
h_dir.push_back(-1);
h_who.push_back(1);
break;
case 'D':
h_dir.push_back(1);
h_who.push_back(1);
break;
case 'L':
w_dir.push_back(-1);
w_who.push_back(1);
break;
case 'R':
w_dir.push_back(1);
w_who.push_back(1);
break;
default:;
}
switch (T[i]) {
case 'U':
h_dir.push_back(-1);
h_who.push_back(0);
break;
case 'D':
h_dir.push_back(1);
h_who.push_back(0);
break;
case 'L':
w_dir.push_back(-1);
w_who.push_back(0);
break;
case 'R':
w_dir.push_back(1);
w_who.push_back(0);
break;
default:;
}
}
if (judge(w_dir, w_who, w, s_c) && judge(h_dir, h_who, h, s_r)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
| #include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
bool judge(vector<int> w_dir, vector<int> w_who, int w, int start) {
int L = 1, R = w;
for (int i = w_dir.size() - 1; i >= 0; i--) {
if (w_who[i] == 1) {
if (w_dir[i] == 1) {
R--;
} else {
L++;
}
} else {
if (w_dir[i] == 1) {
L = max(L - 1, 1);
} else {
R = min(R + 1, w);
}
}
if (R < L) {
return false;
}
}
if (start >= L && start <= R) {
return true;
} else {
return false;
}
}
int main() {
int h, w, n;
cin >> h >> w >> n;
int s_r, s_c;
string S, T;
cin >> s_r >> s_c >> S >> T;
vector<int> w_dir, w_who, h_dir, h_who;
for (int i = 0; i < n; i++) {
switch (S[i]) {
case 'U':
h_dir.push_back(-1);
h_who.push_back(1);
break;
case 'D':
h_dir.push_back(1);
h_who.push_back(1);
break;
case 'L':
w_dir.push_back(-1);
w_who.push_back(1);
break;
case 'R':
w_dir.push_back(1);
w_who.push_back(1);
break;
default:;
}
switch (T[i]) {
case 'U':
h_dir.push_back(-1);
h_who.push_back(0);
break;
case 'D':
h_dir.push_back(1);
h_who.push_back(0);
break;
case 'L':
w_dir.push_back(-1);
w_who.push_back(0);
break;
case 'R':
w_dir.push_back(1);
w_who.push_back(0);
break;
default:;
}
}
if (judge(w_dir, w_who, w, s_c) && judge(h_dir, h_who, h, s_r)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
| [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 869,879 | 869,880 | u766009355 | cpp |
p03054 | #include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define rep(i, x, y) \
for (i64 i = i64(x), i##_max_for_repmacro = i64(y); \
i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T, size_t size> void fill(T (&ary)[size], const T &val) {
fill_n((T *)ary, size, val);
}
void solve() {
// const i64 mod = 1'000'000'007;
i64 H, W, N;
cin >> H >> W >> N;
i64 sr, sc;
cin >> sr >> sc;
--sr;
--sc;
string S, T;
cin >> S >> T;
vector<vector<i64>> l(2, vector<i64>(N)), r(2, vector<i64>(N)),
u(2, vector<i64>(N)), d(2, vector<i64>(N));
/*
{
if(S[0]=='L') ++l[0][0];
else if(S[0]=='R') ++r[0][0];
else if(S[0]=='U') ++u[0][0];
else ++d[0][0];
rep(i,1,N){
l[0][i]=l[0][i-1];
r[0][i]=r[0][i-1];
u[0][i]=u[0][i-1];
d[0][i]=d[0][i-1];
if(S[i]=='L') ++l[0][i];
else if(S[i]=='R') ++r[0][i];
else if(S[i]=='U') ++u[0][i];
else ++d[0][i];
}
}
{
if(T[0]=='L') ++l[1][0];
else if(T[0]=='R') ++r[1][0];
else if(T[0]=='U') ++u[1][0];
else ++d[1][0];
rep(i,1,N){
l[1][i]=l[1][i-1];
r[1][i]=r[1][i-1];
u[1][i]=u[1][i-1];
d[1][i]=d[1][i-1];
if(T[i]=='L') ++l[1][i];
else if(T[i]=='R') ++r[1][i];
else if(T[i]=='U') ++u[1][i];
else ++d[1][i];
}
}
*/
{
if (S[N - 1] == 'L')
++l[0][N - 1];
else if (S[N - 1] == 'R')
++r[0][N - 1];
else if (S[N - 1] == 'U')
++u[0][N - 1];
else
++d[0][N - 1];
for (i64 i = N - 2; i >= 0; --i) {
l[0][i] = l[0][i + 1];
r[0][i] = r[0][i + 1];
u[0][i] = u[0][i + 1];
d[0][i] = d[0][i + 1];
if (S[i] == 'L')
++l[0][i];
else if (S[i] == 'R')
++r[0][i];
else if (S[i] == 'U')
++u[0][i];
else
++d[0][i];
}
}
{
if (T[N - 1] == 'L')
++l[1][N - 1];
else if (T[N - 1] == 'R')
++r[1][N - 1];
else if (T[N - 1] == 'U')
++u[1][N - 1];
else
++d[1][N - 1];
for (i64 i = N - 2; i >= 0; --i) {
l[1][i] = l[1][i + 1];
r[1][i] = r[1][i + 1];
u[1][i] = u[1][i + 1];
d[1][i] = d[1][i + 1];
if (T[i] == 'L')
++l[1][i];
else if (T[i] == 'R')
++r[1][i];
else if (T[i] == 'U')
++u[1][i];
else
++d[1][i];
}
}
{
// 下へ行こうとするのを阻止する
i64 miny = sr;
rep(i, 0, N) {
if (miny + d[0][i] - u[0][i] >= H) {
cout << "NO" << endl;
return;
}
if (S[i] == 'D')
++miny;
if (miny >= H) {
cout << "NO" << endl;
return;
}
if (T[i] == 'U' and miny > 0)
--miny;
}
}
{
// 上へ行こうとするのを阻止する
i64 maxy = sr;
rep(i, 0, N) {
if (maxy - u[0][i] + d[0][i] < 0) {
cout << "NO" << endl;
return;
}
if (S[i] == 'U')
--maxy;
if (maxy < 0) {
cout << "NO" << endl;
return;
}
if (T[i] == 'D' and maxy < H - 1)
++maxy;
}
}
{
// 右へ行こうとするのを阻止する
i64 minx = sc;
rep(i, 0, N) {
if (minx + r[0][i] - l[0][i] >= W) {
cout << "NO" << endl;
return;
}
if (S[i] == 'R')
++minx;
if (minx >= W) {
cout << "NO" << endl;
return;
}
if (T[i] == 'L' and minx > 0)
--minx;
}
}
{
// 左へ行こうとするのを阻止する
i64 maxx = sc;
rep(i, 0, N) {
if (maxx - l[0][i] + r[0][i] < 0) {
cout << "NO" << endl;
return;
}
if (S[i] == 'L')
--maxx;
if (maxx < 0) {
cout << "NO" << endl;
return;
}
if (T[i] == 'R' and maxx < W - 1)
++maxx;
}
}
cout << "YES" << endl;
/*
{
if(S[N-1]=='L') ++l[0][N-1];
else if(S[N-1]=='R') ++r[0][N-1];
else if(S[N-1]=='U') ++u[0][N-1];
else ++d[0][N-1];
for(i64 i=N-2; i>=0; --i){
l[0][i]=l[0][i+1];
r[0][i]=r[0][i+1];
u[0][i]=u[0][i+1];
d[0][i]=d[0][i+1];
if(S[i]=='L') ++l[0][i];
else if(S[i]=='R') ++r[0][i];
else if(S[i]=='U') ++u[0][i];
else ++d[0][i];
}
}
{
if(T[N-1]=='L') ++l[1][N-1];
else if(T[N-1]=='R') ++r[1][N-1];
else if(T[N-1]=='U') ++u[1][N-1];
else ++d[1][N-1];
for(i64 i=N-2; i>=0; --i){
l[1][i]=l[1][i+1];
r[1][i]=r[1][i+1];
u[1][i]=u[1][i+1];
d[1][i]=d[1][i+1];
if(T[i]=='L') ++l[1][i];
else if(T[i]=='R') ++r[1][i];
else if(T[i]=='U') ++u[1][i];
else ++d[1][i];
}
*/
}
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define rep(i, x, y) \
for (i64 i = i64(x), i##_max_for_repmacro = i64(y); \
i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T, size_t size> void fill(T (&ary)[size], const T &val) {
fill_n((T *)ary, size, val);
}
void solve() {
// const i64 mod = 1'000'000'007;
i64 H, W, N;
cin >> H >> W >> N;
i64 sr, sc;
cin >> sr >> sc;
--sr;
--sc;
string S, T;
cin >> S >> T;
vector<vector<i64>> l(2, vector<i64>(N)), r(2, vector<i64>(N)),
u(2, vector<i64>(N)), d(2, vector<i64>(N));
/*
{
if(S[0]=='L') ++l[0][0];
else if(S[0]=='R') ++r[0][0];
else if(S[0]=='U') ++u[0][0];
else ++d[0][0];
rep(i,1,N){
l[0][i]=l[0][i-1];
r[0][i]=r[0][i-1];
u[0][i]=u[0][i-1];
d[0][i]=d[0][i-1];
if(S[i]=='L') ++l[0][i];
else if(S[i]=='R') ++r[0][i];
else if(S[i]=='U') ++u[0][i];
else ++d[0][i];
}
}
{
if(T[0]=='L') ++l[1][0];
else if(T[0]=='R') ++r[1][0];
else if(T[0]=='U') ++u[1][0];
else ++d[1][0];
rep(i,1,N){
l[1][i]=l[1][i-1];
r[1][i]=r[1][i-1];
u[1][i]=u[1][i-1];
d[1][i]=d[1][i-1];
if(T[i]=='L') ++l[1][i];
else if(T[i]=='R') ++r[1][i];
else if(T[i]=='U') ++u[1][i];
else ++d[1][i];
}
}
*/
{
if (S[N - 1] == 'L')
++l[0][N - 1];
else if (S[N - 1] == 'R')
++r[0][N - 1];
else if (S[N - 1] == 'U')
++u[0][N - 1];
else
++d[0][N - 1];
for (i64 i = N - 2; i >= 0; --i) {
l[0][i] = l[0][i + 1];
r[0][i] = r[0][i + 1];
u[0][i] = u[0][i + 1];
d[0][i] = d[0][i + 1];
if (S[i] == 'L')
++l[0][i];
else if (S[i] == 'R')
++r[0][i];
else if (S[i] == 'U')
++u[0][i];
else
++d[0][i];
}
}
{
if (T[N - 1] == 'L')
++l[1][N - 1];
else if (T[N - 1] == 'R')
++r[1][N - 1];
else if (T[N - 1] == 'U')
++u[1][N - 1];
else
++d[1][N - 1];
for (i64 i = N - 2; i >= 0; --i) {
l[1][i] = l[1][i + 1];
r[1][i] = r[1][i + 1];
u[1][i] = u[1][i + 1];
d[1][i] = d[1][i + 1];
if (T[i] == 'L')
++l[1][i];
else if (T[i] == 'R')
++r[1][i];
else if (T[i] == 'U')
++u[1][i];
else
++d[1][i];
}
}
{
// 下へ行こうとするのを阻止する
i64 miny = sr;
rep(i, 0, N) {
if (miny + d[0][i] - u[1][i] >= H) {
cout << "NO" << endl;
return;
}
if (S[i] == 'D')
++miny;
if (miny >= H) {
cout << "NO" << endl;
return;
}
if (T[i] == 'U' and miny > 0)
--miny;
}
}
{
// 上へ行こうとするのを阻止する
i64 maxy = sr;
rep(i, 0, N) {
if (maxy - u[0][i] + d[1][i] < 0) {
cout << "NO" << endl;
return;
}
if (S[i] == 'U')
--maxy;
if (maxy < 0) {
cout << "NO" << endl;
return;
}
if (T[i] == 'D' and maxy < H - 1)
++maxy;
}
}
{
// 右へ行こうとするのを阻止する
i64 minx = sc;
rep(i, 0, N) {
if (minx + r[0][i] - l[1][i] >= W) {
cout << "NO" << endl;
return;
}
if (S[i] == 'R')
++minx;
if (minx >= W) {
cout << "NO" << endl;
return;
}
if (T[i] == 'L' and minx > 0)
--minx;
}
}
{
// 左へ行こうとするのを阻止する
i64 maxx = sc;
rep(i, 0, N) {
if (maxx - l[0][i] + r[1][i] < 0) {
cout << "NO" << endl;
return;
}
if (S[i] == 'L')
--maxx;
if (maxx < 0) {
cout << "NO" << endl;
return;
}
if (T[i] == 'R' and maxx < W - 1)
++maxx;
}
}
cout << "YES" << endl;
/*
{
if(S[N-1]=='L') ++l[0][N-1];
else if(S[N-1]=='R') ++r[0][N-1];
else if(S[N-1]=='U') ++u[0][N-1];
else ++d[0][N-1];
for(i64 i=N-2; i>=0; --i){
l[0][i]=l[0][i+1];
r[0][i]=r[0][i+1];
u[0][i]=u[0][i+1];
d[0][i]=d[0][i+1];
if(S[i]=='L') ++l[0][i];
else if(S[i]=='R') ++r[0][i];
else if(S[i]=='U') ++u[0][i];
else ++d[0][i];
}
}
{
if(T[N-1]=='L') ++l[1][N-1];
else if(T[N-1]=='R') ++r[1][N-1];
else if(T[N-1]=='U') ++u[1][N-1];
else ++d[1][N-1];
for(i64 i=N-2; i>=0; --i){
l[1][i]=l[1][i+1];
r[1][i]=r[1][i+1];
u[1][i]=u[1][i+1];
d[1][i]=d[1][i+1];
if(T[i]=='L') ++l[1][i];
else if(T[i]=='R') ++r[1][i];
else if(T[i]=='U') ++u[1][i];
else ++d[1][i];
}
*/
}
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
solve();
return 0;
}
| [
"literal.number.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change"
] | 869,884 | 869,885 | u759266806 | cpp |
p03054 | #include <bits/stdc++.h>
using namespace std;
int main() {
int H, W, N, sr, sc;
string S, T;
cin >> H >> W >> N >> sr >> sc >> S >> T;
bool flag = true;
int r, c;
r = sr;
for (int i = 0; i < N; i++) {
if (S[i] == 'U')
r--;
if (r == 0)
flag = false;
if (T[i] == 'D' && r < H)
r++;
}
r = sr;
for (int i = 0; i < N; i++) {
if (S[i] == 'D')
r++;
if (r == H + 1)
flag = false;
if (T[i] == 'U' && r > 0)
r--;
}
c = sc;
for (int i = 0; i < N; i++) {
if (S[i] == 'L')
c--;
if (c == 0)
flag = false;
if (T[i] == 'R' && c < W)
c++;
}
c = sc;
for (int i = 0; i < N; i++) {
if (S[i] == 'R')
c++;
if (c == W + 1)
flag = false;
if (T[i] == 'L' && c > 0)
c--;
}
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int H, W, N, sr, sc;
string S, T;
cin >> H >> W >> N >> sr >> sc >> S >> T;
bool flag = true;
int r, c;
r = sr;
for (int i = 0; i < N; i++) {
if (S[i] == 'U')
r--;
if (r == 0)
flag = false;
if (T[i] == 'D' && r < H)
r++;
}
r = sr;
for (int i = 0; i < N; i++) {
if (S[i] == 'D')
r++;
if (r == H + 1)
flag = false;
if (T[i] == 'U' && r > 1)
r--;
}
c = sc;
for (int i = 0; i < N; i++) {
if (S[i] == 'L')
c--;
if (c == 0)
flag = false;
if (T[i] == 'R' && c < W)
c++;
}
c = sc;
for (int i = 0; i < N; i++) {
if (S[i] == 'R')
c++;
if (c == W + 1)
flag = false;
if (T[i] == 'L' && c > 1)
c--;
}
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
} | [
"literal.number.change",
"control_flow.branch.if.condition.change"
] | 869,909 | 869,910 | u573082373 | cpp |
p03054 | /*
`-:://:::-
`//:-------:/:`
.+:--.......--:+`
`+:--..`````..--//`
.o:--..`` ``..--:o`
.o:--...```..---+/`
`/y+o/---....---:+o.
`...````-os+/:---:/+o/--.`
`-/+++++/:. `...` :h+d+oooo+/+-` ...
`/++//:::://++-`....` -.`//````````:` `..`
`o+/::------://o/` `-` -. -` `..`
`---.-o/:./o/::-..``..-ЗАПУСКАЕМ .. .. -` `... ``..``
`....o+:-++/:--.```..-://s. `-` .- -` `-o:
.-//::::/:-`
`:s+/:--....-::/+s-` .- `- -` -///:--------:/:`
./s+//:::::://oo-``..НЕЙРОННУЮ: СЕТЬ:::::::-`РАБОТЯГИ
`+:--........--:/`
.:ooo+++++osso-` `.:-...`/` ./::-------:/:` -`
:+--..``````.--:+:...-+:-`
`.-/+++++/+-.-` -. ``:so:/:--.......--:+`
`-```````o+/+--..`````..--:o/-..:s+:.
```````:``.. `-` -`
`+:--..`````..--/+-.../.`````..-o:--.......---/o. `
`: `:- -. .o:--..`` ``..--:o` `-`
`:o+:--------:+o-`
`-`-... .. .o/--...```..--:+/` `-`
`oy/so/////++o/.`
-/` `-` `- ``+s/o/:---...---:++. `-`
.-../d://///:-.`
`.---..``-..- .-/..`````-oo+/:::::/+o+- `-``-` `-.
````
`:++++/+++++- ..``.-/:` /y-:/++o++/:.`..` ./. `-
-++/::::::://+/..:-``:` .. `-.` ```.``` `..` `..`-` `-
`` -o//:--....-::/++` -.-` `-`.-` `..`..` `-.-
-----ss+:++/:--.```..-://s. /. `:: `-:. ./`
`````/:..+o/::-..``.--:/+s. ..-` `-``-` ..` `-` `-`-`
`-s+/::-----::/+oo---``-` .. .:- ``` .-` .-.- `-`
`:oo+//::://+os/..:`..-/:` :y.-:::::::.`.-` ./-` `-`
`./+oooooooo+/.`- .-:...`.. .//:-------://` `- `..` `:.
``.-::::-.``-/` `-` `- `oo:+:--.......--:/` `-
`.:--h.``..```
-.-`.- .- `+:--..`````..--//` `-
/s-//::::::::.
-` `/- .. .o:--..`` ``..--:o.```.-
`//:--------://`
-` .-`.-`
-.`-o/--...```..--:+/.``-:....``:-.+:--....`...--:+`
..`-. `-. ``:os:o/:---...---:++. `-
``///+:-..``````.--:+-````-.`
`.:///////.-` .:-..` -``-+o+/:::::/+o/. `-
`:+:-..`````..--:o/:--/ys+-
`-++///////+o/. ``....`-. :` `.:++++++/:.` .- -o/---......---/o.
`.`
`++//:-----::/+o:..` .-` : ``````` .- `+so+:--------:++-`
`````:-``:o/::-..`..--:/+o` -. `- .- `../../+o+////+o+:.`
-----syo/o+/:--.```..-://s. .-` `- .- `...
``-:////:-``
.` `/s//:--....-::/+s. -. `-` .- `..`
.+o+/:::--:://+s/-..` .::+y ``` .- `..`
./oo++////+oso-` `.... :y-+:::::::/` ...
`.:+oooooo/-` `....-. .//:-------:/:-.`
``...`` /+:+:--.......--:+`
`+:--..`````..--//`
.o:--..`` ``..--:o`
.+/--...```..--:+/`
`-o/:---...---:++.
`-+o+/:---:/+o/.
`.:+oooo+/-.`
``````
*/
#ifdef aimbot
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#endif
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <limits>
#include <list>
#include <map>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define random escape__from__random__aetuhoetnuhshe
#define mt make_tuple
#define x first
#define y second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define umap unordered_map
#define uset unordered_set
#define elif else if
#define len(v) ((int)v.size())
#define f(i, n) for (int i = 0; i < (n); i++)
#define rof(i, n) for (int i = ((n)-1); i >= 0; i--)
#define apply(v, act) \
for (auto &x : v) { \
act; \
}
#define log(args...) \
{ \
string s = #args; \
deque<string> deq; \
string buf = ""; \
int bal = 0; \
for (char c : s) { \
if (c == '(' || c == '[' || c == '{') { \
bal++; \
} else if (c == ')' || c == ']' || c == '}') { \
bal--; \
} else { \
if (bal == 0) { \
if (c == ',') { \
deq.pb(buf); \
buf = ""; \
} else { \
if (c != ' ') { \
buf += c; \
} \
} \
} \
} \
} \
if (!buf.empty()) { \
deq.pb(buf); \
} \
smart_io::precall_print(); \
smart_io::_print(deq, args); \
}
inline int min(const int &x, const int &y) {
return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x;
}
inline int max(const int &x, const int &y) {
return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y;
}
inline long long min(const long long &x, const long long &y) {
return (((y - x) >> (64 - 1)) & (x ^ y)) ^ x;
}
inline long long max(const long long &x, const long long &y) {
return (((y - x) >> (64 - 1)) & (x ^ y)) ^ y;
}
#define print \
smart_io::precall_print(); \
cout,
#define scan cin,
#ifdef fast_allocator
const int MAXMEM = 200 * 1000 * 1024;
char _memory[MAXMEM];
size_t _ptr = 0;
void *operator new(size_t _x) {
_ptr += _x;
assert(_ptr < MAXMEM);
return _memory + _ptr - _x;
}
void operator delete(void *) noexcept {}
#endif
using namespace std;
char string_in_buffer[(int)2e6];
void fast_scan(int &x) { scanf("%d", &x); }
void fast_scan(long long &x) { scanf("%lld", &x); }
void fast_scan(unsigned long long &x) { scanf("%llu", &x); }
void fast_scan(double &x) { scanf("%lf", &x); }
void fast_scan(long double &x) { scanf("%Lf", &x); }
void fast_scan(char &x) {
scanf("%c", &x);
if (x == '\n') {
fast_scan(x);
}
}
void fast_scan(string &x) {
scanf("%s", string_in_buffer);
x = string(string_in_buffer);
}
template <class TFirst, class TSecond>
void fast_scan(pair<TFirst, TSecond> &p) {
fast_scan(p.first);
fast_scan(p.second);
}
template <class T> void fast_scan(vector<T> &v) {
for (auto &x : v)
fast_scan(x);
}
void fast_print(const int &x) { printf("%d", x); }
void fast_print(const unsigned int &x) { printf("%u", x); }
void fast_print(const long long &x) { printf("%lld", x); }
void fast_print(const unsigned long long &x) { printf("%llu", x); }
void fast_print(const double &x) { printf("%.15lf", x); }
void fast_print(const long double &x) { printf("%.15Lf", x); }
void fast_print(const char &x) { printf("%c", x); };
void fast_print(const string &x) { printf("%s", x.c_str()); }
void fast_print(const char v[]) { fast_print((string)v); }
template <class TFirst, class TSecond>
void fast_print(const pair<TFirst, TSecond> &p) {
fast_print(p.first);
fast_print(' ');
fast_print(p.second);
}
template <class T> void fast_print(const vector<T> &v) {
if (v.empty())
return;
fast_print(v[0]);
for (int i = 1; i < v.size(); i++) {
fast_print(' ');
fast_print(v[i]);
}
}
template <class T> void fast_print(const vector<vector<T>> &v) {
if (v.empty())
return;
fast_print(v[0]);
for (int i = 1; i < v.size(); i++) {
fast_print('\n');
fast_print(v[i]);
}
}
template <class T> void fast_print(const T &v) {
for (const auto &x : v) {
fast_print(x);
fast_print(' ');
}
}
using namespace std;
namespace smart_io {
string print_start = "";
string sep = " ";
bool first_print = false;
void precall_print() {
fast_print(print_start);
print_start = "\n";
first_print = true;
}
void _print(deque<string>) {}
template <class T, class... Args>
void _print(deque<string> names, T elem, Args... args) {
if (!first_print) {
fast_print("\n");
} else {
first_print = false;
}
fast_print(names.front());
fast_print(" = ");
fast_print(elem);
names.pop_front();
_print(names, args...);
}
} // namespace smart_io
template <class T> ostream &operator,(ostream &os, const T &object) {
if (!smart_io::first_print) {
fast_print(smart_io::sep);
} else {
smart_io::first_print = false;
}
fast_print(object);
return os;
}
template <class T> istream &operator,(istream &is, T &object) {
fast_scan(object);
return is;
}
namespace random {
using namespace std::chrono;
mt19937 rng(duration_cast<milliseconds>(system_clock::now().time_since_epoch())
.count());
uniform_real_distribution<> prob_dist(0.0, 1.0);
}; // namespace random
namespace typedefs {
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef long double ld;
} // namespace typedefs
namespace numbers_operation {
template <class T> T floor_mod(T a, T b) {
if (a >= 0 && b >= 0)
return a % b;
if (a <= 0 && b <= 0)
return a % b;
return abs(b) - (abs(a) % abs(b));
}
} // namespace numbers_operation
using namespace numbers_operation;
using namespace typedefs;
using namespace random;
#define ceil anonoeeuhasonetuhetonasonetuh
int h, w, n;
pii ceil;
string s, t;
bool solve(vector<int> a, vector<int> b, int N, int start) {
int l = 0, r = N - 1;
rof(i, n) {
if (b[i] == -1) {
r++;
} else if (b[i] == 1) {
l--;
}
l = max(0, l);
r = min(r, N - 1);
if (a[i] == -1) {
l++;
} else if (a[i] == 1) {
r--;
}
if (l > r)
return false;
}
return l <= start && start <= r;
}
signed main(signed argc, char *argv[]) {
scan h, w, n, ceil;
scan s, t;
{
vector<int> a(n), b(n);
f(i, n) {
if (s[i] == 'L') {
a[i] = -1;
} else if (s[i] == 'R') {
a[i] = 1;
}
if (t[i] == 'L') {
b[i] = -1;
} else if (t[i] == 'R') {
b[i] = 1;
}
}
if (!(solve(a, b, w, ceil.y - 1))) {
print "NO";
return 0;
}
}
{
vector<int> a(n), b(n);
f(i, n) {
if (s[i] == 'U') {
a[i] = -1;
} else if (s[i] == 'D') {
a[i] = 1;
}
if (t[i] == 'U') {
b[i] = -1;
} else if (t[i] == 'D') {
b[i] = 1;
}
}
if (!(solve(a, b, h, ceil.y - 1))) {
print "NO";
return 0;
}
}
{ print "YES"; }
}
| /*
`-:://:::-
`//:-------:/:`
.+:--.......--:+`
`+:--..`````..--//`
.o:--..`` ``..--:o`
.o:--...```..---+/`
`/y+o/---....---:+o.
`...````-os+/:---:/+o/--.`
`-/+++++/:. `...` :h+d+oooo+/+-` ...
`/++//:::://++-`....` -.`//````````:` `..`
`o+/::------://o/` `-` -. -` `..`
`---.-o/:./o/::-..``..-ЗАПУСКАЕМ .. .. -` `... ``..``
`....o+:-++/:--.```..-://s. `-` .- -` `-o:
.-//::::/:-`
`:s+/:--....-::/+s-` .- `- -` -///:--------:/:`
./s+//:::::://oo-``..НЕЙРОННУЮ: СЕТЬ:::::::-`РАБОТЯГИ
`+:--........--:/`
.:ooo+++++osso-` `.:-...`/` ./::-------:/:` -`
:+--..``````.--:+:...-+:-`
`.-/+++++/+-.-` -. ``:so:/:--.......--:+`
`-```````o+/+--..`````..--:o/-..:s+:.
```````:``.. `-` -`
`+:--..`````..--/+-.../.`````..-o:--.......---/o. `
`: `:- -. .o:--..`` ``..--:o` `-`
`:o+:--------:+o-`
`-`-... .. .o/--...```..--:+/` `-`
`oy/so/////++o/.`
-/` `-` `- ``+s/o/:---...---:++. `-`
.-../d://///:-.`
`.---..``-..- .-/..`````-oo+/:::::/+o+- `-``-` `-.
````
`:++++/+++++- ..``.-/:` /y-:/++o++/:.`..` ./. `-
-++/::::::://+/..:-``:` .. `-.` ```.``` `..` `..`-` `-
`` -o//:--....-::/++` -.-` `-`.-` `..`..` `-.-
-----ss+:++/:--.```..-://s. /. `:: `-:. ./`
`````/:..+o/::-..``.--:/+s. ..-` `-``-` ..` `-` `-`-`
`-s+/::-----::/+oo---``-` .. .:- ``` .-` .-.- `-`
`:oo+//::://+os/..:`..-/:` :y.-:::::::.`.-` ./-` `-`
`./+oooooooo+/.`- .-:...`.. .//:-------://` `- `..` `:.
``.-::::-.``-/` `-` `- `oo:+:--.......--:/` `-
`.:--h.``..```
-.-`.- .- `+:--..`````..--//` `-
/s-//::::::::.
-` `/- .. .o:--..`` ``..--:o.```.-
`//:--------://`
-` .-`.-`
-.`-o/--...```..--:+/.``-:....``:-.+:--....`...--:+`
..`-. `-. ``:os:o/:---...---:++. `-
``///+:-..``````.--:+-````-.`
`.:///////.-` .:-..` -``-+o+/:::::/+o/. `-
`:+:-..`````..--:o/:--/ys+-
`-++///////+o/. ``....`-. :` `.:++++++/:.` .- -o/---......---/o.
`.`
`++//:-----::/+o:..` .-` : ``````` .- `+so+:--------:++-`
`````:-``:o/::-..`..--:/+o` -. `- .- `../../+o+////+o+:.`
-----syo/o+/:--.```..-://s. .-` `- .- `...
``-:////:-``
.` `/s//:--....-::/+s. -. `-` .- `..`
.+o+/:::--:://+s/-..` .::+y ``` .- `..`
./oo++////+oso-` `.... :y-+:::::::/` ...
`.:+oooooo/-` `....-. .//:-------:/:-.`
``...`` /+:+:--.......--:+`
`+:--..`````..--//`
.o:--..`` ``..--:o`
.+/--...```..--:+/`
`-o/:---...---:++.
`-+o+/:---:/+o/.
`.:+oooo+/-.`
``````
*/
#ifdef aimbot
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#endif
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <limits>
#include <list>
#include <map>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define random escape__from__random__aetuhoetnuhshe
#define mt make_tuple
#define x first
#define y second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define umap unordered_map
#define uset unordered_set
#define elif else if
#define len(v) ((int)v.size())
#define f(i, n) for (int i = 0; i < (n); i++)
#define rof(i, n) for (int i = ((n)-1); i >= 0; i--)
#define apply(v, act) \
for (auto &x : v) { \
act; \
}
#define log(args...) \
{ \
string s = #args; \
deque<string> deq; \
string buf = ""; \
int bal = 0; \
for (char c : s) { \
if (c == '(' || c == '[' || c == '{') { \
bal++; \
} else if (c == ')' || c == ']' || c == '}') { \
bal--; \
} else { \
if (bal == 0) { \
if (c == ',') { \
deq.pb(buf); \
buf = ""; \
} else { \
if (c != ' ') { \
buf += c; \
} \
} \
} \
} \
} \
if (!buf.empty()) { \
deq.pb(buf); \
} \
smart_io::precall_print(); \
smart_io::_print(deq, args); \
}
inline int min(const int &x, const int &y) {
return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x;
}
inline int max(const int &x, const int &y) {
return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y;
}
inline long long min(const long long &x, const long long &y) {
return (((y - x) >> (64 - 1)) & (x ^ y)) ^ x;
}
inline long long max(const long long &x, const long long &y) {
return (((y - x) >> (64 - 1)) & (x ^ y)) ^ y;
}
#define print \
smart_io::precall_print(); \
cout,
#define scan cin,
#ifdef fast_allocator
const int MAXMEM = 200 * 1000 * 1024;
char _memory[MAXMEM];
size_t _ptr = 0;
void *operator new(size_t _x) {
_ptr += _x;
assert(_ptr < MAXMEM);
return _memory + _ptr - _x;
}
void operator delete(void *) noexcept {}
#endif
using namespace std;
char string_in_buffer[(int)2e6];
void fast_scan(int &x) { scanf("%d", &x); }
void fast_scan(long long &x) { scanf("%lld", &x); }
void fast_scan(unsigned long long &x) { scanf("%llu", &x); }
void fast_scan(double &x) { scanf("%lf", &x); }
void fast_scan(long double &x) { scanf("%Lf", &x); }
void fast_scan(char &x) {
scanf("%c", &x);
if (x == '\n') {
fast_scan(x);
}
}
void fast_scan(string &x) {
scanf("%s", string_in_buffer);
x = string(string_in_buffer);
}
template <class TFirst, class TSecond>
void fast_scan(pair<TFirst, TSecond> &p) {
fast_scan(p.first);
fast_scan(p.second);
}
template <class T> void fast_scan(vector<T> &v) {
for (auto &x : v)
fast_scan(x);
}
void fast_print(const int &x) { printf("%d", x); }
void fast_print(const unsigned int &x) { printf("%u", x); }
void fast_print(const long long &x) { printf("%lld", x); }
void fast_print(const unsigned long long &x) { printf("%llu", x); }
void fast_print(const double &x) { printf("%.15lf", x); }
void fast_print(const long double &x) { printf("%.15Lf", x); }
void fast_print(const char &x) { printf("%c", x); };
void fast_print(const string &x) { printf("%s", x.c_str()); }
void fast_print(const char v[]) { fast_print((string)v); }
template <class TFirst, class TSecond>
void fast_print(const pair<TFirst, TSecond> &p) {
fast_print(p.first);
fast_print(' ');
fast_print(p.second);
}
template <class T> void fast_print(const vector<T> &v) {
if (v.empty())
return;
fast_print(v[0]);
for (int i = 1; i < v.size(); i++) {
fast_print(' ');
fast_print(v[i]);
}
}
template <class T> void fast_print(const vector<vector<T>> &v) {
if (v.empty())
return;
fast_print(v[0]);
for (int i = 1; i < v.size(); i++) {
fast_print('\n');
fast_print(v[i]);
}
}
template <class T> void fast_print(const T &v) {
for (const auto &x : v) {
fast_print(x);
fast_print(' ');
}
}
using namespace std;
namespace smart_io {
string print_start = "";
string sep = " ";
bool first_print = false;
void precall_print() {
fast_print(print_start);
print_start = "\n";
first_print = true;
}
void _print(deque<string>) {}
template <class T, class... Args>
void _print(deque<string> names, T elem, Args... args) {
if (!first_print) {
fast_print("\n");
} else {
first_print = false;
}
fast_print(names.front());
fast_print(" = ");
fast_print(elem);
names.pop_front();
_print(names, args...);
}
} // namespace smart_io
template <class T> ostream &operator,(ostream &os, const T &object) {
if (!smart_io::first_print) {
fast_print(smart_io::sep);
} else {
smart_io::first_print = false;
}
fast_print(object);
return os;
}
template <class T> istream &operator,(istream &is, T &object) {
fast_scan(object);
return is;
}
namespace random {
using namespace std::chrono;
mt19937 rng(duration_cast<milliseconds>(system_clock::now().time_since_epoch())
.count());
uniform_real_distribution<> prob_dist(0.0, 1.0);
}; // namespace random
namespace typedefs {
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef long double ld;
} // namespace typedefs
namespace numbers_operation {
template <class T> T floor_mod(T a, T b) {
if (a >= 0 && b >= 0)
return a % b;
if (a <= 0 && b <= 0)
return a % b;
return abs(b) - (abs(a) % abs(b));
}
} // namespace numbers_operation
using namespace numbers_operation;
using namespace typedefs;
using namespace random;
#define ceil anonoeeuhasonetuhetonasonetuh
int h, w, n;
pii ceil;
string s, t;
bool solve(vector<int> a, vector<int> b, int N, int start) {
int l = 0, r = N - 1;
rof(i, n) {
if (b[i] == -1) {
r++;
} else if (b[i] == 1) {
l--;
}
l = max(0, l);
r = min(r, N - 1);
if (a[i] == -1) {
l++;
} else if (a[i] == 1) {
r--;
}
if (l > r)
return false;
}
return l <= start && start <= r;
}
signed main(signed argc, char *argv[]) {
scan h, w, n, ceil;
scan s, t;
{
vector<int> a(n), b(n);
f(i, n) {
if (s[i] == 'L') {
a[i] = -1;
} else if (s[i] == 'R') {
a[i] = 1;
}
if (t[i] == 'L') {
b[i] = -1;
} else if (t[i] == 'R') {
b[i] = 1;
}
}
if (!(solve(a, b, w, ceil.y - 1))) {
print "NO";
return 0;
}
}
{
vector<int> a(n), b(n);
f(i, n) {
if (s[i] == 'U') {
a[i] = -1;
} else if (s[i] == 'D') {
a[i] = 1;
}
if (t[i] == 'U') {
b[i] = -1;
} else if (t[i] == 'D') {
b[i] = 1;
}
}
if (!(solve(a, b, h, ceil.x - 1))) {
print "NO";
return 0;
}
}
{ print "YES"; }
}
| [
"control_flow.branch.if.condition.change"
] | 869,911 | 869,912 | u656721037 | cpp |
p03054 | #include <bits/stdc++.h>
using namespace std;
struct fast_ios {
fast_ios() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
};
} fast_ios_;
#define FOR(i, begin, end) for (int i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define IFOR(i, begin, end) for (int i = (end)-1; i >= (begin); i--)
#define IREP(i, n) IFOR(i, 0, n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(), v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) \
distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL << (n))
#define bit_exist(x, n) ((x >> n) & 1)
#define Ans(f, y, n) \
if (f) \
cout << y << endl; \
else \
cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) \
cout << #v << "=" << endl; \
REP(i, v.size()) { cout << v[i] << ","; } \
cout << endl;
#define mdebug(m) \
cout << #m << "=" << endl; \
REP(i, m.size()) { \
REP(j, m[i].size()) { cout << m[i][j] << ","; } \
cout << endl; \
}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
template <typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) {
REP(i, a.size()) {
cin >> a[i];
a[i]--;
}
}
// int dx[4] = {1,0,-1,0};
// int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
// int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod
signed main() {
int H, W, N;
cin >> H >> W >> N;
int sr, sc;
cin >> sr >> sc;
sr--;
sc--;
string S, T;
cin >> S >> T;
// x
int xmin = -1, xmax = H;
bool f = true;
IREP(i, N) {
if (llabs(xmax - xmin) <= 1)
f = false;
if (xmin != -1 && T[i] == 'D')
xmin--;
if (xmax != H && T[i] == 'U')
xmax++;
if (S[i] == 'D')
xmax--;
if (S[i] == 'U')
xmin++;
}
// y
int ymin = -1, ymax = W;
IREP(i, N) {
if (llabs(ymax - ymin) <= 1)
f = false;
if (xmin != -1 && T[i] == 'R')
ymin--;
if (xmax != W && T[i] == 'L')
ymax++;
if (S[i] == 'R')
ymax--;
if (S[i] == 'L')
ymin++;
}
Ans(xmin < sr && sr < xmax && ymin < sc && sc < ymax && f, "YES", "NO");
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
struct fast_ios {
fast_ios() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
};
} fast_ios_;
#define FOR(i, begin, end) for (int i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define IFOR(i, begin, end) for (int i = (end)-1; i >= (begin); i--)
#define IREP(i, n) IFOR(i, 0, n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(), v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) \
distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL << (n))
#define bit_exist(x, n) ((x >> n) & 1)
#define Ans(f, y, n) \
if (f) \
cout << y << endl; \
else \
cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) \
cout << #v << "=" << endl; \
REP(i, v.size()) { cout << v[i] << ","; } \
cout << endl;
#define mdebug(m) \
cout << #m << "=" << endl; \
REP(i, m.size()) { \
REP(j, m[i].size()) { cout << m[i][j] << ","; } \
cout << endl; \
}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
template <typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) {
REP(i, a.size()) {
cin >> a[i];
a[i]--;
}
}
// int dx[4] = {1,0,-1,0};
// int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
// int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod
signed main() {
int H, W, N;
cin >> H >> W >> N;
int sr, sc;
cin >> sr >> sc;
sr--;
sc--;
string S, T;
cin >> S >> T;
// x
int xmin = -1, xmax = H;
bool f = true;
IREP(i, N) {
if (llabs(xmax - xmin) <= 1)
f = false;
if (xmin != -1 && T[i] == 'D')
xmin--;
if (xmax != H && T[i] == 'U')
xmax++;
if (S[i] == 'D')
xmax--;
if (S[i] == 'U')
xmin++;
}
// y
int ymin = -1, ymax = W;
IREP(i, N) {
if (llabs(ymax - ymin) <= 1)
f = false;
if (ymin != -1 && T[i] == 'R')
ymin--;
if (ymax != W && T[i] == 'L')
ymax++;
if (S[i] == 'R')
ymax--;
if (S[i] == 'L')
ymin++;
}
Ans(xmin < sr && sr < xmax && ymin < sc && sc < ymax && f, "YES", "NO");
return 0;
}
| [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 869,921 | 869,922 | u434231045 | cpp |
p03054 | #pragma optimize "-O3"
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int h, w, n;
int x, y;
string s, t;
int balR, balL, balU, balD;
void bad() {
cout << "NO";
exit(0);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("input.txt", "r", stdin);
cin >> h >> w >> n >> x >> y;
cin >> s >> t;
for (int i = 0; i < n; i++) {
if (t[i] == 'L' || t[i] == 'R') {
t[i] = 'R' + 'L' - t[i];
} else {
t[i] = 'U' + 'D' - t[i];
}
}
balR = y - w - 1;
balL = -y;
balD = x - h - 1;
balU = -x;
for (int i = 0; i < 2 * n; i++) {
char c;
if (i % 2 == 0)
c = s[i / 2];
else
c = t[i / 2];
int sgn = 1;
if (i % 2 == 1)
sgn = -1;
if (c == 'R') {
balR += sgn;
} else if (c == 'L') {
balL += sgn;
} else if (c == 'D') {
balD += sgn;
} else {
balU += sgn;
}
if (balR >= 0 || balL >= 0 || balU >= 0 || balD >= 0)
bad();
balR = max(balR, -w);
balL = max(balL, -w);
balU = max(balU, -h);
balD = max(balU, -h);
}
cout << "YES" << '\n';
return 0;
} | #pragma optimize "-O3"
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int h, w, n;
int x, y;
string s, t;
int balR, balL, balU, balD;
void bad() {
cout << "NO";
exit(0);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("input.txt", "r", stdin);
cin >> h >> w >> n >> x >> y;
cin >> s >> t;
for (int i = 0; i < n; i++) {
if (t[i] == 'L' || t[i] == 'R') {
t[i] = 'R' + 'L' - t[i];
} else {
t[i] = 'U' + 'D' - t[i];
}
}
balR = y - w - 1;
balL = -y;
balD = x - h - 1;
balU = -x;
for (int i = 0; i < 2 * n; i++) {
char c;
if (i % 2 == 0)
c = s[i / 2];
else
c = t[i / 2];
int sgn = 1;
if (i % 2 == 1)
sgn = -1;
if (c == 'R') {
balR += sgn;
} else if (c == 'L') {
balL += sgn;
} else if (c == 'D') {
balD += sgn;
} else {
balU += sgn;
}
if (balR >= 0 || balL >= 0 || balU >= 0 || balD >= 0)
bad();
balR = max(balR, -w);
balL = max(balL, -w);
balU = max(balU, -h);
balD = max(balD, -h);
}
cout << "YES" << '\n';
return 0;
} | [
"assignment.value.change",
"identifier.change",
"call.arguments.change"
] | 869,923 | 869,924 | u720150053 | cpp |
p03054 | /*input
2 3 3
2 2
RRL
LUD
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
#define IOS \
ios_base::sync_with_stdio(0); \
cin.tie(0)
#define ALL(a) a.begin(), a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i, n) for (int i = 0; i < ((int)n); i++)
#define pb push_back
#define MP(a, b) make_pair(a, b)
#define SORT_UNIQUE(c) \
(sort(c.begin(), c.end()), \
c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin())
template <typename T1, typename T2>
ostream &operator<<(ostream &out, pair<T1, T2> P) {
out << '(' << P.F << ',' << P.S << ')';
return out;
}
//}}}
const ll maxn = 300005;
const ll maxlg = __lg(maxn) + 2;
const ll INF64 = 8000000000000000000LL;
const int INF = 0x3f3f3f3f;
const ll MOD = ll(1e9 + 7);
const ld PI = acos(-1);
const ld eps = 1e-9;
// const ll p=880301;
// const ll P=31;
ll mypow(ll a, ll b) {
ll res = 1LL;
while (b) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
string s, t;
int main() {
IOS;
int n, m, q;
cin >> n >> m >> q;
int x, y;
cin >> x >> y;
x--;
y--;
cin >> s >> t;
int l = 0, r = m, d = 0, u = n;
for (int i = q - 1; i >= 0; i--) {
if (t[i] == 'L') {
r++;
if (r > m)
r--;
} else if (t[i] == 'R') {
l--;
if (l < 0)
l++;
} else if (t[i] == 'U') {
u++;
if (u > n)
u--;
} else {
d--;
if (d < 0)
d = 0;
}
if (s[i] == 'L') {
l++;
} else if (s[i] == 'R') {
r--;
} else if (s[i] == 'U') {
d++;
} else {
u--;
}
if (d == u || l == r) {
cout << "NO\n";
return 0;
}
}
if (d <= x && x < u && l <= y && y < u) {
cout << "YES\n";
} else
cout << "NO\n";
return 0;
}
| /*input
1 5 5
1 3
RRRRR
LLLUU
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
#define IOS \
ios_base::sync_with_stdio(0); \
cin.tie(0)
#define ALL(a) a.begin(), a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i, n) for (int i = 0; i < ((int)n); i++)
#define pb push_back
#define MP(a, b) make_pair(a, b)
#define SORT_UNIQUE(c) \
(sort(c.begin(), c.end()), \
c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin())
template <typename T1, typename T2>
ostream &operator<<(ostream &out, pair<T1, T2> P) {
out << '(' << P.F << ',' << P.S << ')';
return out;
}
//}}}
const ll maxn = 300005;
const ll maxlg = __lg(maxn) + 2;
const ll INF64 = 8000000000000000000LL;
const int INF = 0x3f3f3f3f;
const ll MOD = ll(1e9 + 7);
const ld PI = acos(-1);
const ld eps = 1e-9;
// const ll p=880301;
// const ll P=31;
ll mypow(ll a, ll b) {
ll res = 1LL;
while (b) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
string s, t;
int main() {
IOS;
int n, m, q;
cin >> n >> m >> q;
int x, y;
cin >> x >> y;
x--;
y--;
cin >> s >> t;
int l = 0, r = m, d = 0, u = n;
for (int i = q - 1; i >= 0; i--) {
if (t[i] == 'L') {
r++;
if (r > m)
r--;
} else if (t[i] == 'R') {
l--;
if (l < 0)
l++;
} else if (t[i] == 'U') {
u++;
if (u > n)
u--;
} else {
d--;
if (d < 0)
d = 0;
}
if (s[i] == 'L') {
l++;
} else if (s[i] == 'R') {
r--;
} else if (s[i] == 'U') {
d++;
} else {
u--;
}
if (d == u || l == r) {
cout << "NO\n";
return 0;
}
// cout<<d<<' '<<u<<' '<<l<<' '<<r<<'\n';
}
if (d <= x && x < u && l <= y && y < r) {
cout << "YES\n";
} else
cout << "NO\n";
return 0;
}
| [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 869,929 | 869,930 | u010467501 | cpp |
p03054 | #include <iostream>
using namespace std;
int H, W, N, sx, sy;
int direction[4] = {};
string S, T;
int main() {
cin >> H >> W >> N;
cin >> sx >> sy;
cin >> S >> T;
for (int i = 1; i <= N; i++) {
if (S[i - 1] == 'U')
direction[0]++;
if (S[i - 1] == 'L')
direction[1]++;
if (S[i - 1] == 'D')
direction[2]++;
if (S[i - 1] == 'R')
direction[3]++;
if (sx - direction[0] <= 0 || H - sx - direction[2] <= 0 ||
sy - direction[1] <= 0 || W - sy - direction[3] <= 0) {
cout << "NO" << endl;
return 0;
}
if (T[i - 1] == 'U')
direction[2] = max(direction[2] - 1, -sx + 1);
if (T[i - 1] == 'L')
direction[3] = max(direction[3] - 1, -sy + 1);
if (T[i - 1] == 'D')
direction[0] = max(direction[0] - 1, sx - H);
if (T[i - 1] == 'R')
direction[1] = max(direction[1] - 1, sy - W);
}
cout << "YES" << endl;
} | #include <iostream>
using namespace std;
int H, W, N, sx, sy;
int direction[4] = {};
string S, T;
int main() {
cin >> H >> W >> N;
cin >> sx >> sy;
cin >> S >> T;
for (int i = 1; i <= N; i++) {
if (S[i - 1] == 'U')
direction[0]++;
if (S[i - 1] == 'L')
direction[1]++;
if (S[i - 1] == 'D')
direction[2]++;
if (S[i - 1] == 'R')
direction[3]++;
if (sx - direction[0] <= 0 || H - sx - direction[2] + 1 <= 0 ||
sy - direction[1] <= 0 || W - sy - direction[3] + 1 <= 0) {
cout << "NO" << endl;
return 0;
}
if (T[i - 1] == 'U')
direction[2] = max(direction[2] - 1, -sx + 1);
if (T[i - 1] == 'L')
direction[3] = max(direction[3] - 1, -sy + 1);
if (T[i - 1] == 'D')
direction[0] = max(direction[0] - 1, sx - H);
if (T[i - 1] == 'R')
direction[1] = max(direction[1] - 1, sy - W);
}
cout << "YES" << endl;
} | [
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one"
] | 869,931 | 869,932 | u623954643 | cpp |
p03054 | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define repm(i, a, b) for (int i = (int)(a); i > (int)(b); --i)
int main() {
int H, W, N;
cin >> H >> W >> N;
int sr, sc;
cin >> sr >> sc;
string S;
cin >> S;
string T;
cin >> T;
int minr = 1, maxr = H + 1, minc = 1, maxc = W + 1;
repm(i, N - 1, -1) {
if (T[i] == 'L')
maxc = min(maxc + 1, W + 1);
if (T[i] == 'R')
minc = min(minc - 1, 1);
if (T[i] == 'U')
maxr = min(maxr + 1, H + 1);
if (T[i] == 'D')
minr = min(minr - 1, 1);
if (S[i] == 'L')
++minc;
if (S[i] == 'R')
--maxc;
if (S[i] == 'U')
++minr;
if (S[i] == 'D')
--maxr;
if (minc == maxc || minr == maxr)
return cout << "NO" << endl, 0;
}
cout << ((minr <= sr && sr < maxr && minc <= sc && sc < maxc) ? "YES" : "NO")
<< endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define repm(i, a, b) for (int i = (int)(a); i > (int)(b); --i)
int main() {
int H, W, N;
cin >> H >> W >> N;
int sr, sc;
cin >> sr >> sc;
string S;
cin >> S;
string T;
cin >> T;
int minr = 1, maxr = H + 1, minc = 1, maxc = W + 1;
repm(i, N - 1, -1) {
if (T[i] == 'L')
maxc = min(maxc + 1, W + 1);
if (T[i] == 'R')
minc = max(minc - 1, 1);
if (T[i] == 'U')
maxr = min(maxr + 1, H + 1);
if (T[i] == 'D')
minr = max(minr - 1, 1);
if (S[i] == 'L')
++minc;
if (S[i] == 'R')
--maxc;
if (S[i] == 'U')
++minr;
if (S[i] == 'D')
--maxr;
if (minc == maxc || minr == maxr)
return cout << "NO" << endl, 0;
}
cout << ((minr <= sr && sr < maxr && minc <= sc && sc < maxc) ? "YES" : "NO")
<< endl;
return 0;
}
| [
"misc.opposites",
"assignment.value.change",
"identifier.change",
"call.function.change"
] | 869,933 | 869,934 | u007446928 | cpp |
p03054 | #include <bits/stdc++.h>
using namespace std;
const int MX = 200000;
bool solve(int w, int n, int x, int *ds, int *dt) {
int L = 1, R = w;
for (int i = n - 1; i >= 0; i--) {
if (dt[i] == 1)
L = max(L - 1, 1);
if (dt[i] == -1)
R = min(R + 1, n);
if (ds[i] == 1)
R--;
if (ds[i] == -1)
L++;
if (L > R)
return false;
}
return L <= x && x <= R;
}
char s[MX + 1], t[MX + 1];
int ds[MX], dt[MX];
int main() {
int h, w, n, x, y;
ignore = scanf("%d %d %d %d %d %s %s", &h, &w, &n, &x, &y, s, t);
bool ans = true;
auto getX = [](char c) {
if (c == 'U')
return -1;
if (c == 'D')
return 1;
return 0;
};
for (int i = 0; i < n; i++) {
ds[i] = getX(s[i]);
dt[i] = getX(t[i]);
}
ans = ans && solve(h, n, x, ds, dt);
auto getY = [](char c) {
if (c == 'L')
return -1;
if (c == 'R')
return 1;
return 0;
};
for (int i = 0; i < n; i++) {
ds[i] = getY(s[i]);
dt[i] = getY(t[i]);
}
ans = ans && solve(w, n, y, ds, dt);
printf("%s\n", ans ? "YES" : "NO");
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int MX = 200000;
bool solve(int w, int n, int x, int *ds, int *dt) {
int L = 1, R = w;
for (int i = n - 1; i >= 0; i--) {
if (dt[i] == 1)
L = max(L - 1, 1);
if (dt[i] == -1)
R = min(R + 1, w);
if (ds[i] == 1)
R--;
if (ds[i] == -1)
L++;
if (L > R)
return false;
}
return L <= x && x <= R;
}
char s[MX + 1], t[MX + 1];
int ds[MX], dt[MX];
int main() {
int h, w, n, x, y;
ignore = scanf("%d %d %d %d %d %s %s", &h, &w, &n, &x, &y, s, t);
bool ans = true;
auto getX = [](char c) {
if (c == 'U')
return -1;
if (c == 'D')
return 1;
return 0;
};
for (int i = 0; i < n; i++) {
ds[i] = getX(s[i]);
dt[i] = getX(t[i]);
}
ans = ans && solve(h, n, x, ds, dt);
auto getY = [](char c) {
if (c == 'L')
return -1;
if (c == 'R')
return 1;
return 0;
};
for (int i = 0; i < n; i++) {
ds[i] = getY(s[i]);
dt[i] = getY(t[i]);
}
ans = ans && solve(w, n, y, ds, dt);
printf("%s\n", ans ? "YES" : "NO");
return 0;
}
| [
"assignment.value.change",
"identifier.change",
"call.arguments.change"
] | 869,940 | 869,941 | u037304230 | cpp |
p03054 | #include <bits/stdc++.h>
using namespace std;
using int64 = long long;
const int mod = 1e9 + 7;
const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
struct IoSetup {
IoSetup() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
cerr << fixed << setprecision(10);
}
} iosetup;
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << p.first << " " << p.second;
return os;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < (int)v.size(); i++) {
os << v[i] << (i + 1 != v.size() ? " " : "");
}
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (T &in : v)
is >> in;
return is;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
template <typename T = int64> 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);
}
int main() {
int H, W, N, Y, X;
string S, T;
cin >> H >> W >> N;
cin >> Y >> X;
--Y, --X;
cin >> S >> T;
const int d[] = {-1, 1, -1, 1};
string V = "LRUD";
for (int i = 0; i < 4; i++) {
int pon = i <= 1 ? X : Y;
int n = i <= 1 ? W : H;
for (int j = 0; j < N; j++) {
if (S[j] == V[i])
pon += d[j];
if (pon < 0 || pon >= n) {
cout << "NO" << endl;
return 0;
}
if (T[j] == V[i ^ 1]) {
pon -= d[j];
if (pon < 0 || pon >= n)
pon += d[j];
}
}
}
cout << "YES" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using int64 = long long;
const int mod = 1e9 + 7;
const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
struct IoSetup {
IoSetup() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
cerr << fixed << setprecision(10);
}
} iosetup;
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << p.first << " " << p.second;
return os;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < (int)v.size(); i++) {
os << v[i] << (i + 1 != v.size() ? " " : "");
}
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (T &in : v)
is >> in;
return is;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
template <typename T = int64> 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);
}
int main() {
int H, W, N, Y, X;
string S, T;
cin >> H >> W >> N;
cin >> Y >> X;
--Y, --X;
cin >> S >> T;
const int d[] = {-1, 1, -1, 1};
string V = "LRUD";
for (int i = 0; i < 4; i++) {
int pon = i <= 1 ? X : Y;
int n = i <= 1 ? W : H;
for (int j = 0; j < N; j++) {
if (S[j] == V[i])
pon += d[i];
if (pon < 0 || pon >= n) {
cout << "NO" << endl;
return 0;
}
if (T[j] == V[i ^ 1]) {
pon -= d[i];
if (pon < 0 || pon >= n)
pon += d[i];
}
}
}
cout << "YES" << endl;
}
| [
"assignment.value.change",
"identifier.change",
"variable_access.subscript.index.change"
] | 869,944 | 869,945 | u524343822 | cpp |
p03054 | #include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
#define int long long
typedef pair<int, int> P;
int Y, X, h, w, n;
string s, t;
bool U() {
int y = Y;
r(i, n) {
if (s[i] == 'U')
y--;
if (y == 0)
return 1;
if (t[i] == 'D')
y++;
y = min(y, h);
}
return 0;
}
bool D() {
int y = Y;
r(i, n) {
if (s[i] == 'D')
y++;
if (y > h)
return 1;
if (t[i] == 'U')
y--;
y = max(y, 1LL);
}
return 0;
}
bool R() {
int x = X;
r(i, n) {
if (s[i] == 'R')
x++;
if (w < x)
return 1;
if (t[i] == 'L')
x--;
x = max(1LL, x);
}
return 0;
}
bool L() {
int x = X;
r(i, n) {
if (s[i] == 'L')
x--;
if (x == 0)
return 1;
if (t[i] == 'R')
x++;
x = min(w, x);
}
return 0;
}
signed main() {
cin >> h >> w >> n;
cin >> Y >> X;
cin >> s;
cin >> t;
if (U() || R() || D() || L())
cout << "No" << endl;
else
cout << "Yes" << endl;
} | #include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
#define int long long
typedef pair<int, int> P;
int Y, X, h, w, n;
string s, t;
bool U() {
int y = Y;
r(i, n) {
if (s[i] == 'U')
y--;
if (y == 0)
return 1;
if (t[i] == 'D')
y++;
y = min(y, h);
}
return 0;
}
bool D() {
int y = Y;
r(i, n) {
if (s[i] == 'D')
y++;
if (y > h)
return 1;
if (t[i] == 'U')
y--;
y = max(y, 1LL);
}
return 0;
}
bool R() {
int x = X;
r(i, n) {
if (s[i] == 'R')
x++;
if (w < x)
return 1;
if (t[i] == 'L')
x--;
x = max(1LL, x);
}
return 0;
}
bool L() {
int x = X;
r(i, n) {
if (s[i] == 'L')
x--;
if (x == 0)
return 1;
if (t[i] == 'R')
x++;
x = min(w, x);
}
return 0;
}
signed main() {
cin >> h >> w >> n;
cin >> Y >> X;
cin >> s;
cin >> t;
if (U() || R() || D() || L())
cout << "NO" << endl;
else
cout << "YES" << endl;
}
| [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 869,946 | 869,947 | u777468981 | cpp |
p03055 | #include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 1; i <= n; ++i)
#define all(x) begin(x), end(x)
#define show(obj) \
{ \
for (auto x : obj) \
cout << x << ' '; \
cout << endl; \
}
#define line "----------"
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int inf = 1001001000;
const ll INF = 1LL << 60;
const int MOD = (int)1e9 + 7;
vector<vector<int>> G(200100, vector<int>());
// UnweightedTree
// argument -> [Vertex_Size, Start_Node]
// return -> [Furthest_Node, Diameter]
P tree_diameter(int V, int st) {
int t = inf;
int diameter = -1;
queue<int> Q;
vector<int> dist(V, inf);
dist[st] = 0;
Q.push(st);
while (!Q.empty()) {
int f = Q.front();
Q.pop();
for (auto x : G[f]) {
if (dist[x] == inf) {
dist[x] = dist[f] + 1;
Q.push(x);
if (dist[x] > diameter) {
diameter = dist[x];
t = x;
}
}
}
}
return make_pair(t, diameter);
}
int main() {
int N;
cin >> N;
int a, b;
G.resize(N);
rep(i, N - 1) {
cin >> a >> b;
--a;
--b;
G[a].push_back(b);
G[b].push_back(a);
}
P x = tree_diameter(N, 0);
P y = tree_diameter(N, x.first);
int furthest_dist = y.second + 1;
cout << ((furthest_dist % 3 == 2) ? "Second" : "First") << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 1; i <= n; ++i)
#define all(x) begin(x), end(x)
#define show(obj) \
{ \
for (auto x : obj) \
cout << x << ' '; \
cout << endl; \
}
#define line "----------"
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int inf = 1001001000;
const ll INF = 1LL << 60;
const int MOD = (int)1e9 + 7;
vector<vector<int>> G(200100, vector<int>());
// UnweightedTree
// argument -> [Vertex_Size, Start_Node]
// return -> [Furthest_Node, Diameter]
P tree_diameter(int V, int st) {
int t = st;
int diameter = 0;
queue<int> Q;
vector<int> dist(V, inf);
dist[st] = 0;
Q.push(st);
while (!Q.empty()) {
int f = Q.front();
Q.pop();
for (auto x : G[f]) {
if (dist[x] == inf) {
dist[x] = dist[f] + 1;
Q.push(x);
if (dist[x] > diameter) {
diameter = dist[x];
t = x;
}
}
}
}
return make_pair(t, diameter);
}
int main() {
int N;
cin >> N;
int a, b;
G.resize(N);
rep(i, N - 1) {
cin >> a >> b;
--a;
--b;
G[a].push_back(b);
G[b].push_back(a);
}
P x = tree_diameter(N, 0);
P y = tree_diameter(N, x.first);
int furthest_dist = y.second + 1;
cout << ((furthest_dist % 3 == 2) ? "Second" : "First") << endl;
return 0;
}
| [
"variable_declaration.value.change",
"identifier.change",
"literal.number.change"
] | 869,965 | 869,966 | u190761897 | cpp |
p03055 | #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <assert.h>
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <climits>
#include <complex> // complex
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <iomanip> // setprecision
#include <iostream> // cout, endl, cin
#include <map> // map
#include <math.h>
#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
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// ---------------------------------------------------------------------------
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<vector<int>> G(N);
for (int i = 0; i < N - 1; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].emplace_back(b);
G[b].emplace_back(a);
}
auto bfs = [&](int root) {
vector<int> dist(N, -1);
queue<int> que;
que.emplace(root);
dist[root] = 0;
while (que.size()) {
int v = que.front();
que.pop();
for (int nv : G[v]) {
if (dist[nv] != -1)
continue;
dist[nv] = dist[v] + 1;
que.emplace(nv);
}
}
int id;
int mx = 0;
for (int i = 0; i < N; i++) {
if (chmax(mx, dist[i])) {
id = i;
}
}
return P(id, mx);
};
P p = bfs(0);
p = bfs(p.first);
if (p.second % 3 == 1) {
cout << "Second\n";
} else {
cout << "First\n";
}
return 0;
} | #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <assert.h>
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <climits>
#include <complex> // complex
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <iomanip> // setprecision
#include <iostream> // cout, endl, cin
#include <map> // map
#include <math.h>
#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
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// ---------------------------------------------------------------------------
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<vector<int>> G(N);
for (int i = 0; i < N - 1; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].emplace_back(b);
G[b].emplace_back(a);
}
auto bfs = [&](int root) {
vector<int> dist(N, -1);
queue<int> que;
que.emplace(root);
dist[root] = 0;
while (que.size()) {
int v = que.front();
que.pop();
for (int nv : G[v]) {
if (dist[nv] != -1)
continue;
dist[nv] = dist[v] + 1;
que.emplace(nv);
}
}
int id;
int mx = -1;
for (int i = 0; i < N; i++) {
if (chmax(mx, dist[i])) {
id = i;
}
}
return P(id, mx);
};
P p = bfs(0);
p = bfs(p.first);
if (p.second % 3 == 1) {
cout << "Second\n";
} else {
cout << "First\n";
}
return 0;
} | [
"literal.number.change",
"variable_declaration.value.change"
] | 869,971 | 869,972 | u550014122 | cpp |
p03055 | #include <bits/stdc++.h>
#include <random>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
#define int ll
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef pair<int, int> pii;
typedef pair<pii, pii> piii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for (int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;
#ifdef RUS_HOME
#define cerr cout
#else
#define cerr \
if (false) \
cerr
#endif
const double PI = 2 * acos(0.0);
#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";
template <class T0, class T1>
inline ostream &operator<<(ostream &out, pair<T0, T1> &a) {
return out << "{" << a.first << ", " << a.second << "}";
}
template <class T0, class T1>
inline istream &operator>>(istream &in, pair<T0, T1> &a) {
return in >> a.first >> a.second;
}
template <class T0, class T1, class T2>
inline ostream &operator<<(ostream &out, tuple<T0, T1, T2> &a) {
return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a)
<< "}";
}
template <class T0, class T1, class T2, class T3>
inline ostream &operator<<(ostream &out, tuple<T0, T1, T2, T3> &a) {
return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a)
<< ", " << get<3>(a) << "}";
}
template <class T> inline ostream &operator<<(ostream &out, vector<T> &a) {
out << "[";
fori(i, a.size()) out << a[i]
<< vector<string>{", ", "] "}[i + 1 == a.size()];
return out;
}
void smain();
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef RUS_HOME
freopen("input", "r", stdin);
clock_t start = clock();
#endif
cout << setprecision(12) << fixed;
smain();
#ifdef RUS_HOME
cout << "\n\n\n\nTOTAL EXECUTION TIME: "
<< float(clock() - start) / CLOCKS_PER_SEC << endl;
#endif
return 0;
}
const int N = 2e5 + 100;
vi g[N];
int d[N], otv[N];
void dfs(int v, int pr, int h) {
d[v] = h;
for (auto p : g[v]) {
if (p == pr)
continue;
dfs(p, v, d[v] + 1);
}
}
void smain() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
dfs(1, 1, 0);
int cur = 0, vert = 1;
for (int i = 1; i <= n; i++) {
if (d[i] > cur) {
cur = d[i];
vert = i;
}
}
dfs(vert, vert, 0);
cur = 0;
for (int i = 1; i <= n; i++) {
if (d[i] > cur) {
cur = d[i];
}
}
vi dp(cur + 1);
dp[0] = 1;
for (int i = 1; i <= cur; i++) {
if (dp[i - 1] == 2) {
dp[i] = 1;
continue;
}
if (i > 1 && dp[i - 2] == 2) {
dp[i] = 1;
continue;
}
dp[i] = 2;
}
if (dp[cur] == 1)
cout << "First";
else
cout << "Second";
} | #include <bits/stdc++.h>
#include <random>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
#define int ll
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef pair<int, int> pii;
typedef pair<pii, pii> piii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for (int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;
#ifdef RUS_HOME
#define cerr cout
#else
#define cerr \
if (false) \
cerr
#endif
const double PI = 2 * acos(0.0);
#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";
template <class T0, class T1>
inline ostream &operator<<(ostream &out, pair<T0, T1> &a) {
return out << "{" << a.first << ", " << a.second << "}";
}
template <class T0, class T1>
inline istream &operator>>(istream &in, pair<T0, T1> &a) {
return in >> a.first >> a.second;
}
template <class T0, class T1, class T2>
inline ostream &operator<<(ostream &out, tuple<T0, T1, T2> &a) {
return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a)
<< "}";
}
template <class T0, class T1, class T2, class T3>
inline ostream &operator<<(ostream &out, tuple<T0, T1, T2, T3> &a) {
return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a)
<< ", " << get<3>(a) << "}";
}
template <class T> inline ostream &operator<<(ostream &out, vector<T> &a) {
out << "[";
fori(i, a.size()) out << a[i]
<< vector<string>{", ", "] "}[i + 1 == a.size()];
return out;
}
void smain();
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef RUS_HOME
freopen("input", "r", stdin);
clock_t start = clock();
#endif
cout << setprecision(12) << fixed;
smain();
#ifdef RUS_HOME
cout << "\n\n\n\nTOTAL EXECUTION TIME: "
<< float(clock() - start) / CLOCKS_PER_SEC << endl;
#endif
return 0;
}
const int N = 2e5 + 100;
vi g[N];
int d[N], otv[N];
void dfs(int v, int pr, int h) {
d[v] = h;
for (auto p : g[v]) {
if (p == pr)
continue;
dfs(p, v, d[v] + 1);
}
}
void smain() {
int n;
cin >> n;
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
dfs(1, 1, 0);
int cur = 0, vert = 1;
for (int i = 1; i <= n; i++) {
if (d[i] > cur) {
cur = d[i];
vert = i;
}
}
dfs(vert, vert, 0);
cur = 0;
for (int i = 1; i <= n; i++) {
if (d[i] > cur) {
cur = d[i];
}
}
vi dp(cur + 1);
dp[0] = 1;
for (int i = 1; i <= cur; i++) {
if (dp[i - 1] == 2) {
dp[i] = 1;
continue;
}
if (i > 1 && dp[i - 2] == 2) {
dp[i] = 1;
continue;
}
dp[i] = 2;
}
if (dp[cur] == 1)
cout << "First";
else
cout << "Second";
} | [
"control_flow.loop.for.condition.change",
"misc.off_by_one"
] | 869,975 | 869,976 | u844213925 | cpp |
p03055 | #include <bits/stdc++.h>
#include <random>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
#define int ll
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef pair<int, int> pii;
typedef pair<pii, pii> piii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for (int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;
#ifdef RUS_HOME
#define cerr cout
#else
#define cerr \
if (false) \
cerr
#endif
const double PI = 2 * acos(0.0);
#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";
template <class T0, class T1>
inline ostream &operator<<(ostream &out, pair<T0, T1> &a) {
return out << "{" << a.first << ", " << a.second << "}";
}
template <class T0, class T1>
inline istream &operator>>(istream &in, pair<T0, T1> &a) {
return in >> a.first >> a.second;
}
template <class T0, class T1, class T2>
inline ostream &operator<<(ostream &out, tuple<T0, T1, T2> &a) {
return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a)
<< "}";
}
template <class T0, class T1, class T2, class T3>
inline ostream &operator<<(ostream &out, tuple<T0, T1, T2, T3> &a) {
return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a)
<< ", " << get<3>(a) << "}";
}
template <class T> inline ostream &operator<<(ostream &out, vector<T> &a) {
out << "[";
fori(i, a.size()) out << a[i]
<< vector<string>{", ", "] "}[i + 1 == a.size()];
return out;
}
void smain();
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef RUS_HOME
freopen("input", "r", stdin);
clock_t start = clock();
#endif
cout << setprecision(12) << fixed;
smain();
#ifdef RUS_HOME
cout << "\n\n\n\nTOTAL EXECUTION TIME: "
<< float(clock() - start) / CLOCKS_PER_SEC << endl;
#endif
return 0;
}
const int N = 1e5 + 100;
vi g[N];
int d[N], otv[N];
void dfs(int v, int pr, int h) {
d[v] = h;
for (auto p : g[v]) {
if (p == pr)
continue;
dfs(p, v, d[v] + 1);
}
}
void smain() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
dfs(1, 1, 0);
int cur = 0, vert = 1;
for (int i = 1; i <= n; i++) {
if (d[i] > cur) {
cur = d[i];
vert = i;
}
}
dfs(vert, vert, 0);
cur = 0;
for (int i = 1; i <= n; i++) {
if (d[i] > cur) {
cur = d[i];
}
}
vi dp(cur + 1);
dp[0] = 1;
for (int i = 1; i <= cur; i++) {
if (dp[i - 1] == 2) {
dp[i] = 1;
continue;
}
if (i > 1 && dp[i - 2] == 2) {
dp[i] = 1;
continue;
}
dp[i] = 2;
}
if (dp[cur] == 1)
cout << "First";
else
cout << "Second";
} | #include <bits/stdc++.h>
#include <random>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
#define int ll
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef pair<int, int> pii;
typedef pair<pii, pii> piii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for (int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;
#ifdef RUS_HOME
#define cerr cout
#else
#define cerr \
if (false) \
cerr
#endif
const double PI = 2 * acos(0.0);
#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";
template <class T0, class T1>
inline ostream &operator<<(ostream &out, pair<T0, T1> &a) {
return out << "{" << a.first << ", " << a.second << "}";
}
template <class T0, class T1>
inline istream &operator>>(istream &in, pair<T0, T1> &a) {
return in >> a.first >> a.second;
}
template <class T0, class T1, class T2>
inline ostream &operator<<(ostream &out, tuple<T0, T1, T2> &a) {
return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a)
<< "}";
}
template <class T0, class T1, class T2, class T3>
inline ostream &operator<<(ostream &out, tuple<T0, T1, T2, T3> &a) {
return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a)
<< ", " << get<3>(a) << "}";
}
template <class T> inline ostream &operator<<(ostream &out, vector<T> &a) {
out << "[";
fori(i, a.size()) out << a[i]
<< vector<string>{", ", "] "}[i + 1 == a.size()];
return out;
}
void smain();
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef RUS_HOME
freopen("input", "r", stdin);
clock_t start = clock();
#endif
cout << setprecision(12) << fixed;
smain();
#ifdef RUS_HOME
cout << "\n\n\n\nTOTAL EXECUTION TIME: "
<< float(clock() - start) / CLOCKS_PER_SEC << endl;
#endif
return 0;
}
const int N = 2e5 + 100;
vi g[N];
int d[N], otv[N];
void dfs(int v, int pr, int h) {
d[v] = h;
for (auto p : g[v]) {
if (p == pr)
continue;
dfs(p, v, d[v] + 1);
}
}
void smain() {
int n;
cin >> n;
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
dfs(1, 1, 0);
int cur = 0, vert = 1;
for (int i = 1; i <= n; i++) {
if (d[i] > cur) {
cur = d[i];
vert = i;
}
}
dfs(vert, vert, 0);
cur = 0;
for (int i = 1; i <= n; i++) {
if (d[i] > cur) {
cur = d[i];
}
}
vi dp(cur + 1);
dp[0] = 1;
for (int i = 1; i <= cur; i++) {
if (dp[i - 1] == 2) {
dp[i] = 1;
continue;
}
if (i > 1 && dp[i - 2] == 2) {
dp[i] = 1;
continue;
}
dp[i] = 2;
}
if (dp[cur] == 1)
cout << "First";
else
cout << "Second";
} | [
"literal.number.change",
"expression.operation.binary.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one"
] | 869,977 | 869,976 | u844213925 | cpp |
p03055 | #include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) \
for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) { cout << (expr ? "First" : "Second") << "\n"; }
struct Node;
vector<Node> V;
struct Node {
int idx;
vector<int> nbr;
bool vst = false;
int dist = 0;
void dfs(int d) {
dist = d + 1;
vst = true;
for (int x : nbr) {
if (!V[x].vst) {
V[x].dfs(dist);
}
}
};
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int N;
cin >> N;
REP(i, N) V.emplace_back();
REP(i, N - 1) {
int u, v;
cin >> u >> v;
u--;
v--;
V[u].nbr.push_back(v);
V[v].nbr.push_back(u);
}
V[0].dfs(0);
int maxd = 0;
int idx = -1;
REP(i, N) {
if (V[i].dist > maxd) {
maxd = V[i].dist;
idx = i;
}
V[i].dist = 0;
V[i].vst = false;
}
V[idx].dfs(0);
maxd = 0;
REP(i, N) if (V[i].dist > maxd) maxd = V[i].dist;
yes(maxd % 3 == 0);
} | #include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) \
for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) { cout << (expr ? "First" : "Second") << "\n"; }
struct Node;
vector<Node> V;
struct Node {
int idx;
vector<int> nbr;
bool vst = false;
int dist = 0;
void dfs(int d) {
dist = d + 1;
vst = true;
for (int x : nbr) {
if (!V[x].vst) {
V[x].dfs(dist);
}
}
};
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int N;
cin >> N;
REP(i, N) V.emplace_back();
REP(i, N - 1) {
int u, v;
cin >> u >> v;
u--;
v--;
V[u].nbr.push_back(v);
V[v].nbr.push_back(u);
}
V[0].dfs(0);
int maxd = 0;
int idx = -1;
REP(i, N) {
if (V[i].dist > maxd) {
maxd = V[i].dist;
idx = i;
}
V[i].dist = 0;
V[i].vst = false;
}
V[idx].dfs(0);
maxd = 0;
REP(i, N) if (V[i].dist > maxd) maxd = V[i].dist;
// cout << maxd << endl;
yes(maxd % 3 != 2);
} | [] | 869,988 | 869,989 | u914173586 | cpp |
p03055 | #include <bits/stdc++.h>
using namespace std;
class TreeDiameter {
public:
int V;
vector<vector<int>> G;
vector<int> diameter;
TreeDiameter(int node_size) : V(node_size), G(V) {}
void add(int u, int v) { G.at(u).push_back(v), G.at(v).push_back(u); }
void dfs(int u, int p, int d, int &far, int &mx) {
if (mx < d) {
far = u;
mx = d;
}
for (int v : G.at(u)) {
if (v != p) {
dfs(v, u, d + 1, far, mx);
}
}
}
bool redfs(int u, int p, const int t) {
if (u == t) {
return true;
}
for (int v : G.at(u)) {
if (v != p) {
diameter.push_back(v);
if (redfs(v, u, t)) {
return true;
} else {
diameter.pop_back();
}
}
}
return false;
}
void solve() {
int s, t, mx;
mx = -1;
dfs(0, -1, 0, s, mx);
mx = -1;
dfs(s, -1, 0, t, mx);
diameter.push_back(s);
redfs(s, -1, t);
}
};
int main() {
ios::sync_with_stdio(false);
int N;
cin >> N;
TreeDiameter TD(N);
for (int i = 0; i < N - 1; i++) {
int a, b;
cin >> a >> b;
TD.add(--a, --b);
}
TD.solve();
int D = TD.diameter.at(0);
cout << ((D % 3 == 1) ? "Second" : "First") << "\n";
} | #include <bits/stdc++.h>
using namespace std;
class TreeDiameter {
public:
int V;
vector<vector<int>> G;
vector<int> diameter;
TreeDiameter(int node_size) : V(node_size), G(V) {}
void add(int u, int v) { G.at(u).push_back(v), G.at(v).push_back(u); }
void dfs(int u, int p, int d, int &far, int &mx) {
if (mx < d) {
far = u;
mx = d;
}
for (int v : G.at(u)) {
if (v != p) {
dfs(v, u, d + 1, far, mx);
}
}
}
bool redfs(int u, int p, const int t) {
if (u == t) {
return true;
}
for (int v : G.at(u)) {
if (v != p) {
diameter.push_back(v);
if (redfs(v, u, t)) {
return true;
} else {
diameter.pop_back();
}
}
}
return false;
}
void solve() {
int s, t, mx;
mx = -1;
dfs(0, -1, 0, s, mx);
mx = -1;
dfs(s, -1, 0, t, mx);
diameter.push_back(s);
redfs(s, -1, t);
}
};
int main() {
ios::sync_with_stdio(false);
int N;
cin >> N;
TreeDiameter TD(N);
for (int i = 0; i < N - 1; i++) {
int a, b;
cin >> a >> b;
TD.add(--a, --b);
}
TD.solve();
int D = TD.diameter.size() - 1;
cout << ((D % 3 == 1) ? "Second" : "First") << "\n";
} | [
"call.function.change",
"call.arguments.change"
] | 869,995 | 869,996 | u045289115 | cpp |
p03055 | #include <algorithm>
#include <climits>
#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 vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef vector<vector<ll>> VVL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound
int main() {
int N;
cin >> N;
VI A(N - 1), B(N - 1);
rep(i, N - 1) cin >> A[i] >> B[i];
VVI X(N, VI());
rep(i, N - 1) {
X[A[i] - 1].pb(B[i] - 1);
X[B[i] - 1].pb(A[i] - 1);
}
VI D(N, -1);
D[0] = 0;
queue<int> Q;
Q.push(0);
while (!Q.empty()) {
int tmp = Q.front();
Q.pop();
rep(i, X[tmp].size()) {
if (D[X[tmp][i]] == -1) {
D[X[tmp][i]] = D[tmp] + 1;
Q.push(X[tmp][i]);
}
}
}
int Y = 0;
rep(i, N) if (D[Y] < D[i]) Y = i;
rep(i, N) D[i] = -1;
D[Y] = 0;
Q.push(Y);
while (!Q.empty()) {
int tmp = Q.front();
Q.pop();
rep(i, X[tmp].size()) {
if (D[X[tmp][i]] == -1) {
D[X[tmp][i]] = D[tmp] + 1;
Q.push(X[tmp][i]);
}
}
}
int L = 0;
rep(i, N) if (L < D[i]) L = D[i];
if ((L + 1) % 3 == 0)
cout << "First" << endl;
else
cout << "Second" << endl;
} | #include <algorithm>
#include <climits>
#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 vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef vector<vector<ll>> VVL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound
int main() {
int N;
cin >> N;
VI A(N - 1), B(N - 1);
rep(i, N - 1) cin >> A[i] >> B[i];
VVI X(N, VI());
rep(i, N - 1) {
X[A[i] - 1].pb(B[i] - 1);
X[B[i] - 1].pb(A[i] - 1);
}
VI D(N, -1);
D[0] = 0;
queue<int> Q;
Q.push(0);
while (!Q.empty()) {
int tmp = Q.front();
Q.pop();
rep(i, X[tmp].size()) {
if (D[X[tmp][i]] == -1) {
D[X[tmp][i]] = D[tmp] + 1;
Q.push(X[tmp][i]);
}
}
}
int Y = 0;
rep(i, N) if (D[Y] < D[i]) Y = i;
rep(i, N) D[i] = -1;
D[Y] = 0;
Q.push(Y);
while (!Q.empty()) {
int tmp = Q.front();
Q.pop();
rep(i, X[tmp].size()) {
if (D[X[tmp][i]] == -1) {
D[X[tmp][i]] = D[tmp] + 1;
Q.push(X[tmp][i]);
}
}
}
int L = 0;
rep(i, N) if (L < D[i]) L = D[i];
if (L % 3 != 1)
cout << "First" << endl;
else
cout << "Second" << endl;
}
| [
"control_flow.branch.if.condition.change",
"expression.operator.arithmetic.change"
] | 870,013 | 870,014 | u154756110 | cpp |
p03055 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(), (a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int, int>
#define priq priority_queue<int>
#define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (int)(key)))
#define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (int)(key)))
#define tii tuple<int, int, int>
#define Priq priority_queue<int, vi, greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll << 62) - 1
#define MAX 1000000000
signed main() {
int N;
cin >> N;
vii A(N);
rep(i, 1, N) {
int X, Y;
cin >> X >> Y;
A[X - 1].pb(Y - 1);
A[Y - 1].pb(X - 1);
}
vi F(N, -1);
F[0] = 0;
queue<int> Q;
Q.push(0);
Q.push(-1);
int cnt = 1;
while (Q.size() > 1) {
int X = Q.front();
Q.pop();
if (X == -1) {
cnt++;
Q.push(-1);
} else {
rep(i, 0, A[X].size()) {
int Y = A[X][i];
if (F[Y] == -1) {
F[Y] = cnt;
Q.push(Y);
}
}
}
}
int mem = 0, sum = 0;
int ans = 0;
rep(i, 0, N) {
if (F[i] > sum) {
sum = F[i];
mem = i;
}
}
Q.pop();
Q.push(mem);
Q.push(-1);
vector<bool> G(N, 1);
G[mem] = 0;
cnt = 0;
while (Q.size() > 1) {
int X = Q.front();
Q.pop();
if (X == -1) {
cnt++;
Q.push(-1);
} else {
rep(i, 0, A[X].size()) {
int Y = A[X][i];
if (G[Y]) {
G[Y] = 0;
Q.push(Y);
ans = max(ans, cnt);
}
}
}
}
if (ans % 3 == 0)
cout << "Second" << endl;
else
cout << "First" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(), (a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int, int>
#define priq priority_queue<int>
#define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (int)(key)))
#define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (int)(key)))
#define tii tuple<int, int, int>
#define Priq priority_queue<int, vi, greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll << 62) - 1
#define MAX 1000000000
signed main() {
int N;
cin >> N;
vii A(N);
rep(i, 1, N) {
int X, Y;
cin >> X >> Y;
A[X - 1].pb(Y - 1);
A[Y - 1].pb(X - 1);
}
vi F(N, -1);
F[0] = 0;
queue<int> Q;
Q.push(0);
Q.push(-1);
int cnt = 1;
while (Q.size() > 1) {
int X = Q.front();
Q.pop();
if (X == -1) {
cnt++;
Q.push(-1);
} else {
rep(i, 0, A[X].size()) {
int Y = A[X][i];
if (F[Y] == -1) {
F[Y] = cnt;
Q.push(Y);
}
}
}
}
int mem = 0, sum = 0;
int ans = 0;
rep(i, 0, N) {
if (F[i] > sum) {
sum = F[i];
mem = i;
}
}
Q.pop();
Q.push(mem);
Q.push(-1);
vector<bool> G(N, 1);
G[mem] = 0;
cnt = 1;
while (Q.size() > 1) {
int X = Q.front();
Q.pop();
if (X == -1) {
cnt++;
Q.push(-1);
} else {
rep(i, 0, A[X].size()) {
int Y = A[X][i];
if (G[Y]) {
G[Y] = 0;
Q.push(Y);
ans = max(ans, cnt);
}
}
}
}
if (ans % 3 == 1)
cout << "Second" << endl;
else
cout << "First" << endl;
}
| [
"literal.number.change",
"assignment.value.change",
"control_flow.branch.if.condition.change"
] | 870,017 | 870,018 | u347057617 | cpp |
p03055 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(), (a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int, int>
#define priq priority_queue<int>
#define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (int)(key)))
#define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (int)(key)))
#define tii tuple<int, int, int>
#define Priq priority_queue<int, vi, greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll << 62) - 1
#define MAX 1000000000
signed main() {
int N;
cin >> N;
vii A(N);
rep(i, 1, N) {
int X, Y;
cin >> X >> Y;
A[X - 1].pb(Y - 1);
A[Y - 1].pb(X - 1);
}
vi F(N, -1);
F[0] = 0;
queue<int> Q;
Q.push(0);
Q.push(-1);
int cnt = 1;
while (Q.size() > 1) {
int X = Q.front();
Q.pop();
if (X == -1) {
cnt++;
Q.push(-1);
} else {
rep(i, 0, A[X].size()) {
int Y = A[X][i];
if (F[Y] == -1) {
F[Y] = cnt;
Q.push(Y);
}
}
}
}
int mem = 0, sum = 0;
int ans = 0;
rep(i, 0, N) {
if (F[i] > sum) {
sum = F[i];
mem = i;
}
}
Q.pop();
Q.push(mem);
Q.push(-1);
vector<bool> G(N, 1);
G[mem] = 0;
cnt = 2;
while (Q.size() > 1) {
int X = Q.front();
Q.pop();
if (X == -1) {
cnt++;
Q.push(-1);
} else {
rep(i, 0, A[X].size()) {
int Y = A[X][i];
if (G[Y]) {
G[Y] = 0;
Q.push(Y);
ans = max(ans, cnt);
}
}
}
}
if (ans % 3 != 0)
cout << "Second" << endl;
else
cout << "First" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(), (a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int, int>
#define priq priority_queue<int>
#define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (int)(key)))
#define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (int)(key)))
#define tii tuple<int, int, int>
#define Priq priority_queue<int, vi, greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll << 62) - 1
#define MAX 1000000000
signed main() {
int N;
cin >> N;
vii A(N);
rep(i, 1, N) {
int X, Y;
cin >> X >> Y;
A[X - 1].pb(Y - 1);
A[Y - 1].pb(X - 1);
}
vi F(N, -1);
F[0] = 0;
queue<int> Q;
Q.push(0);
Q.push(-1);
int cnt = 1;
while (Q.size() > 1) {
int X = Q.front();
Q.pop();
if (X == -1) {
cnt++;
Q.push(-1);
} else {
rep(i, 0, A[X].size()) {
int Y = A[X][i];
if (F[Y] == -1) {
F[Y] = cnt;
Q.push(Y);
}
}
}
}
int mem = 0, sum = 0;
int ans = 0;
rep(i, 0, N) {
if (F[i] > sum) {
sum = F[i];
mem = i;
}
}
Q.pop();
Q.push(mem);
Q.push(-1);
vector<bool> G(N, 1);
G[mem] = 0;
cnt = 1;
while (Q.size() > 1) {
int X = Q.front();
Q.pop();
if (X == -1) {
cnt++;
Q.push(-1);
} else {
rep(i, 0, A[X].size()) {
int Y = A[X][i];
if (G[Y]) {
G[Y] = 0;
Q.push(Y);
ans = max(ans, cnt);
}
}
}
}
if (ans % 3 == 1)
cout << "Second" << endl;
else
cout << "First" << endl;
}
| [
"literal.number.change",
"assignment.value.change"
] | 870,019 | 870,018 | u347057617 | cpp |
p03055 | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
// const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> v) {
os << "(" << v.first << ", " << v.second << ")";
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> v) {
for (int i = 0; i < (int)v.size(); i++) {
if (i > 0) {
os << " ";
}
os << v[i];
}
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<vector<T>> v) {
for (int i = 0; i < (int)v.size(); i++) {
if (i > 0) {
os << endl;
}
os << v[i];
}
return os;
}
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// conversion number to bit
string num2bit(ll num, ll len) {
string bit = "";
REP(i, len) { bit += char('0' + (num >> i & 1)); }
return bit;
}
using Graph = vector<vector<ll>>;
pll dfs(ll now, ll par, Graph &G) {
pll res = {0, now};
for (auto next : G[now]) {
if (next == par)
continue;
auto cost = dfs(next, now, G);
cost.first++;
res = max(res, cost);
}
return res;
}
ll tree_diameter(Graph &G) {
auto p = dfs(0, -1, G);
auto q = dfs(p.second, -1, G);
// (p.second, q.second) is the diameter
return q.first;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin >> N;
Graph G(N);
REP(i, N - 1) {
ll a, b;
cin >> a >> b;
a--, b--;
G[a].push_back(b);
G[b].push_back(a);
}
ll d = tree_diameter(G);
if (d % 3 != 2) {
cout << "Second" << endl;
} else {
cout << "First" << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
// const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> v) {
os << "(" << v.first << ", " << v.second << ")";
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> v) {
for (int i = 0; i < (int)v.size(); i++) {
if (i > 0) {
os << " ";
}
os << v[i];
}
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<vector<T>> v) {
for (int i = 0; i < (int)v.size(); i++) {
if (i > 0) {
os << endl;
}
os << v[i];
}
return os;
}
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// conversion number to bit
string num2bit(ll num, ll len) {
string bit = "";
REP(i, len) { bit += char('0' + (num >> i & 1)); }
return bit;
}
using Graph = vector<vector<ll>>;
pll dfs(ll now, ll par, Graph &G) {
pll res = {0, now};
for (auto next : G[now]) {
if (next == par)
continue;
auto cost = dfs(next, now, G);
cost.first++;
res = max(res, cost);
}
return res;
}
ll tree_diameter(Graph &G) {
auto p = dfs(0, -1, G);
auto q = dfs(p.second, -1, G);
// (p.second, q.second) is the diameter
return q.first;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin >> N;
Graph G(N);
REP(i, N - 1) {
ll a, b;
cin >> a >> b;
a--, b--;
G[a].push_back(b);
G[b].push_back(a);
}
ll d = tree_diameter(G);
if (d % 3 == 1) {
cout << "Second" << endl;
} else {
cout << "First" << endl;
}
return 0;
} | [] | 870,036 | 870,037 | u895971408 | cpp |
p03055 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
ll mod = 1e9 + 7;
int main() {
ll n;
cin >> n;
vector<set<ll>> E(n);
for (ll i = 0; i < n - 1; i++) {
ll a, b;
cin >> a >> b;
a--;
b--;
E[a].insert(b);
E[b].insert(a);
}
vector<ll> d1(n, -1);
vector<ll> d2(n, -1);
queue<ll> q;
q.push(0);
d1[0] = 0;
while (q.size()) {
ll f = q.front();
q.pop();
for (ll t : E[f]) {
if (d1[t] < 0) {
d1[t] = d1[f] + 1;
q.push(t);
}
}
}
ll mx = 0, mi;
for (ll i = 0; i < n; i++) {
if (d1[i] > mx) {
mx = d1[i];
mi = i;
}
}
d2[mi] = 0;
q.push(mi);
while (q.size()) {
ll f = q.front();
q.pop();
for (ll t : E[f]) {
if (d2[t] < 0) {
d2[t] = d2[f] + 1;
q.push(t);
}
}
}
mx = 0;
for (ll i = 0; i < n; i++) {
mx = max(mx, d2[i]);
}
if (!mx % 3 == 2) {
cout << "Second" << endl;
} else {
cout << "First" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
ll mod = 1e9 + 7;
int main() {
ll n;
cin >> n;
vector<set<ll>> E(n);
for (ll i = 0; i < n - 1; i++) {
ll a, b;
cin >> a >> b;
a--;
b--;
E[a].insert(b);
E[b].insert(a);
}
vector<ll> d1(n, -1);
vector<ll> d2(n, -1);
queue<ll> q;
q.push(0);
d1[0] = 0;
while (q.size()) {
ll f = q.front();
q.pop();
for (ll t : E[f]) {
if (d1[t] < 0) {
d1[t] = d1[f] + 1;
q.push(t);
}
}
}
ll mx = 0, mi = 0;
for (ll i = 0; i < n; i++) {
if (d1[i] > mx) {
mx = d1[i];
mi = i;
}
}
d2[mi] = 0;
q.push(mi);
while (q.size()) {
ll f = q.front();
q.pop();
for (ll t : E[f]) {
if (d2[t] < 0) {
d2[t] = d2[f] + 1;
q.push(t);
}
}
}
mx = 0;
for (ll i = 0; i < n; i++) {
mx = max(mx, d2[i]);
}
if (mx % 3 == 1) {
cout << "Second" << endl;
} else {
cout << "First" << endl;
}
} | [
"variable_declaration.value.change",
"expression.operation.unary.logical.remove",
"control_flow.branch.if.condition.change",
"literal.number.change"
] | 870,042 | 870,041 | u718758485 | cpp |
p03055 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
struct Edge {
int to, w;
Edge(int t, int w) : to(t), w(w) {}
};
struct Tree {
int N;
vector<vector<Edge>> edges;
void addEdge(int a, int b) { addEdge(a, b, 1); }
void addEdge(int a, int b, int w) { edges[a].emplace_back(b, w); }
Tree(int N) : N(N), edges(N) {}
long long diam() {
setDist(0);
int start;
long long maxd = 0;
rep(i, N) {
if (dist[i] > maxd) {
maxd = dist[i];
start = i;
}
}
setDist(start);
rep(i, N) maxd = max(maxd, dist[i]);
return maxd;
}
vector<long long> dist;
void setDist(int s) {
dist = vector<long long>(N, -1);
dist[s] = 0;
queue<int> q;
q.push(s);
while (!q.empty()) {
int x = q.front();
q.pop();
for (Edge e : edges[x]) {
if (dist[e.to] != -1)
continue;
dist[e.to] = dist[x] + e.w;
q.push(e.to);
}
}
}
};
int main() {
int N;
cin >> N;
Tree G(N);
rep(i, N - 1) {
int x, y;
cin >> x >> y;
x--;
y--;
G.addEdge(x, y);
G.addEdge(y, x);
}
long long diam = G.diam();
if ((diam + 1) % 3 == 2)
cout << "Second" << endl;
else
cout << "First" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
struct Edge {
int to, w;
Edge(int t, int w) : to(t), w(w) {}
};
struct Tree {
int N;
vector<vector<Edge>> edges;
void addEdge(int a, int b) { addEdge(a, b, 1); }
void addEdge(int a, int b, int w) { edges[a].emplace_back(b, w); }
Tree(int N) : N(N), edges(N) {}
long long diam() {
setDist(0);
int start;
long long maxd = -1;
rep(i, N) {
if (dist[i] > maxd) {
maxd = dist[i];
start = i;
}
}
setDist(start);
rep(i, N) maxd = max(maxd, dist[i]);
return maxd;
}
vector<long long> dist;
void setDist(int s) {
dist = vector<long long>(N, -1);
dist[s] = 0;
queue<int> q;
q.push(s);
while (!q.empty()) {
int x = q.front();
q.pop();
for (Edge e : edges[x]) {
if (dist[e.to] != -1)
continue;
dist[e.to] = dist[x] + e.w;
q.push(e.to);
}
}
}
};
int main() {
int N;
cin >> N;
Tree G(N);
rep(i, N - 1) {
int x, y;
cin >> x >> y;
x--;
y--;
G.addEdge(x, y);
G.addEdge(y, x);
}
long long diam = G.diam();
if ((diam + 1) % 3 == 2)
cout << "Second" << endl;
else
cout << "First" << endl;
}
| [
"literal.number.change",
"variable_declaration.value.change"
] | 870,049 | 870,050 | u544437817 | cpp |
p03055 | #pragma GCC optimize("Ofast")
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define INF 1LL << 30
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;
// typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge {
ll to, cost, val;
};
template <class T, class U> bool chmin(T &a, const U &b) {
if (a <= b)
return false;
a = b;
return true;
}
template <class T, class U> bool chmax(T &a, const U &b) {
if (a >= b)
return false;
a = b;
return true;
}
//__builtin_popcount(S);
// C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int d[210000];
signed main(void) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<int> V[210000];
for (int i = 0; i < N - 1; i++) {
int a, b;
cin >> a >> b;
V[a].push_back(b);
V[b].push_back(a);
}
d[1] = 0;
queue<int> que;
que.push(1);
int t;
while (!que.empty()) {
int now = que.front();
que.pop();
for (int next : V[now]) {
if (d[next] == 0) {
d[next] = d[now] + 1;
t = next;
que.push(next);
}
}
}
for (int i = 0; i < 210000; i++)
d[0] = 0;
que.push(t);
int ans;
while (!que.empty()) {
int now = que.front();
que.pop();
for (int next : V[now]) {
if (d[next] == 0) {
d[next] = d[now] + 1;
t = next;
ans = d[next];
que.push(next);
}
}
}
ans++;
if (ans % 3 == 2)
cout << "Second" << endl;
else
cout << "First" << endl;
}
| #pragma GCC optimize("Ofast")
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define INF 1LL << 30
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;
// typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge {
ll to, cost, val;
};
template <class T, class U> bool chmin(T &a, const U &b) {
if (a <= b)
return false;
a = b;
return true;
}
template <class T, class U> bool chmax(T &a, const U &b) {
if (a >= b)
return false;
a = b;
return true;
}
//__builtin_popcount(S);
// C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int d[210000];
signed main(void) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<int> V[210000];
for (int i = 0; i < N - 1; i++) {
int a, b;
cin >> a >> b;
V[a].push_back(b);
V[b].push_back(a);
}
d[1] = 0;
queue<int> que;
que.push(1);
int t;
while (!que.empty()) {
int now = que.front();
que.pop();
for (int next : V[now]) {
if (d[next] == 0) {
d[next] = d[now] + 1;
t = next;
que.push(next);
}
}
}
for (int i = 0; i < 210000; i++)
d[i] = 0;
que.push(t);
int ans;
while (!que.empty()) {
int now = que.front();
que.pop();
for (int next : V[now]) {
if (d[next] == 0) {
d[next] = d[now] + 1;
t = next;
ans = d[next];
que.push(next);
}
}
}
ans++;
// cout<<ans<<endl;
if (ans % 3 == 2)
cout << "Second" << endl;
else
cout << "First" << endl;
}
| [
"assignment.variable.change",
"identifier.replace.add",
"literal.replace.remove",
"variable_access.subscript.index.change"
] | 870,057 | 870,058 | u591914971 | cpp |
p03055 | #pragma GCC optimize("Ofast")
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define INF 1LL << 30
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;
// typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge {
ll to, cost, val;
};
template <class T, class U> bool chmin(T &a, const U &b) {
if (a <= b)
return false;
a = b;
return true;
}
template <class T, class U> bool chmax(T &a, const U &b) {
if (a >= b)
return false;
a = b;
return true;
}
//__builtin_popcount(S);
// C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int d[210000];
signed main(void) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<int> V[210000];
for (int i = 0; i < N - 1; i++) {
int a, b;
cin >> a >> b;
V[a].push_back(b);
V[b].push_back(a);
}
d[1] = 0;
queue<int> que;
que.push(1);
int t;
while (!que.empty()) {
int now = que.front();
que.pop();
for (int next : V[now]) {
if (d[next] == 0) {
d[next] = d[now] + 1;
t = next;
que.push(next);
}
}
}
for (int i = 0; i < 210000; i++)
d[0] = 0;
que.push(t);
int ans;
while (!que.empty()) {
int now = que.front();
que.pop();
for (int next : V[now]) {
if (d[next] == 0) {
d[next] = d[now] + 1;
t = next;
ans = d[next];
que.push(next);
}
}
}
if (ans % 3 == 2)
cout << "Second" << endl;
else
cout << "First" << endl;
}
| #pragma GCC optimize("Ofast")
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define INF 1LL << 30
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;
// typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge {
ll to, cost, val;
};
template <class T, class U> bool chmin(T &a, const U &b) {
if (a <= b)
return false;
a = b;
return true;
}
template <class T, class U> bool chmax(T &a, const U &b) {
if (a >= b)
return false;
a = b;
return true;
}
//__builtin_popcount(S);
// C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int d[210000];
signed main(void) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<int> V[210000];
for (int i = 0; i < N - 1; i++) {
int a, b;
cin >> a >> b;
V[a].push_back(b);
V[b].push_back(a);
}
d[1] = 0;
queue<int> que;
que.push(1);
int t;
while (!que.empty()) {
int now = que.front();
que.pop();
for (int next : V[now]) {
if (d[next] == 0) {
d[next] = d[now] + 1;
t = next;
que.push(next);
}
}
}
for (int i = 0; i < 210000; i++)
d[i] = 0;
que.push(t);
int ans;
while (!que.empty()) {
int now = que.front();
que.pop();
for (int next : V[now]) {
if (d[next] == 0) {
d[next] = d[now] + 1;
t = next;
ans = d[next];
que.push(next);
}
}
}
ans++;
// cout<<ans<<endl;
if (ans % 3 == 2)
cout << "Second" << endl;
else
cout << "First" << endl;
}
| [
"assignment.variable.change",
"identifier.replace.add",
"literal.replace.remove",
"variable_access.subscript.index.change",
"expression.unary.arithmetic.add"
] | 870,059 | 870,058 | u591914971 | cpp |
p03055 | #include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#pragma GCC optimize("O3")
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPP(i, n) for (int i = 1; i <= n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
// const double PI = acos(-1);
// const double EPS = 1e-15;
// long long INF=(long long)1E17;
#define i_7 (long long)(1e9 + 7)
//#define i_7 998'244'353
long mod(long a) {
long long c = a % i_7;
if (c >= 0)
return c;
return c + i_7;
}
long long po(long a, long b) {
if (b == 0) {
return 1;
}
long long z = po(a, b / 2);
z = mod(z * z);
if (b % 2 != 0) {
z = mod(a * z);
}
return z;
}
using namespace std;
// using namespace boost::multiprecision;
bool prime_(int n) {
if (n == 1) {
return false;
} else if (n == 2) {
return true;
} else {
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
}
long long gcd_(long long a, long long b) {
if (a < b) {
swap(a, b);
}
if (a % b == 0) {
return b;
} else {
return gcd_(b, a % b);
}
}
long long lcm_(long long x, long long y) { return (x / gcd_(x, y)) * y; }
vector<int> G[200'010];
int dist[200'010];
void dfs(int v, int p) {
for (int nv : G[v]) {
if (nv == p) {
continue;
}
dist[nv] = dist[v] + 1;
dfs(nv, v);
}
return;
}
int main() {
int n;
cin >> n;
int a[n - 1], b[n - 1];
REP(i, n - 1) {
cin >> a[i] >> b[i];
a[i]--;
b[i]--;
G[a[i]].push_back(b[i]);
G[b[i]].push_back(a[i]);
}
dist[0] = 0;
dfs(0, -1);
int c;
int temp = 0;
REP(i, n) {
if (temp < dist[i]) {
c = i;
temp = dist[i];
}
}
dist[c] = 0;
dfs(c, -1);
int d = 0; //直径
REP(i, n) { d = max(d, dist[i]); }
if (d % 3 == 0) {
cout << "Second" << endl;
} else {
cout << "First" << endl;
}
return 0;
}
| #include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#pragma GCC optimize("O3")
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPP(i, n) for (int i = 1; i <= n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
// const double PI = acos(-1);
// const double EPS = 1e-15;
// long long INF=(long long)1E17;
#define i_7 (long long)(1e9 + 7)
//#define i_7 998'244'353
long mod(long a) {
long long c = a % i_7;
if (c >= 0)
return c;
return c + i_7;
}
long long po(long a, long b) {
if (b == 0) {
return 1;
}
long long z = po(a, b / 2);
z = mod(z * z);
if (b % 2 != 0) {
z = mod(a * z);
}
return z;
}
using namespace std;
// using namespace boost::multiprecision;
bool prime_(int n) {
if (n == 1) {
return false;
} else if (n == 2) {
return true;
} else {
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
}
long long gcd_(long long a, long long b) {
if (a < b) {
swap(a, b);
}
if (a % b == 0) {
return b;
} else {
return gcd_(b, a % b);
}
}
long long lcm_(long long x, long long y) { return (x / gcd_(x, y)) * y; }
vector<int> G[200'010];
int dist[200'010];
void dfs(int v, int p) {
for (int nv : G[v]) {
if (nv == p) {
continue;
}
dist[nv] = dist[v] + 1;
dfs(nv, v);
}
return;
}
int main() {
int n;
cin >> n;
int a[n - 1], b[n - 1];
REP(i, n - 1) {
cin >> a[i] >> b[i];
a[i]--;
b[i]--;
G[a[i]].push_back(b[i]);
G[b[i]].push_back(a[i]);
}
dist[0] = 0;
dfs(0, -1);
int c;
int temp = 0;
REP(i, n) {
if (temp < dist[i]) {
c = i;
temp = dist[i];
}
}
dist[c] = 0;
dfs(c, -1);
int d = 0; //直径
REP(i, n) { d = max(d, dist[i]); }
if (d % 3 == 1) {
cout << "Second" << endl;
} else {
cout << "First" << endl;
}
return 0;
}
| [
"literal.number.change",
"control_flow.branch.if.condition.change"
] | 870,060 | 870,061 | u222293734 | cpp |
p03055 | #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
#include "LOCAL_DEBUG.hpp"
#endif
#define int long long
struct edge {
int to, cost;
};
pair<int, int> dfs(const vector<vector<edge>> &g, int idx, int par) {
pair<int, int> ret(0, idx);
for (auto &e : g[idx]) {
if (e.to == par)
continue;
auto cost = dfs(g, e.to, idx);
cost.first += e.cost;
ret = max(ret, cost);
}
return ret;
}
int tree_diameter(const vector<vector<edge>> &g) {
auto p = dfs(g, 0, -1);
auto q = dfs(g, p.second, -1);
return (q.first);
}
signed main() {
int n;
cin >> n;
vector<vector<edge>> G(n);
for (int i = 0; i < n - 1; i++) {
int s, t;
cin >> s >> t;
s--, t--;
G[s].push_back({t, 1});
G[t].push_back({s, 1});
}
int res = tree_diameter(G);
if (res % 3 == 2) {
cout << "First" << endl;
} else {
cout << "Second" << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
#include "LOCAL_DEBUG.hpp"
#endif
#define int long long
struct edge {
int to, cost;
};
pair<int, int> dfs(const vector<vector<edge>> &g, int idx, int par) {
pair<int, int> ret(0, idx);
for (auto &e : g[idx]) {
if (e.to == par)
continue;
auto cost = dfs(g, e.to, idx);
cost.first += e.cost;
ret = max(ret, cost);
}
return ret;
}
int tree_diameter(const vector<vector<edge>> &g) {
auto p = dfs(g, 0, -1);
auto q = dfs(g, p.second, -1);
return (q.first);
}
signed main() {
int n;
cin >> n;
vector<vector<edge>> G(n);
for (int i = 0; i < n - 1; i++) {
int s, t;
cin >> s >> t;
s--, t--;
G[s].push_back({t, 1});
G[t].push_back({s, 1});
}
int res = tree_diameter(G);
if (res % 3 != 1) {
cout << "First" << endl;
} else {
cout << "Second" << endl;
}
return 0;
}
| [] | 870,064 | 870,065 | u344122377 | cpp |
p03055 | #include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define l first
#define r second
#define int long long
int n;
vector<int> graph[500000];
int d[500000];
int dp[500000];
signed main() {
cin >> n;
for (int i = 0; i < n - 1; i++) {
int v, u;
cin >> v >> u;
graph[v].push_back(u);
graph[u].push_back(v);
}
dp[1] = 1;
dp[2] = 2;
dp[3] = 1;
for (int i = 4; i < 500000; i++) {
if (dp[i - 1] == 2 || dp[i - 2] == 2)
dp[i] = 1;
else
dp[1] = 2;
}
d[1] = 1;
vector<int> q = {1};
for (int i = 0; i < q.size(); i++) {
for (int j = 0; j < graph[q[i]].size(); j++) {
int u = graph[q[i]][j];
if (d[u] == 0) {
d[u] = d[q[i]] + 1;
q.push_back(u);
}
}
}
int idmx = 0;
for (int i = 1; i <= n; i++)
if (d[i] >= d[idmx])
idmx = i;
fill(d, d + n + 1, 0);
d[idmx] = 1;
q = {idmx};
for (int i = 0; i < q.size(); i++) {
for (int j = 0; j < graph[q[i]].size(); j++) {
int u = graph[q[i]][j];
if (d[u] == 0) {
d[u] = d[q[i]] + 1;
q.push_back(u);
}
}
}
for (int i = 1; i <= n; i++)
if (d[i] >= d[idmx])
idmx = i;
if (dp[d[idmx]] == 1) {
cout << "First";
} else {
cout << "Second";
}
} | #include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define l first
#define r second
#define int long long
int n;
vector<int> graph[500000];
int d[500000];
int dp[500000];
signed main() {
cin >> n;
for (int i = 0; i < n - 1; i++) {
int v, u;
cin >> v >> u;
graph[v].push_back(u);
graph[u].push_back(v);
}
dp[1] = 1;
dp[2] = 2;
dp[3] = 1;
for (int i = 4; i < 500000; i++) {
if (dp[i - 1] == 2 || dp[i - 2] == 2)
dp[i] = 1;
else
dp[i] = 2;
}
d[1] = 1;
vector<int> q = {1};
for (int i = 0; i < q.size(); i++) {
for (int j = 0; j < graph[q[i]].size(); j++) {
int u = graph[q[i]][j];
if (d[u] == 0) {
d[u] = d[q[i]] + 1;
q.push_back(u);
}
}
}
int idmx = 0;
for (int i = 1; i <= n; i++)
if (d[i] >= d[idmx])
idmx = i;
fill(d, d + n + 1, 0);
d[idmx] = 1;
q = {idmx};
for (int i = 0; i < q.size(); i++) {
for (int j = 0; j < graph[q[i]].size(); j++) {
int u = graph[q[i]][j];
if (d[u] == 0) {
d[u] = d[q[i]] + 1;
q.push_back(u);
}
}
}
for (int i = 1; i <= n; i++)
if (d[i] >= d[idmx])
idmx = i;
if (dp[d[idmx]] == 1) {
cout << "First";
} else {
cout << "Second";
}
} | [
"assignment.variable.change",
"identifier.replace.add",
"literal.replace.remove",
"variable_access.subscript.index.change"
] | 870,068 | 870,069 | u798339690 | cpp |
p03055 | /*Unknown_Ghost*/
/*AGC033C Removing Coins*/
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
#define LL long long
#define MAXN 200000
#define MOD 998244353
#define Pr pair<int, int>
#define X first
#define Y second
#define mem(x, p) memset(x, p, sizeof(x))
LL read() {
LL x = 0, F = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
F = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (x << 3) + (x << 1) + c - '0';
c = getchar();
}
return x * F;
}
int add(int x, int y) { return (x + y >= MOD) ? x + y - MOD : x + y; }
int dec(int x, int y) { return (x - y < 0) ? x - y + MOD : x - y; }
int mul(int x, int y) { return 1LL * x * y % MOD; }
int n, D, pos;
vector<int> G[MAXN + 5];
void dfs(int x, int fa, int dis) {
if (dis > D) {
D = dis;
pos = x;
}
for (int i = 0; i < G[x].size(); i++) {
int nxt = G[x][i];
if (nxt == fa)
continue;
dfs(nxt, x, dis + 1);
}
}
int main() {
n = read();
for (int i = 1; i < n; i++) {
int u = read(), v = read();
G[u].push_back(v);
G[v].push_back(u);
}
dfs(1, 0, 1);
D = 0;
dfs(pos, 0, 1);
printf("%s", (D % 3) ? "Second" : "First");
}
| /*Unknown_Ghost*/
/*AGC033C Removing Coins*/
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
#define LL long long
#define MAXN 200000
#define MOD 998244353
#define Pr pair<int, int>
#define X first
#define Y second
#define mem(x, p) memset(x, p, sizeof(x))
LL read() {
LL x = 0, F = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
F = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (x << 3) + (x << 1) + c - '0';
c = getchar();
}
return x * F;
}
int add(int x, int y) { return (x + y >= MOD) ? x + y - MOD : x + y; }
int dec(int x, int y) { return (x - y < 0) ? x - y + MOD : x - y; }
int mul(int x, int y) { return 1LL * x * y % MOD; }
int n, D, pos;
vector<int> G[MAXN + 5];
void dfs(int x, int fa, int dis) {
if (dis > D) {
D = dis;
pos = x;
}
for (int i = 0; i < G[x].size(); i++) {
int nxt = G[x][i];
if (nxt == fa)
continue;
dfs(nxt, x, dis + 1);
}
}
int main() {
n = read();
for (int i = 1; i < n; i++) {
int u = read(), v = read();
G[u].push_back(v);
G[v].push_back(u);
}
dfs(1, 0, 1);
D = 0;
dfs(pos, 0, 1);
printf("%s", (D % 3 == 2) ? "Second" : "First");
}
| [
"expression.operation.binary.add"
] | 870,078 | 870,079 | u778193086 | cpp |
p03055 | #include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int N;
Graph G;
int Tree_Diameter(const Graph &G) {
int MAX_D = -1, node = 0;
vector<bool> seen(G.size(), false);
stack<pair<int, int>> sta;
sta.emplace(0, 0);
while (!sta.empty()) {
int dep, v;
tie(v, dep) = sta.top();
sta.pop();
seen[v] = true;
if (chmax(MAX_D, dep))
node = v;
for (auto e : G[v]) {
if (seen[e])
continue;
sta.emplace(e, dep + 1);
}
}
MAX_D = -1;
seen.assign(G.size(), false);
sta.emplace(node, 0);
while (!sta.empty()) {
int dep, v;
tie(v, dep) = sta.top();
sta.pop();
seen[v] = true;
chmax(MAX_D, dep);
for (auto e : G[v]) {
if (seen[e])
continue;
sta.emplace(e, dep + 1);
}
}
return MAX_D;
}
int main() {
int N;
cin >> N;
Graph G(N, vector<int>());
for (int i = 1; i < N; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].emplace_back(b);
G[b].emplace_back(a);
}
int R = Tree_Diameter(G);
if (R % 3 == 1) {
cout << "First" << endl;
} else {
cout << "Second" << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int N;
Graph G;
int Tree_Diameter(const Graph &G) {
int MAX_D = -1, node = 0;
vector<bool> seen(G.size(), false);
stack<pair<int, int>> sta;
sta.emplace(0, 0);
while (!sta.empty()) {
int dep, v;
tie(v, dep) = sta.top();
sta.pop();
seen[v] = true;
if (chmax(MAX_D, dep))
node = v;
for (auto e : G[v]) {
if (seen[e])
continue;
sta.emplace(e, dep + 1);
}
}
MAX_D = -1;
seen.assign(G.size(), false);
sta.emplace(node, 0);
while (!sta.empty()) {
int dep, v;
tie(v, dep) = sta.top();
sta.pop();
seen[v] = true;
chmax(MAX_D, dep);
for (auto e : G[v]) {
if (seen[e])
continue;
sta.emplace(e, dep + 1);
}
}
return MAX_D;
}
int main() {
int N;
cin >> N;
Graph G(N, vector<int>());
for (int i = 1; i < N; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].emplace_back(b);
G[b].emplace_back(a);
}
int R = Tree_Diameter(G);
if (R % 3 == 1) {
cout << "Second" << endl;
} else {
cout << "First" << endl;
}
return 0;
} | [
"literal.string.change",
"io.output.change"
] | 870,080 | 870,081 | u615258936 | cpp |
p03055 | #include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <unordered_map>
#include <vector>
#define mod 1000000007
using namespace std;
typedef long long ll;
bool chmax(ll &a, ll b) {
if (a > b)
return 0;
a = b;
return 1;
}
bool chmin(ll &a, ll b) {
if (a < b)
return 0;
a = b;
return 1;
}
#define mad(a, b) a = (a + b) % mod
#define mul(a, b) a = a * b % mod
ll n;
vector<ll> g[200010];
ll ma, pnt;
void dfs(ll x, ll from, ll d) {
if (d > ma)
ma = d, pnt = x;
for (auto y : g[x])
if (y != from) {
dfs(y, x, d + 1);
}
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
ll a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
ma = -1;
dfs(1, 0, 0);
dfs(pnt, 0, 0);
if (ma % 3 != 1)
cout << "First" << endl;
else
cout << "second" << endl;
}
| #include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <unordered_map>
#include <vector>
#define mod 1000000007
using namespace std;
typedef long long ll;
bool chmax(ll &a, ll b) {
if (a > b)
return 0;
a = b;
return 1;
}
bool chmin(ll &a, ll b) {
if (a < b)
return 0;
a = b;
return 1;
}
#define mad(a, b) a = (a + b) % mod
#define mul(a, b) a = a * b % mod
ll n;
vector<ll> g[200010];
ll ma, pnt;
void dfs(ll x, ll from, ll d) {
if (d >= ma)
ma = d, pnt = x;
for (auto y : g[x])
if (y != from) {
dfs(y, x, d + 1);
}
}
int main() {
cin >> n;
for (int i = 0; i < n - 1; i++) {
ll a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
ma = -1;
dfs(1, 0, 0);
dfs(pnt, 0, 0);
if (ma % 3 != 1)
cout << "First" << endl;
else
cout << "Second" << endl;
}
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one",
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 870,088 | 870,087 | u924885571 | cpp |
p03055 | #include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <unordered_map>
#include <vector>
#define mod 1000000007
using namespace std;
typedef long long ll;
bool chmax(ll &a, ll b) {
if (a > b)
return 0;
a = b;
return 1;
}
bool chmin(ll &a, ll b) {
if (a < b)
return 0;
a = b;
return 1;
}
#define mad(a, b) a = (a + b) % mod
#define mul(a, b) a = a * b % mod
ll n;
vector<ll> g[100010];
ll ma, pnt;
void dfs(ll x, ll from, ll d) {
if (d > ma)
ma = d, pnt = x;
for (auto y : g[x])
if (y != from) {
dfs(y, x, d + 1);
}
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
ll a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
ma = -1;
dfs(1, 0, 0);
dfs(pnt, 0, 0);
if (ma % 3 != 1)
cout << "First" << endl;
else
cout << "second" << endl;
}
| #include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <unordered_map>
#include <vector>
#define mod 1000000007
using namespace std;
typedef long long ll;
bool chmax(ll &a, ll b) {
if (a > b)
return 0;
a = b;
return 1;
}
bool chmin(ll &a, ll b) {
if (a < b)
return 0;
a = b;
return 1;
}
#define mad(a, b) a = (a + b) % mod
#define mul(a, b) a = a * b % mod
ll n;
vector<ll> g[200010];
ll ma, pnt;
void dfs(ll x, ll from, ll d) {
if (d >= ma)
ma = d, pnt = x;
for (auto y : g[x])
if (y != from) {
dfs(y, x, d + 1);
}
}
int main() {
cin >> n;
for (int i = 0; i < n - 1; i++) {
ll a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
ma = -1;
dfs(1, 0, 0);
dfs(pnt, 0, 0);
if (ma % 3 != 1)
cout << "First" << endl;
else
cout << "Second" << endl;
}
| [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one",
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 870,089 | 870,087 | u924885571 | cpp |
p03055 | #include <algorithm> // minmax, sort, swap
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <cstdio> // printf, scanf
#include <deque> // deque
#include <functional> // std::function<void(int)>
#include <iomanip> // cout<<setprecision(n)
#include <iostream> // cin, cout, cerr, clog
#include <map> // key-value pairs sorted by keys
#include <numeric> // iota, accumulate, inner_product
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, stoi, to_string
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <vector> // vector
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'
#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */
signed main() {
int n;
std::cin >> n;
std::vector<std::vector<int>> t(n, std::vector<int>());
rep(i, n - 1) {
int a, b;
std::cin >> a >> b;
a--;
b--;
t[a].emplace_back(b);
t[b].emplace_back(a);
}
int v; // maxi
int fmaxd = 0; // first max
std::vector<int> went(n, 0);
std::function<void(int, int)> dfs = [&](int i, int d) {
went[i] = true;
if (fmaxd < d) {
fmaxd = d;
v = i;
}
for (auto to : t[i]) {
if (!went[to]) {
dfs(to, d + 1);
}
}
};
dfs(0, 0);
rep(i, n) went[i] = false;
dfs(v, 0);
if (fmaxd % 3 == 1) {
print("Second");
} else {
print("First");
}
return 0;
}
| #include <algorithm> // minmax, sort, swap
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <cstdio> // printf, scanf
#include <deque> // deque
#include <functional> // std::function<void(int)>
#include <iomanip> // cout<<setprecision(n)
#include <iostream> // cin, cout, cerr, clog
#include <map> // key-value pairs sorted by keys
#include <numeric> // iota, accumulate, inner_product
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, stoi, to_string
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <vector> // vector
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'
#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */
signed main() {
int n;
std::cin >> n;
std::vector<std::vector<int>> t(n, std::vector<int>());
rep(i, n - 1) {
int a, b;
std::cin >> a >> b;
a--;
b--;
t[a].emplace_back(b);
t[b].emplace_back(a);
}
int v = 0; // maxi
int fmaxd = 0; // first max
std::vector<int> went(n, 0);
std::function<void(int, int)> dfs = [&](int i, int d) {
went[i] = true;
if (fmaxd < d) {
fmaxd = d;
v = i;
}
for (auto to : t[i]) {
if (!went[to]) {
dfs(to, d + 1);
}
}
};
dfs(0, 0);
rep(i, n) went[i] = false;
dfs(v, 0);
if (fmaxd % 3 == 1) {
print("Second");
} else {
print("First");
}
return 0;
}
| [
"variable_declaration.value.change"
] | 870,090 | 870,091 | u128456980 | cpp |
p03055 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
vector<vector<int>> g;
P bfs(int s) {
vector<int> dist(g.size(), -1);
queue<int> que;
que.push(s);
dist[s] = 0;
while (!que.empty()) {
int v = que.front();
que.pop();
for (auto u : g[v]) {
if (dist[u] != -1)
continue;
dist[u] = dist[v] + 1;
que.push(u);
}
}
int dmax = 0, idx = -1;
for (int i = 0; i < int(g.size()); i++) {
if (dist[i] > dmax) {
dmax = dist[i];
idx = i;
}
}
return P(idx, dmax);
}
int main() {
int n;
cin >> n;
g.resize(n);
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].push_back(b);
g[b].push_back(a);
}
int u = 0, v, dmax = 0;
for (int i = 0; i < 3; i++) {
auto p = bfs(u);
v = u;
u = p.first;
dmax = p.second;
}
cout << (dmax % 3 == 0 ? "Second" : "First") << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
vector<vector<int>> g;
P bfs(int s) {
vector<int> dist(g.size(), -1);
queue<int> que;
que.push(s);
dist[s] = 0;
while (!que.empty()) {
int v = que.front();
que.pop();
for (auto u : g[v]) {
if (dist[u] != -1)
continue;
dist[u] = dist[v] + 1;
que.push(u);
}
}
int dmax = 0, idx = -1;
for (int i = 0; i < int(g.size()); i++) {
if (dist[i] > dmax) {
dmax = dist[i];
idx = i;
}
}
return P(idx, dmax);
}
int main() {
int n;
cin >> n;
g.resize(n);
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].push_back(b);
g[b].push_back(a);
}
int u = 0, v, dmax = 0;
for (int i = 0; i < 10; i++) {
auto p = bfs(u);
v = u;
u = p.first;
dmax = p.second;
}
cout << (dmax % 3 == 1 ? "Second" : "First") << endl;
return 0;
} | [
"literal.number.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change",
"expression.off_by_one",
"io.output.change"
] | 870,092 | 870,093 | u271063202 | cpp |
p03055 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
vector<vector<int>> g(n);
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].push_back(b);
g[b].push_back(a);
}
vector<int> d(n);
for (int i = 0; i < n; i++) {
d[i] = -1;
}
function<void(int)> dfs = [&](int v) {
for (int nx : g[v]) {
if (d[nx] != -1)
continue;
d[nx] = d[v] + 1;
dfs(nx);
}
};
d[0] = 0;
dfs(0);
int pos = 0;
int ma = 0;
for (int i = 0; i < n; i++) {
if (ma < d[i]) {
ma = d[i];
pos = i;
}
}
for (int i = 0; i < n; i++) {
d[i] = -1;
}
d[pos] = 0;
dfs(pos);
ma = 0;
pos = 0;
for (int i = 0; i < n; i++) {
if (ma < d[i]) {
ma = d[i];
pos = i;
}
}
ma++;
if (ma % 3 == 2) {
cout << "Second" << endl;
} else {
cout << "First" << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
vector<vector<int>> g(n);
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].push_back(b);
g[b].push_back(a);
}
vector<int> d(n);
for (int i = 0; i < n; i++) {
d[i] = -1;
}
function<void(int)> dfs = [&](int v) {
for (int nx : g[v]) {
if (d[nx] != -1)
continue;
d[nx] = d[v] + 1;
dfs(nx);
}
};
d[0] = 0;
dfs(0);
int pos = 0;
int ma = 0;
for (int i = 0; i < n; i++) {
if (ma < d[i]) {
ma = d[i];
pos = i;
}
}
for (int i = 0; i < n; i++) {
d[i] = -1;
}
d[pos] = 0;
dfs(pos);
ma = 0;
pos = 0;
for (int i = 0; i < n; i++) {
if (ma < d[i]) {
ma = d[i];
pos = i;
}
}
ma++;
if (ma % 3 == 2) {
cout << "Second" << endl;
} else {
cout << "First" << endl;
}
}
| [
"control_flow.loop.for.condition.change",
"misc.off_by_one"
] | 870,096 | 870,097 | u410878763 | cpp |
p03055 | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define int long long
using namespace std;
typedef long double ld;
typedef unsigned int ui;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tiii;
typedef unsigned long long ull;
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const int INF = 1e18;
const int M = 1e9 + 7;
//__int128
const int maxn = 3e5;
std::vector<int> G[maxn];
int len;
int d[maxn];
int bfs(int x) {
queue<int> q;
q.push(x);
memset(d, 0, sizeof(d));
int res = 0;
d[x] = 1;
bitset<maxn> vis;
vis[x] = 1;
while (!q.empty()) {
int u = q.front();
q.pop();
for (auto i : G[u]) {
if (!vis[i]) {
q.push(i);
vis[i] = 1;
d[i] = d[u] + 1;
if (d[i] > len) {
res = i;
len = d[i];
}
}
}
}
return res;
}
signed main() {
// freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 1; i < n; ++i) {
int u, v;
cin >> u >> v;
G[u].eb(v);
G[v].eb(u);
}
int x = bfs(1);
bfs(x);
bitset<maxn> sg;
sg[1] = 1;
for (int i = 3; i <= len; ++i) {
sg[i] = !(sg[i - 1] && sg[i - 2]);
}
if (sg[len]) {
cout << "First" << endl;
} else {
cout << "Second" << endl;
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define int long long
using namespace std;
typedef long double ld;
typedef unsigned int ui;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tiii;
typedef unsigned long long ull;
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const int INF = 1e18;
const int M = 1e9 + 7;
//__int128
const int maxn = 3e5;
std::vector<int> G[maxn];
int len = 1;
int d[maxn];
int bfs(int x) {
queue<int> q;
q.push(x);
memset(d, 0, sizeof(d));
int res = 0;
d[x] = 1;
bitset<maxn> vis;
vis[x] = 1;
while (!q.empty()) {
int u = q.front();
q.pop();
for (auto i : G[u]) {
if (!vis[i]) {
q.push(i);
vis[i] = 1;
d[i] = d[u] + 1;
if (d[i] > len) {
res = i;
len = d[i];
}
}
}
}
return res;
}
signed main() {
// freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 1; i < n; ++i) {
int u, v;
cin >> u >> v;
G[u].eb(v);
G[v].eb(u);
}
int x = bfs(1);
bfs(x);
bitset<maxn> sg;
sg[1] = 1;
for (int i = 3; i <= len; ++i) {
sg[i] = !(sg[i - 1] && sg[i - 2]);
}
if (sg[len]) {
cout << "First" << endl;
} else {
cout << "Second" << endl;
}
return 0;
} | [
"variable_declaration.value.change"
] | 870,110 | 870,111 | u778948914 | cpp |
p03055 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <type_traits>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007; //良く出てくるMOD
constexpr ll INF = 1050000000; // intで使うでかい数
constexpr ll LONGINF = 1050000000000000000; // longlongで使うでかい数
const int nCk_MAX = 510000; // nCkの前計算で使うかもしれない 普段は入ってないよ
struct all_init {
//初期化のためだけの構造体
//コンストラクタが呼ばれ、cin,cout高速化がされる
//ついでに少数も出力できるようにしている
all_init() {
cout.tie(nullptr);
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
};
} ALL_INIT;
struct edge {
//辺の重みを管理できるような構造体
//コンストラクタによって簡単に値を入れられるようにしている
// operatorは辺の重みでソート出来るようにしている
int from, to;
ll cost;
ll capa;
edge(int s, int d) : from(s), to(d) {
cost = 0;
capa = 0;
}
edge(int s, int d, ll w) : from(s), to(d), cost(w) { capa = 0; }
edge(int s, int d, ll x, ll y) : from(s), to(d), cost(x), capa(y) {}
bool operator<(const edge &x) const { return cost < x.cost; }
};
#define CIN(vector_array_etc, n) \
for (int loop = 0; loop < n; loop++) { \
cin >> vector_array_etc[loop]; \
}
#define COUT(vector_array_etc, n) \
for (int LOOP = 0; LOOP < n; LOOP++) { \
cout << vector_array_etc[LOOP] << (LOOP == n - 1 ? '\n' : ' '); \
}
#define VC(Type_name) vector<Type_name> // 1次元ならあまり意味ないかも
#define VCVC(Type_name) vector<vector<Type_name>> // 2次元配列定義怠過ぎ問題
#define SORT(vector_etc) sort(vector_etc.begin(), vector_etc.end())
#define ALL(vec_etc) vec_etc.begin(), vec_etc.end()
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
} // aに最大値が入る
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
} // aに最小値が入る
template <typename T> istream &operator>>(istream &is, vector<T> &Vec) {
for (T &x : Vec) {
is >> x;
}
return is;
}
template <typename V, typename H> void resize(vector<V> &vec, const H head) {
vec.resize(head);
}
template <typename V, typename H, typename... T>
void resize(vector<V> &vec, const H &head, const T... tail) {
vec.resize(head);
for (auto &v : vec) {
resize(v, tail...);
}
}
int dx[] = {0, 1, -1, 0, 1, -1, 1, -1}; // i<4:4way i<8:8way
int dy[] = {1, 0, 0, -1, 1, -1, -1, 1};
ll PowMod(ll n, ll k, ll mod) {
//繰り返し2乗法
// n^kをmodで求める
ll r = 1;
for (; k > 0; k >>= 1) {
if (k & 1) {
r = (r * n) % mod;
}
n = (n * n) % mod;
}
return r;
}
ll Gcd(ll a, ll b) { //最大公約数
return b != 0 ? Gcd(b, a % b) : a;
}
ll Lcm(ll a, ll b) { //最小公倍数
return a / Gcd(a, b) * b;
}
bool isPrime(ll n) {
//素数かどうかを判定
// true 素数
if (n < 2)
return false;
for (ll i = 2; i * i <= n; i++)
if (!(n % i))
return false;
return true;
}
ll MergeCount(vector<int> &a) {
//反転数を数える
ll count = 0;
int n = a.size();
if (n > 1) {
vector<int> b(a.begin(), a.begin() + n / 2);
vector<int> c(a.begin() + n / 2, a.end());
count += MergeCount(b);
count += MergeCount(c);
for (int i = 0, j = 0, k = 0; i < n; ++i)
if (k == c.size())
a[i] = b[j++];
else if (j == b.size())
a[i] = c[k++];
else if (b[j] <= c[k])
a[i] = b[j++];
else {
a[i] = c[k++];
count += n / 2 - j;
}
}
return count;
}
bool WarshallFloyd(vector<vector<ll>> &c, int V) {
//ワーシャルフロイド法
//全ての頂点間の最短距離を求める
// falseの時、負の閉路検出
for (int i = 0; i < V; i++) {
c[i][i] = 0;
}
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
for (int k = 0; k < V; k++) {
if (c[j][k] > c[j][i] + c[i][k]) {
c[j][k] = c[j][i] + c[i][k];
}
}
}
}
for (int i = 0; i < V; i++) {
if (c[i][i] < 0) {
return false;
}
}
return true;
}
vector<ll> Dijkstra(int i, vector<vector<edge>> graph) {
// i:始点
// graph:重み付きグラフ
int n = graph.size();
vector<ll> d(n, LONGINF);
d[i] = 0;
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>>
q;
q.push(make_pair(0, i)); //第一引数:コスト 第二引数:頂点
while (!q.empty()) {
pair<ll, int> p = q.top();
q.pop();
int v = p.second;
if (d[v] < p.first) {
continue;
}
for (auto x : graph[v]) {
if (d[x.to] > d[v] + x.cost) {
d[x.to] = d[v] + x.cost;
q.push(make_pair(d[x.to], x.to));
}
}
}
return d;
}
bool BellmanFord(int start, int E, int V, vector<edge> Edge, vector<ll> &d) {
//第一引数:start 始点
//第二引数:E 辺の数
//第三引数:V 頂点数
//第四引数:Edge 辺の重み付きのグラフ
//第五引数:d 各頂点への距離を入れる配列(答えが入る)
fill(d.begin(), d.end(), LONGINF);
d[start] = 0;
vector<bool> t(V, false);
/*
for (int i = 0; i < V - 1; i++) {
for (int j = 0; j < E; j++) {
edge e = Edge[j];
if (d[e.from] == LONGINF) { continue; }
if (d[e.to] > d[e.from] + e.cost) {
d[e.to] = d[e.from] + e.cost;
}
}
}
*/
for (int i = 0; i < V; i++) {
for (int j = 0; j < E; j++) {
edge e = Edge[j];
if (d[e.from] == LONGINF) {
continue;
}
if (d[e.to] > d[e.from] + e.cost) {
d[e.to] = d[e.from] + e.cost;
t[e.to] = true;
if (i == V - 1) { //どこかに閉路があることを感知する
return false;
}
}
if (t[e.from]) {
t[e.to] = true;
}
}
}
/*
if (t[V - 1]) {
//V-1は頂点番号n-1で、始点からn-1までに負の閉路を検出したい場合には、
//コメントアウトを解除すること。
return false;
}
*/
return true;
}
bool TopologicalSort(const vector<vector<edge>> &g, vector<int> &ans) {
//トポロジカルソート
// trueが帰る時、トポロジカルソートが成功し、その結果がansに渡される
// falseはトポロジカルソートの失敗
int n = g.size(), k = 0;
vector<int> ord(n), in(n);
for (auto &es : g) {
for (auto &e : es) {
in[e.to]++;
}
}
queue<int> q;
for (int i = 0; i < n; ++i) {
if (in[i] == 0)
q.push(i);
}
while (!q.empty()) {
int v = q.front();
q.pop();
ord[k++] = v;
for (auto &e : g[v]) {
if (--in[e.to] == 0)
q.push(e.to);
}
}
ans = ord;
if (*max_element(in.begin(), in.end()) == 0) {
return true;
}
return false;
}
vector<int> ArticulationNode(const vector<vector<edge>> &g) {
//グラフの関節点を列挙する
//最後の2行で、erace
//uniqueをしない場合は、その分割によって何個のグラフに分かれるかを判定できる(要チェック)。
int n = g.size(), idx;
vector<int> low(n), ord(n), art;
function<void(int)> DFS = [&](int v) {
low[v] = ord[v] = ++idx;
for (auto &e : g[v]) {
int w = e.to;
if (ord[w] == 0) {
DFS(w);
low[v] = min(low[v], low[w]);
if ((ord[v] == 1 && ord[w] != 2) || (ord[v] != 1 && low[w] >= ord[v])) {
art.push_back(v);
}
} else {
low[v] = min(low[v], ord[w]);
}
}
};
for (int u = 0; u < n; u++) {
if (ord[u] == 0) {
idx = 0;
DFS(u);
}
}
sort(art.begin(), art.end()); //与えられた関節点をソート
art.erase(unique(art.begin(), art.end()),
art.end()); //同じ関節点が複数存在することがある,
return art;
}
edge TreeDiameter(const vector<vector<edge>> &g) {
//重み付きグラフ(木)を受け取り、その木の直径を求める
//返り値はfrom,to,costを持った構造体
int start = 0; //どの始点から始めても良いので、0から始める
static const auto bfs = [](const vector<vector<edge>> &g, int s,
queue<int> &q, vector<ll> &dist) {
while (!q.empty()) {
q.pop();
}
q.push(s);
int n = g.size();
dist.assign(n, LONGINF);
dist[s] = 0;
while (q.size()) {
int u = q.front();
q.pop();
for (auto &e : g[u]) {
int v = e.to;
if (dist[v] == LONGINF) {
dist[v] = dist[u] + e.cost;
q.push(v);
}
}
}
return dist;
};
vector<ll> dist;
queue<int> q;
bfs(g, start, q, dist);
int n = g.size(), u = -1, v = -1;
for (int i = 0; i < n; i++)
if (dist[i] != LONGINF && (u == -1 || dist[i] > dist[u]))
u = i;
bfs(g, u, q, dist);
for (int i = 0; i < n; i++)
if (dist[i] != LONGINF && (v == -1 || dist[i] > dist[v]))
v = i;
ll d = dist[v];
if (u > v)
swap(u, v); //念のため辞書順
return edge(u, v, d);
}
class UnionFind {
// satanicさん作 UnionFind
//追加機能:forest forestは、全体に含まれる木の数を表す
private:
std::vector<int> parent;
std::vector<int> height;
std::vector<int> m_size;
int forest_num;
public:
UnionFind(int size_) : parent(size_), height(size_, 0), m_size(size_, 1) {
forest_num = size_;
for (int i = 0; i < size_; ++i)
parent[i] = i;
}
void init(int size_) {
parent.resize(size_);
height.resize(size_, 0);
m_size.resize(size_, 1);
forest_num = size_;
for (int i = 0; i < size_; ++i)
parent[i] = i;
}
int find(int x) {
if (parent[x] == x)
return x;
return parent[x] = find(parent[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return;
int t = size(x) + size(y);
m_size[x] = m_size[y] = t;
if (height[x] < height[y])
parent[x] = y;
else
parent[y] = x;
if (height[x] == height[y])
++height[x];
forest_num--;
}
bool same(int x, int y) { return find(x) == find(y); }
int size(int x) {
if (parent[x] == x)
return m_size[x];
return size(parent[x] = find(parent[x]));
}
int forest() { return forest_num; }
};
class Dinic {
//最大流を求める
private:
int n, s, t;
vector<int> level, prog, que;
vector<vector<ll>> cap, flow;
vector<vector<int>> g;
ll inf;
public:
Dinic(const vector<vector<edge>> &graph)
: n(graph.size()), cap(n, vector<ll>(n)), //
flow(n, vector<ll>(n)), g(n, vector<int>()), inf(LONGINF) {
for (int i = 0; i < n; i++) {
for (auto &e : graph[i]) {
int u = e.from, v = e.to;
ll c = e.capa;
cap[u][v] += c;
cap[v][u] += c;
flow[v][u] += c;
g[u].push_back(v);
g[v].push_back(u);
}
}
}
inline ll residue(int u, int v) { return cap[u][v] - flow[u][v]; }
ll solve(int s_, int t_) {
this->t = t_, this->s = s_;
que.resize(n + 1);
ll res = 0;
while (levelize()) {
prog.assign(n, 0);
res += augment(s, inf);
}
return res;
}
bool levelize() {
int l = 0, r = 0;
level.assign(n, -1);
level[s] = 0;
que[r++] = s;
while (l != r) {
int v = que[l++];
if (v == t)
break;
for (const int &d : g[v])
if (level[d] == -1 && residue(v, d) != 0) {
level[d] = level[v] + 1;
que[r++] = d;
}
}
return level[t] != -1;
}
ll augment(int v, ll lim) {
ll res = 0;
if (v == t)
return lim;
for (int &i = prog[v]; i < (int)g[v].size(); i++) {
const int &d = g[v][i];
if (residue(v, d) == 0 || level[v] >= level[d])
continue;
const ll aug = augment(d, min(lim, residue(v, d)));
flow[v][d] += aug;
flow[d][v] -= aug;
res += aug;
lim -= aug;
if (lim == 0)
break;
}
return res;
}
};
class MinimumCostFlow {
private:
using Flow = ll;
using Cost = ll;
struct Edge {
int d;
Flow c, f;
Cost w;
int r, is_r;
Edge(int d_, Flow c_, Flow f_, Cost w_, int r_, bool is_r_)
: d(d_), c(c_), f(f_), w(w_), r(r_), is_r(is_r_) {}
};
int n;
vector<vector<Edge>> g;
public:
MinimumCostFlow(int n_) : n(n_), g(vector<vector<Edge>>(n_)) {}
void add_edge(int src, int dst, Flow cap, Cost cost) { // 有向辺
int rsrc = g[dst].size();
int rdst = g[src].size();
g[src].emplace_back(dst, cap, 0, cost, rsrc, false);
g[dst].emplace_back(src, cap, cap, -cost, rdst, true);
}
Cost solve(int s, int t, Flow f) {
Cost res = 0;
vector<Cost> h(n + 10), dist(n);
vector<int> prevv(n + 10), preve(n + 10);
using pcv = pair<Cost, int>;
priority_queue<pcv, vector<pcv>, greater<pcv>> q;
fill(h.begin(), h.end(), 0);
while (f > 0) {
fill(dist.begin(), dist.end(), LONGINF);
dist[s] = 0;
q.emplace(0, s);
while (q.size()) {
Cost cd;
int v;
tie(cd, v) = q.top();
q.pop();
if (dist[v] < cd)
continue;
for (int i = 0; i < (int)(g[v].size()); ++i) {
Edge &e = g[v][i];
if (residue(e) == 0)
continue;
if (dist[e.d] + h[e.d] > cd + h[v] + e.w) {
dist[e.d] = dist[v] + e.w + h[v] - h[e.d];
prevv[e.d] = v;
preve[e.d] = i;
q.emplace(dist[e.d], e.d);
}
}
}
if (dist[t] == LONGINF)
return -1; // 経路が見つからなかった
// s-t 間を最短路に沿って目一杯流す
for (int i = 0; i < n; ++i)
h[i] += dist[i];
Flow d = f;
for (int v = t; v != s; v = prevv[v]) {
chmin(d, residue(g[prevv[v]][preve[v]]));
}
f -= d;
res += d * h[t];
for (int v = t; v != s; v = prevv[v]) {
Edge &e = g[prevv[v]][preve[v]];
e.f += d;
g[v][e.r].f -= d;
}
}
return res;
}
Flow residue(const Edge &e) { return e.c - e.f; }
// 流量を表示
void show() {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < (int)(g[i].size()); ++j) {
Edge &e = g[i][j];
if (e.is_r)
continue;
cout << i << "->" << e.d << "(flow:" << e.f << ")" << endl;
}
}
}
};
class BipartiteMatching {
private:
int V;
vector<int> match;
vector<bool> used;
vector<vector<int>> g;
vector<pair<int, int>> match_pair;
bool dfs(int v) {
used[v] = true;
for (int i = 0; i < (int)g[v].size(); i++) {
int u = g[v][i];
int w = match[u];
if (w < 0 || !used[w] && dfs(w)) {
match[v] = u;
match[u] = v;
match_pair.emplace_back(make_pair(u, v));
return true;
}
}
return false;
}
public:
BipartiteMatching(int n) {
V = n;
resize(match, n);
resize(used, n);
resize(g, n);
}
void add_edge(int u, int v) {
g[u].emplace_back(v);
g[v].emplace_back(u);
}
int MatchingSolve() {
int res = 0;
fill(match.begin(), match.end(), -1);
for (int v = 0; v < V; v++) {
if (match[v] < 0) {
fill(used.begin(), used.end(), false);
if (dfs(v)) {
res++;
}
}
}
return res;
}
vector<pair<int, int>> get_pair() {
for (auto x : match_pair) {
cout << x.first << " " << x.second << endl;
}
return match_pair;
}
};
class Lca {
private:
int n;
int log2_n;
vector<vector<int>> parent;
vector<int> depth;
void dfs(const vector<vector<edge>> &g, int v, int p, int d) {
parent[0][v] = p;
depth[v] = d;
for (auto &e : g[v]) {
if (e.to != p) {
dfs(g, e.to, v, d + 1);
}
}
}
public:
Lca(const vector<vector<edge>> &g, int root) {
n = g.size();
log2_n = (int)log2(n) + 1;
resize(parent, log2_n, n);
resize(depth, n);
dfs(g, root, -1, 0);
for (int k = 0; k + 1 < log2_n; k++) {
for (int v = 0; v < (int)g.size(); v++) {
if (parent[k][v] < 0) {
parent[k + 1][v] = -1;
} else {
parent[k + 1][v] = parent[k][parent[k][v]];
}
}
}
}
int get_lca(int u, int v) {
if (depth[u] > depth[v]) {
swap(u, v);
} // u≦v
for (int k = 0; k < log2_n; k++) {
if ((depth[v] - depth[u]) >> k & 1) {
v = parent[k][v];
}
}
if (u == v) {
return u;
}
for (int k = log2_n - 1; k >= 0; k--) {
if (parent[k][u] != parent[k][v]) {
u = parent[k][u];
v = parent[k][v];
}
}
return parent[0][u];
}
int get_depth(int v) { return depth[v]; }
};
vector<vector<edge>> to_roottree(const vector<vector<edge>> &g, int r) {
int n = g.size();
vector<vector<edge>> G(n);
vector<int> ord(n, -1);
queue<int> q;
q.push(r);
int k = 0;
while (q.size()) {
int u = q.front();
q.pop();
for (auto &e : g[u]) {
int v = e.to;
if (ord[v] == -1) {
ord[v] = k;
k++;
q.push(v);
G[u].emplace_back(e);
}
}
}
return G;
}
int main() {
int n;
cin >> n;
vector<vector<edge>> g(n);
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].emplace_back(a, b, 1);
g[b].emplace_back(b, a, 1);
}
int check = TreeDiameter(g).cost;
if (check % 3 == 0) {
cout << "Second" << endl;
} else if (check % 3 == 1) {
cout << "First" << endl;
} else {
cout << "First" << endl;
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <type_traits>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007; //良く出てくるMOD
constexpr ll INF = 1050000000; // intで使うでかい数
constexpr ll LONGINF = 1050000000000000000; // longlongで使うでかい数
const int nCk_MAX = 510000; // nCkの前計算で使うかもしれない 普段は入ってないよ
struct all_init {
//初期化のためだけの構造体
//コンストラクタが呼ばれ、cin,cout高速化がされる
//ついでに少数も出力できるようにしている
all_init() {
cout.tie(nullptr);
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
};
} ALL_INIT;
struct edge {
//辺の重みを管理できるような構造体
//コンストラクタによって簡単に値を入れられるようにしている
// operatorは辺の重みでソート出来るようにしている
int from, to;
ll cost;
ll capa;
edge(int s, int d) : from(s), to(d) {
cost = 0;
capa = 0;
}
edge(int s, int d, ll w) : from(s), to(d), cost(w) { capa = 0; }
edge(int s, int d, ll x, ll y) : from(s), to(d), cost(x), capa(y) {}
bool operator<(const edge &x) const { return cost < x.cost; }
};
#define CIN(vector_array_etc, n) \
for (int loop = 0; loop < n; loop++) { \
cin >> vector_array_etc[loop]; \
}
#define COUT(vector_array_etc, n) \
for (int LOOP = 0; LOOP < n; LOOP++) { \
cout << vector_array_etc[LOOP] << (LOOP == n - 1 ? '\n' : ' '); \
}
#define VC(Type_name) vector<Type_name> // 1次元ならあまり意味ないかも
#define VCVC(Type_name) vector<vector<Type_name>> // 2次元配列定義怠過ぎ問題
#define SORT(vector_etc) sort(vector_etc.begin(), vector_etc.end())
#define ALL(vec_etc) vec_etc.begin(), vec_etc.end()
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
} // aに最大値が入る
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
} // aに最小値が入る
template <typename T> istream &operator>>(istream &is, vector<T> &Vec) {
for (T &x : Vec) {
is >> x;
}
return is;
}
template <typename V, typename H> void resize(vector<V> &vec, const H head) {
vec.resize(head);
}
template <typename V, typename H, typename... T>
void resize(vector<V> &vec, const H &head, const T... tail) {
vec.resize(head);
for (auto &v : vec) {
resize(v, tail...);
}
}
int dx[] = {0, 1, -1, 0, 1, -1, 1, -1}; // i<4:4way i<8:8way
int dy[] = {1, 0, 0, -1, 1, -1, -1, 1};
ll PowMod(ll n, ll k, ll mod) {
//繰り返し2乗法
// n^kをmodで求める
ll r = 1;
for (; k > 0; k >>= 1) {
if (k & 1) {
r = (r * n) % mod;
}
n = (n * n) % mod;
}
return r;
}
ll Gcd(ll a, ll b) { //最大公約数
return b != 0 ? Gcd(b, a % b) : a;
}
ll Lcm(ll a, ll b) { //最小公倍数
return a / Gcd(a, b) * b;
}
bool isPrime(ll n) {
//素数かどうかを判定
// true 素数
if (n < 2)
return false;
for (ll i = 2; i * i <= n; i++)
if (!(n % i))
return false;
return true;
}
ll MergeCount(vector<int> &a) {
//反転数を数える
ll count = 0;
int n = a.size();
if (n > 1) {
vector<int> b(a.begin(), a.begin() + n / 2);
vector<int> c(a.begin() + n / 2, a.end());
count += MergeCount(b);
count += MergeCount(c);
for (int i = 0, j = 0, k = 0; i < n; ++i)
if (k == c.size())
a[i] = b[j++];
else if (j == b.size())
a[i] = c[k++];
else if (b[j] <= c[k])
a[i] = b[j++];
else {
a[i] = c[k++];
count += n / 2 - j;
}
}
return count;
}
bool WarshallFloyd(vector<vector<ll>> &c, int V) {
//ワーシャルフロイド法
//全ての頂点間の最短距離を求める
// falseの時、負の閉路検出
for (int i = 0; i < V; i++) {
c[i][i] = 0;
}
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
for (int k = 0; k < V; k++) {
if (c[j][k] > c[j][i] + c[i][k]) {
c[j][k] = c[j][i] + c[i][k];
}
}
}
}
for (int i = 0; i < V; i++) {
if (c[i][i] < 0) {
return false;
}
}
return true;
}
vector<ll> Dijkstra(int i, vector<vector<edge>> graph) {
// i:始点
// graph:重み付きグラフ
int n = graph.size();
vector<ll> d(n, LONGINF);
d[i] = 0;
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>>
q;
q.push(make_pair(0, i)); //第一引数:コスト 第二引数:頂点
while (!q.empty()) {
pair<ll, int> p = q.top();
q.pop();
int v = p.second;
if (d[v] < p.first) {
continue;
}
for (auto x : graph[v]) {
if (d[x.to] > d[v] + x.cost) {
d[x.to] = d[v] + x.cost;
q.push(make_pair(d[x.to], x.to));
}
}
}
return d;
}
bool BellmanFord(int start, int E, int V, vector<edge> Edge, vector<ll> &d) {
//第一引数:start 始点
//第二引数:E 辺の数
//第三引数:V 頂点数
//第四引数:Edge 辺の重み付きのグラフ
//第五引数:d 各頂点への距離を入れる配列(答えが入る)
fill(d.begin(), d.end(), LONGINF);
d[start] = 0;
vector<bool> t(V, false);
/*
for (int i = 0; i < V - 1; i++) {
for (int j = 0; j < E; j++) {
edge e = Edge[j];
if (d[e.from] == LONGINF) { continue; }
if (d[e.to] > d[e.from] + e.cost) {
d[e.to] = d[e.from] + e.cost;
}
}
}
*/
for (int i = 0; i < V; i++) {
for (int j = 0; j < E; j++) {
edge e = Edge[j];
if (d[e.from] == LONGINF) {
continue;
}
if (d[e.to] > d[e.from] + e.cost) {
d[e.to] = d[e.from] + e.cost;
t[e.to] = true;
if (i == V - 1) { //どこかに閉路があることを感知する
return false;
}
}
if (t[e.from]) {
t[e.to] = true;
}
}
}
/*
if (t[V - 1]) {
//V-1は頂点番号n-1で、始点からn-1までに負の閉路を検出したい場合には、
//コメントアウトを解除すること。
return false;
}
*/
return true;
}
bool TopologicalSort(const vector<vector<edge>> &g, vector<int> &ans) {
//トポロジカルソート
// trueが帰る時、トポロジカルソートが成功し、その結果がansに渡される
// falseはトポロジカルソートの失敗
int n = g.size(), k = 0;
vector<int> ord(n), in(n);
for (auto &es : g) {
for (auto &e : es) {
in[e.to]++;
}
}
queue<int> q;
for (int i = 0; i < n; ++i) {
if (in[i] == 0)
q.push(i);
}
while (!q.empty()) {
int v = q.front();
q.pop();
ord[k++] = v;
for (auto &e : g[v]) {
if (--in[e.to] == 0)
q.push(e.to);
}
}
ans = ord;
if (*max_element(in.begin(), in.end()) == 0) {
return true;
}
return false;
}
vector<int> ArticulationNode(const vector<vector<edge>> &g) {
//グラフの関節点を列挙する
//最後の2行で、erace
//uniqueをしない場合は、その分割によって何個のグラフに分かれるかを判定できる(要チェック)。
int n = g.size(), idx;
vector<int> low(n), ord(n), art;
function<void(int)> DFS = [&](int v) {
low[v] = ord[v] = ++idx;
for (auto &e : g[v]) {
int w = e.to;
if (ord[w] == 0) {
DFS(w);
low[v] = min(low[v], low[w]);
if ((ord[v] == 1 && ord[w] != 2) || (ord[v] != 1 && low[w] >= ord[v])) {
art.push_back(v);
}
} else {
low[v] = min(low[v], ord[w]);
}
}
};
for (int u = 0; u < n; u++) {
if (ord[u] == 0) {
idx = 0;
DFS(u);
}
}
sort(art.begin(), art.end()); //与えられた関節点をソート
art.erase(unique(art.begin(), art.end()),
art.end()); //同じ関節点が複数存在することがある,
return art;
}
edge TreeDiameter(const vector<vector<edge>> &g) {
//重み付きグラフ(木)を受け取り、その木の直径を求める
//返り値はfrom,to,costを持った構造体
int start = 0; //どの始点から始めても良いので、0から始める
static const auto bfs = [](const vector<vector<edge>> &g, int s,
queue<int> &q, vector<ll> &dist) {
while (!q.empty()) {
q.pop();
}
q.push(s);
int n = g.size();
dist.assign(n, LONGINF);
dist[s] = 0;
while (q.size()) {
int u = q.front();
q.pop();
for (auto &e : g[u]) {
int v = e.to;
if (dist[v] == LONGINF) {
dist[v] = dist[u] + e.cost;
q.push(v);
}
}
}
return dist;
};
vector<ll> dist;
queue<int> q;
bfs(g, start, q, dist);
int n = g.size(), u = -1, v = -1;
for (int i = 0; i < n; i++)
if (dist[i] != LONGINF && (u == -1 || dist[i] > dist[u]))
u = i;
bfs(g, u, q, dist);
for (int i = 0; i < n; i++)
if (dist[i] != LONGINF && (v == -1 || dist[i] > dist[v]))
v = i;
ll d = dist[v];
if (u > v)
swap(u, v); //念のため辞書順
return edge(u, v, d);
}
class UnionFind {
// satanicさん作 UnionFind
//追加機能:forest forestは、全体に含まれる木の数を表す
private:
std::vector<int> parent;
std::vector<int> height;
std::vector<int> m_size;
int forest_num;
public:
UnionFind(int size_) : parent(size_), height(size_, 0), m_size(size_, 1) {
forest_num = size_;
for (int i = 0; i < size_; ++i)
parent[i] = i;
}
void init(int size_) {
parent.resize(size_);
height.resize(size_, 0);
m_size.resize(size_, 1);
forest_num = size_;
for (int i = 0; i < size_; ++i)
parent[i] = i;
}
int find(int x) {
if (parent[x] == x)
return x;
return parent[x] = find(parent[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return;
int t = size(x) + size(y);
m_size[x] = m_size[y] = t;
if (height[x] < height[y])
parent[x] = y;
else
parent[y] = x;
if (height[x] == height[y])
++height[x];
forest_num--;
}
bool same(int x, int y) { return find(x) == find(y); }
int size(int x) {
if (parent[x] == x)
return m_size[x];
return size(parent[x] = find(parent[x]));
}
int forest() { return forest_num; }
};
class Dinic {
//最大流を求める
private:
int n, s, t;
vector<int> level, prog, que;
vector<vector<ll>> cap, flow;
vector<vector<int>> g;
ll inf;
public:
Dinic(const vector<vector<edge>> &graph)
: n(graph.size()), cap(n, vector<ll>(n)), //
flow(n, vector<ll>(n)), g(n, vector<int>()), inf(LONGINF) {
for (int i = 0; i < n; i++) {
for (auto &e : graph[i]) {
int u = e.from, v = e.to;
ll c = e.capa;
cap[u][v] += c;
cap[v][u] += c;
flow[v][u] += c;
g[u].push_back(v);
g[v].push_back(u);
}
}
}
inline ll residue(int u, int v) { return cap[u][v] - flow[u][v]; }
ll solve(int s_, int t_) {
this->t = t_, this->s = s_;
que.resize(n + 1);
ll res = 0;
while (levelize()) {
prog.assign(n, 0);
res += augment(s, inf);
}
return res;
}
bool levelize() {
int l = 0, r = 0;
level.assign(n, -1);
level[s] = 0;
que[r++] = s;
while (l != r) {
int v = que[l++];
if (v == t)
break;
for (const int &d : g[v])
if (level[d] == -1 && residue(v, d) != 0) {
level[d] = level[v] + 1;
que[r++] = d;
}
}
return level[t] != -1;
}
ll augment(int v, ll lim) {
ll res = 0;
if (v == t)
return lim;
for (int &i = prog[v]; i < (int)g[v].size(); i++) {
const int &d = g[v][i];
if (residue(v, d) == 0 || level[v] >= level[d])
continue;
const ll aug = augment(d, min(lim, residue(v, d)));
flow[v][d] += aug;
flow[d][v] -= aug;
res += aug;
lim -= aug;
if (lim == 0)
break;
}
return res;
}
};
class MinimumCostFlow {
private:
using Flow = ll;
using Cost = ll;
struct Edge {
int d;
Flow c, f;
Cost w;
int r, is_r;
Edge(int d_, Flow c_, Flow f_, Cost w_, int r_, bool is_r_)
: d(d_), c(c_), f(f_), w(w_), r(r_), is_r(is_r_) {}
};
int n;
vector<vector<Edge>> g;
public:
MinimumCostFlow(int n_) : n(n_), g(vector<vector<Edge>>(n_)) {}
void add_edge(int src, int dst, Flow cap, Cost cost) { // 有向辺
int rsrc = g[dst].size();
int rdst = g[src].size();
g[src].emplace_back(dst, cap, 0, cost, rsrc, false);
g[dst].emplace_back(src, cap, cap, -cost, rdst, true);
}
Cost solve(int s, int t, Flow f) {
Cost res = 0;
vector<Cost> h(n + 10), dist(n);
vector<int> prevv(n + 10), preve(n + 10);
using pcv = pair<Cost, int>;
priority_queue<pcv, vector<pcv>, greater<pcv>> q;
fill(h.begin(), h.end(), 0);
while (f > 0) {
fill(dist.begin(), dist.end(), LONGINF);
dist[s] = 0;
q.emplace(0, s);
while (q.size()) {
Cost cd;
int v;
tie(cd, v) = q.top();
q.pop();
if (dist[v] < cd)
continue;
for (int i = 0; i < (int)(g[v].size()); ++i) {
Edge &e = g[v][i];
if (residue(e) == 0)
continue;
if (dist[e.d] + h[e.d] > cd + h[v] + e.w) {
dist[e.d] = dist[v] + e.w + h[v] - h[e.d];
prevv[e.d] = v;
preve[e.d] = i;
q.emplace(dist[e.d], e.d);
}
}
}
if (dist[t] == LONGINF)
return -1; // 経路が見つからなかった
// s-t 間を最短路に沿って目一杯流す
for (int i = 0; i < n; ++i)
h[i] += dist[i];
Flow d = f;
for (int v = t; v != s; v = prevv[v]) {
chmin(d, residue(g[prevv[v]][preve[v]]));
}
f -= d;
res += d * h[t];
for (int v = t; v != s; v = prevv[v]) {
Edge &e = g[prevv[v]][preve[v]];
e.f += d;
g[v][e.r].f -= d;
}
}
return res;
}
Flow residue(const Edge &e) { return e.c - e.f; }
// 流量を表示
void show() {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < (int)(g[i].size()); ++j) {
Edge &e = g[i][j];
if (e.is_r)
continue;
cout << i << "->" << e.d << "(flow:" << e.f << ")" << endl;
}
}
}
};
class BipartiteMatching {
private:
int V;
vector<int> match;
vector<bool> used;
vector<vector<int>> g;
vector<pair<int, int>> match_pair;
bool dfs(int v) {
used[v] = true;
for (int i = 0; i < (int)g[v].size(); i++) {
int u = g[v][i];
int w = match[u];
if (w < 0 || !used[w] && dfs(w)) {
match[v] = u;
match[u] = v;
match_pair.emplace_back(make_pair(u, v));
return true;
}
}
return false;
}
public:
BipartiteMatching(int n) {
V = n;
resize(match, n);
resize(used, n);
resize(g, n);
}
void add_edge(int u, int v) {
g[u].emplace_back(v);
g[v].emplace_back(u);
}
int MatchingSolve() {
int res = 0;
fill(match.begin(), match.end(), -1);
for (int v = 0; v < V; v++) {
if (match[v] < 0) {
fill(used.begin(), used.end(), false);
if (dfs(v)) {
res++;
}
}
}
return res;
}
vector<pair<int, int>> get_pair() {
for (auto x : match_pair) {
cout << x.first << " " << x.second << endl;
}
return match_pair;
}
};
class Lca {
private:
int n;
int log2_n;
vector<vector<int>> parent;
vector<int> depth;
void dfs(const vector<vector<edge>> &g, int v, int p, int d) {
parent[0][v] = p;
depth[v] = d;
for (auto &e : g[v]) {
if (e.to != p) {
dfs(g, e.to, v, d + 1);
}
}
}
public:
Lca(const vector<vector<edge>> &g, int root) {
n = g.size();
log2_n = (int)log2(n) + 1;
resize(parent, log2_n, n);
resize(depth, n);
dfs(g, root, -1, 0);
for (int k = 0; k + 1 < log2_n; k++) {
for (int v = 0; v < (int)g.size(); v++) {
if (parent[k][v] < 0) {
parent[k + 1][v] = -1;
} else {
parent[k + 1][v] = parent[k][parent[k][v]];
}
}
}
}
int get_lca(int u, int v) {
if (depth[u] > depth[v]) {
swap(u, v);
} // u≦v
for (int k = 0; k < log2_n; k++) {
if ((depth[v] - depth[u]) >> k & 1) {
v = parent[k][v];
}
}
if (u == v) {
return u;
}
for (int k = log2_n - 1; k >= 0; k--) {
if (parent[k][u] != parent[k][v]) {
u = parent[k][u];
v = parent[k][v];
}
}
return parent[0][u];
}
int get_depth(int v) { return depth[v]; }
};
vector<vector<edge>> to_roottree(const vector<vector<edge>> &g, int r) {
int n = g.size();
vector<vector<edge>> G(n);
vector<int> ord(n, -1);
queue<int> q;
q.push(r);
int k = 0;
while (q.size()) {
int u = q.front();
q.pop();
for (auto &e : g[u]) {
int v = e.to;
if (ord[v] == -1) {
ord[v] = k;
k++;
q.push(v);
G[u].emplace_back(e);
}
}
}
return G;
}
int main() {
int n;
cin >> n;
vector<vector<edge>> g(n);
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].emplace_back(a, b, 1);
g[b].emplace_back(b, a, 1);
}
int check = TreeDiameter(g).cost;
// cout << check % 3 << endl;
if (check % 3 == 0) {
cout << "First" << endl;
} else if (check % 3 == 1) {
cout << "Second" << endl;
} else {
cout << "First" << endl;
}
return 0;
}
| [
"literal.string.change",
"io.output.change"
] | 870,112 | 870,113 | u385617244 | cpp |
p03055 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <type_traits>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007; //良く出てくるMOD
constexpr ll INF = 1050000000; // intで使うでかい数
constexpr ll LONGINF = 1050000000000000000; // longlongで使うでかい数
const int nCk_MAX = 510000; // nCkの前計算で使うかもしれない 普段は入ってないよ
struct all_init {
//初期化のためだけの構造体
//コンストラクタが呼ばれ、cin,cout高速化がされる
//ついでに少数も出力できるようにしている
all_init() {
cout.tie(nullptr);
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
};
} ALL_INIT;
struct edge {
//辺の重みを管理できるような構造体
//コンストラクタによって簡単に値を入れられるようにしている
// operatorは辺の重みでソート出来るようにしている
int from, to;
ll cost;
ll capa;
edge(int s, int d) : from(s), to(d) {
cost = 0;
capa = 0;
}
edge(int s, int d, ll w) : from(s), to(d), cost(w) { capa = 0; }
edge(int s, int d, ll x, ll y) : from(s), to(d), cost(x), capa(y) {}
bool operator<(const edge &x) const { return cost < x.cost; }
};
#define CIN(vector_array_etc, n) \
for (int loop = 0; loop < n; loop++) { \
cin >> vector_array_etc[loop]; \
}
#define COUT(vector_array_etc, n) \
for (int LOOP = 0; LOOP < n; LOOP++) { \
cout << vector_array_etc[LOOP] << (LOOP == n - 1 ? '\n' : ' '); \
}
#define VC(Type_name) vector<Type_name> // 1次元ならあまり意味ないかも
#define VCVC(Type_name) vector<vector<Type_name>> // 2次元配列定義怠過ぎ問題
#define SORT(vector_etc) sort(vector_etc.begin(), vector_etc.end())
#define ALL(vec_etc) vec_etc.begin(), vec_etc.end()
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
} // aに最大値が入る
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
} // aに最小値が入る
template <typename T> istream &operator>>(istream &is, vector<T> &Vec) {
for (T &x : Vec) {
is >> x;
}
return is;
}
template <typename V, typename H> void resize(vector<V> &vec, const H head) {
vec.resize(head);
}
template <typename V, typename H, typename... T>
void resize(vector<V> &vec, const H &head, const T... tail) {
vec.resize(head);
for (auto &v : vec) {
resize(v, tail...);
}
}
int dx[] = {0, 1, -1, 0, 1, -1, 1, -1}; // i<4:4way i<8:8way
int dy[] = {1, 0, 0, -1, 1, -1, -1, 1};
ll PowMod(ll n, ll k, ll mod) {
//繰り返し2乗法
// n^kをmodで求める
ll r = 1;
for (; k > 0; k >>= 1) {
if (k & 1) {
r = (r * n) % mod;
}
n = (n * n) % mod;
}
return r;
}
ll Gcd(ll a, ll b) { //最大公約数
return b != 0 ? Gcd(b, a % b) : a;
}
ll Lcm(ll a, ll b) { //最小公倍数
return a / Gcd(a, b) * b;
}
bool isPrime(ll n) {
//素数かどうかを判定
// true 素数
if (n < 2)
return false;
for (ll i = 2; i * i <= n; i++)
if (!(n % i))
return false;
return true;
}
ll MergeCount(vector<int> &a) {
//反転数を数える
ll count = 0;
int n = a.size();
if (n > 1) {
vector<int> b(a.begin(), a.begin() + n / 2);
vector<int> c(a.begin() + n / 2, a.end());
count += MergeCount(b);
count += MergeCount(c);
for (int i = 0, j = 0, k = 0; i < n; ++i)
if (k == c.size())
a[i] = b[j++];
else if (j == b.size())
a[i] = c[k++];
else if (b[j] <= c[k])
a[i] = b[j++];
else {
a[i] = c[k++];
count += n / 2 - j;
}
}
return count;
}
bool WarshallFloyd(vector<vector<ll>> &c, int V) {
//ワーシャルフロイド法
//全ての頂点間の最短距離を求める
// falseの時、負の閉路検出
for (int i = 0; i < V; i++) {
c[i][i] = 0;
}
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
for (int k = 0; k < V; k++) {
if (c[j][k] > c[j][i] + c[i][k]) {
c[j][k] = c[j][i] + c[i][k];
}
}
}
}
for (int i = 0; i < V; i++) {
if (c[i][i] < 0) {
return false;
}
}
return true;
}
vector<ll> Dijkstra(int i, vector<vector<edge>> graph) {
// i:始点
// graph:重み付きグラフ
int n = graph.size();
vector<ll> d(n, LONGINF);
d[i] = 0;
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>>
q;
q.push(make_pair(0, i)); //第一引数:コスト 第二引数:頂点
while (!q.empty()) {
pair<ll, int> p = q.top();
q.pop();
int v = p.second;
if (d[v] < p.first) {
continue;
}
for (auto x : graph[v]) {
if (d[x.to] > d[v] + x.cost) {
d[x.to] = d[v] + x.cost;
q.push(make_pair(d[x.to], x.to));
}
}
}
return d;
}
bool BellmanFord(int start, int E, int V, vector<edge> Edge, vector<ll> &d) {
//第一引数:start 始点
//第二引数:E 辺の数
//第三引数:V 頂点数
//第四引数:Edge 辺の重み付きのグラフ
//第五引数:d 各頂点への距離を入れる配列(答えが入る)
fill(d.begin(), d.end(), LONGINF);
d[start] = 0;
vector<bool> t(V, false);
/*
for (int i = 0; i < V - 1; i++) {
for (int j = 0; j < E; j++) {
edge e = Edge[j];
if (d[e.from] == LONGINF) { continue; }
if (d[e.to] > d[e.from] + e.cost) {
d[e.to] = d[e.from] + e.cost;
}
}
}
*/
for (int i = 0; i < V; i++) {
for (int j = 0; j < E; j++) {
edge e = Edge[j];
if (d[e.from] == LONGINF) {
continue;
}
if (d[e.to] > d[e.from] + e.cost) {
d[e.to] = d[e.from] + e.cost;
t[e.to] = true;
if (i == V - 1) { //どこかに閉路があることを感知する
return false;
}
}
if (t[e.from]) {
t[e.to] = true;
}
}
}
/*
if (t[V - 1]) {
//V-1は頂点番号n-1で、始点からn-1までに負の閉路を検出したい場合には、
//コメントアウトを解除すること。
return false;
}
*/
return true;
}
bool TopologicalSort(const vector<vector<edge>> &g, vector<int> &ans) {
//トポロジカルソート
// trueが帰る時、トポロジカルソートが成功し、その結果がansに渡される
// falseはトポロジカルソートの失敗
int n = g.size(), k = 0;
vector<int> ord(n), in(n);
for (auto &es : g) {
for (auto &e : es) {
in[e.to]++;
}
}
queue<int> q;
for (int i = 0; i < n; ++i) {
if (in[i] == 0)
q.push(i);
}
while (!q.empty()) {
int v = q.front();
q.pop();
ord[k++] = v;
for (auto &e : g[v]) {
if (--in[e.to] == 0)
q.push(e.to);
}
}
ans = ord;
if (*max_element(in.begin(), in.end()) == 0) {
return true;
}
return false;
}
vector<int> ArticulationNode(const vector<vector<edge>> &g) {
//グラフの関節点を列挙する
//最後の2行で、erace
//uniqueをしない場合は、その分割によって何個のグラフに分かれるかを判定できる(要チェック)。
int n = g.size(), idx;
vector<int> low(n), ord(n), art;
function<void(int)> DFS = [&](int v) {
low[v] = ord[v] = ++idx;
for (auto &e : g[v]) {
int w = e.to;
if (ord[w] == 0) {
DFS(w);
low[v] = min(low[v], low[w]);
if ((ord[v] == 1 && ord[w] != 2) || (ord[v] != 1 && low[w] >= ord[v])) {
art.push_back(v);
}
} else {
low[v] = min(low[v], ord[w]);
}
}
};
for (int u = 0; u < n; u++) {
if (ord[u] == 0) {
idx = 0;
DFS(u);
}
}
sort(art.begin(), art.end()); //与えられた関節点をソート
art.erase(unique(art.begin(), art.end()),
art.end()); //同じ関節点が複数存在することがある,
return art;
}
edge TreeDiameter(const vector<vector<edge>> &g) {
//重み付きグラフ(木)を受け取り、その木の直径を求める
//返り値はfrom,to,costを持った構造体
int start = 0; //どの始点から始めても良いので、0から始める
static const auto bfs = [](const vector<vector<edge>> &g, int s,
queue<int> &q, vector<ll> &dist) {
while (!q.empty()) {
q.pop();
}
q.push(s);
int n = g.size();
dist.assign(n, LONGINF);
dist[s] = 0;
while (q.size()) {
int u = q.front();
q.pop();
for (auto &e : g[u]) {
int v = e.to;
if (dist[v] == LONGINF) {
dist[v] = dist[u] + e.cost;
q.push(v);
}
}
}
return dist;
};
vector<ll> dist;
queue<int> q;
bfs(g, start, q, dist);
int n = g.size(), u = -1, v = -1;
for (int i = 0; i < n; i++)
if (dist[i] != LONGINF && (u == -1 || dist[i] > dist[u]))
u = i;
bfs(g, u, q, dist);
for (int i = 0; i < n; i++)
if (dist[i] != LONGINF && (v == -1 || dist[i] > dist[v]))
v = i;
ll d = dist[v];
if (u > v)
swap(u, v); //念のため辞書順
return edge(u, v, d);
}
class UnionFind {
// satanicさん作 UnionFind
//追加機能:forest forestは、全体に含まれる木の数を表す
private:
std::vector<int> parent;
std::vector<int> height;
std::vector<int> m_size;
int forest_num;
public:
UnionFind(int size_) : parent(size_), height(size_, 0), m_size(size_, 1) {
forest_num = size_;
for (int i = 0; i < size_; ++i)
parent[i] = i;
}
void init(int size_) {
parent.resize(size_);
height.resize(size_, 0);
m_size.resize(size_, 1);
forest_num = size_;
for (int i = 0; i < size_; ++i)
parent[i] = i;
}
int find(int x) {
if (parent[x] == x)
return x;
return parent[x] = find(parent[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return;
int t = size(x) + size(y);
m_size[x] = m_size[y] = t;
if (height[x] < height[y])
parent[x] = y;
else
parent[y] = x;
if (height[x] == height[y])
++height[x];
forest_num--;
}
bool same(int x, int y) { return find(x) == find(y); }
int size(int x) {
if (parent[x] == x)
return m_size[x];
return size(parent[x] = find(parent[x]));
}
int forest() { return forest_num; }
};
class Dinic {
//最大流を求める
private:
int n, s, t;
vector<int> level, prog, que;
vector<vector<ll>> cap, flow;
vector<vector<int>> g;
ll inf;
public:
Dinic(const vector<vector<edge>> &graph)
: n(graph.size()), cap(n, vector<ll>(n)), //
flow(n, vector<ll>(n)), g(n, vector<int>()), inf(LONGINF) {
for (int i = 0; i < n; i++) {
for (auto &e : graph[i]) {
int u = e.from, v = e.to;
ll c = e.capa;
cap[u][v] += c;
cap[v][u] += c;
flow[v][u] += c;
g[u].push_back(v);
g[v].push_back(u);
}
}
}
inline ll residue(int u, int v) { return cap[u][v] - flow[u][v]; }
ll solve(int s_, int t_) {
this->t = t_, this->s = s_;
que.resize(n + 1);
ll res = 0;
while (levelize()) {
prog.assign(n, 0);
res += augment(s, inf);
}
return res;
}
bool levelize() {
int l = 0, r = 0;
level.assign(n, -1);
level[s] = 0;
que[r++] = s;
while (l != r) {
int v = que[l++];
if (v == t)
break;
for (const int &d : g[v])
if (level[d] == -1 && residue(v, d) != 0) {
level[d] = level[v] + 1;
que[r++] = d;
}
}
return level[t] != -1;
}
ll augment(int v, ll lim) {
ll res = 0;
if (v == t)
return lim;
for (int &i = prog[v]; i < (int)g[v].size(); i++) {
const int &d = g[v][i];
if (residue(v, d) == 0 || level[v] >= level[d])
continue;
const ll aug = augment(d, min(lim, residue(v, d)));
flow[v][d] += aug;
flow[d][v] -= aug;
res += aug;
lim -= aug;
if (lim == 0)
break;
}
return res;
}
};
class MinimumCostFlow {
private:
using Flow = ll;
using Cost = ll;
struct Edge {
int d;
Flow c, f;
Cost w;
int r, is_r;
Edge(int d_, Flow c_, Flow f_, Cost w_, int r_, bool is_r_)
: d(d_), c(c_), f(f_), w(w_), r(r_), is_r(is_r_) {}
};
int n;
vector<vector<Edge>> g;
public:
MinimumCostFlow(int n_) : n(n_), g(vector<vector<Edge>>(n_)) {}
void add_edge(int src, int dst, Flow cap, Cost cost) { // 有向辺
int rsrc = g[dst].size();
int rdst = g[src].size();
g[src].emplace_back(dst, cap, 0, cost, rsrc, false);
g[dst].emplace_back(src, cap, cap, -cost, rdst, true);
}
Cost solve(int s, int t, Flow f) {
Cost res = 0;
vector<Cost> h(n + 10), dist(n);
vector<int> prevv(n + 10), preve(n + 10);
using pcv = pair<Cost, int>;
priority_queue<pcv, vector<pcv>, greater<pcv>> q;
fill(h.begin(), h.end(), 0);
while (f > 0) {
fill(dist.begin(), dist.end(), LONGINF);
dist[s] = 0;
q.emplace(0, s);
while (q.size()) {
Cost cd;
int v;
tie(cd, v) = q.top();
q.pop();
if (dist[v] < cd)
continue;
for (int i = 0; i < (int)(g[v].size()); ++i) {
Edge &e = g[v][i];
if (residue(e) == 0)
continue;
if (dist[e.d] + h[e.d] > cd + h[v] + e.w) {
dist[e.d] = dist[v] + e.w + h[v] - h[e.d];
prevv[e.d] = v;
preve[e.d] = i;
q.emplace(dist[e.d], e.d);
}
}
}
if (dist[t] == LONGINF)
return -1; // 経路が見つからなかった
// s-t 間を最短路に沿って目一杯流す
for (int i = 0; i < n; ++i)
h[i] += dist[i];
Flow d = f;
for (int v = t; v != s; v = prevv[v]) {
chmin(d, residue(g[prevv[v]][preve[v]]));
}
f -= d;
res += d * h[t];
for (int v = t; v != s; v = prevv[v]) {
Edge &e = g[prevv[v]][preve[v]];
e.f += d;
g[v][e.r].f -= d;
}
}
return res;
}
Flow residue(const Edge &e) { return e.c - e.f; }
// 流量を表示
void show() {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < (int)(g[i].size()); ++j) {
Edge &e = g[i][j];
if (e.is_r)
continue;
cout << i << "->" << e.d << "(flow:" << e.f << ")" << endl;
}
}
}
};
class BipartiteMatching {
private:
int V;
vector<int> match;
vector<bool> used;
vector<vector<int>> g;
vector<pair<int, int>> match_pair;
bool dfs(int v) {
used[v] = true;
for (int i = 0; i < (int)g[v].size(); i++) {
int u = g[v][i];
int w = match[u];
if (w < 0 || !used[w] && dfs(w)) {
match[v] = u;
match[u] = v;
match_pair.emplace_back(make_pair(u, v));
return true;
}
}
return false;
}
public:
BipartiteMatching(int n) {
V = n;
resize(match, n);
resize(used, n);
resize(g, n);
}
void add_edge(int u, int v) {
g[u].emplace_back(v);
g[v].emplace_back(u);
}
int MatchingSolve() {
int res = 0;
fill(match.begin(), match.end(), -1);
for (int v = 0; v < V; v++) {
if (match[v] < 0) {
fill(used.begin(), used.end(), false);
if (dfs(v)) {
res++;
}
}
}
return res;
}
vector<pair<int, int>> get_pair() {
for (auto x : match_pair) {
cout << x.first << " " << x.second << endl;
}
return match_pair;
}
};
class Lca {
private:
int n;
int log2_n;
vector<vector<int>> parent;
vector<int> depth;
void dfs(const vector<vector<edge>> &g, int v, int p, int d) {
parent[0][v] = p;
depth[v] = d;
for (auto &e : g[v]) {
if (e.to != p) {
dfs(g, e.to, v, d + 1);
}
}
}
public:
Lca(const vector<vector<edge>> &g, int root) {
n = g.size();
log2_n = (int)log2(n) + 1;
resize(parent, log2_n, n);
resize(depth, n);
dfs(g, root, -1, 0);
for (int k = 0; k + 1 < log2_n; k++) {
for (int v = 0; v < (int)g.size(); v++) {
if (parent[k][v] < 0) {
parent[k + 1][v] = -1;
} else {
parent[k + 1][v] = parent[k][parent[k][v]];
}
}
}
}
int get_lca(int u, int v) {
if (depth[u] > depth[v]) {
swap(u, v);
} // u≦v
for (int k = 0; k < log2_n; k++) {
if ((depth[v] - depth[u]) >> k & 1) {
v = parent[k][v];
}
}
if (u == v) {
return u;
}
for (int k = log2_n - 1; k >= 0; k--) {
if (parent[k][u] != parent[k][v]) {
u = parent[k][u];
v = parent[k][v];
}
}
return parent[0][u];
}
int get_depth(int v) { return depth[v]; }
};
vector<vector<edge>> to_roottree(const vector<vector<edge>> &g, int r) {
int n = g.size();
vector<vector<edge>> G(n);
vector<int> ord(n, -1);
queue<int> q;
q.push(r);
int k = 0;
while (q.size()) {
int u = q.front();
q.pop();
for (auto &e : g[u]) {
int v = e.to;
if (ord[v] == -1) {
ord[v] = k;
k++;
q.push(v);
G[u].emplace_back(e);
}
}
}
return G;
}
int main() {
int n;
cin >> n;
vector<vector<edge>> g(n);
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].emplace_back(a, b, 1);
g[b].emplace_back(b, a, 1);
}
int check = TreeDiameter(g).cost;
if (check % 3 == 0) {
cout << "Second" << endl;
} else if (check % 3 == 1) {
cout << "Second" << endl;
} else {
cout << "First" << endl;
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <type_traits>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007; //良く出てくるMOD
constexpr ll INF = 1050000000; // intで使うでかい数
constexpr ll LONGINF = 1050000000000000000; // longlongで使うでかい数
const int nCk_MAX = 510000; // nCkの前計算で使うかもしれない 普段は入ってないよ
struct all_init {
//初期化のためだけの構造体
//コンストラクタが呼ばれ、cin,cout高速化がされる
//ついでに少数も出力できるようにしている
all_init() {
cout.tie(nullptr);
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
};
} ALL_INIT;
struct edge {
//辺の重みを管理できるような構造体
//コンストラクタによって簡単に値を入れられるようにしている
// operatorは辺の重みでソート出来るようにしている
int from, to;
ll cost;
ll capa;
edge(int s, int d) : from(s), to(d) {
cost = 0;
capa = 0;
}
edge(int s, int d, ll w) : from(s), to(d), cost(w) { capa = 0; }
edge(int s, int d, ll x, ll y) : from(s), to(d), cost(x), capa(y) {}
bool operator<(const edge &x) const { return cost < x.cost; }
};
#define CIN(vector_array_etc, n) \
for (int loop = 0; loop < n; loop++) { \
cin >> vector_array_etc[loop]; \
}
#define COUT(vector_array_etc, n) \
for (int LOOP = 0; LOOP < n; LOOP++) { \
cout << vector_array_etc[LOOP] << (LOOP == n - 1 ? '\n' : ' '); \
}
#define VC(Type_name) vector<Type_name> // 1次元ならあまり意味ないかも
#define VCVC(Type_name) vector<vector<Type_name>> // 2次元配列定義怠過ぎ問題
#define SORT(vector_etc) sort(vector_etc.begin(), vector_etc.end())
#define ALL(vec_etc) vec_etc.begin(), vec_etc.end()
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
} // aに最大値が入る
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
} // aに最小値が入る
template <typename T> istream &operator>>(istream &is, vector<T> &Vec) {
for (T &x : Vec) {
is >> x;
}
return is;
}
template <typename V, typename H> void resize(vector<V> &vec, const H head) {
vec.resize(head);
}
template <typename V, typename H, typename... T>
void resize(vector<V> &vec, const H &head, const T... tail) {
vec.resize(head);
for (auto &v : vec) {
resize(v, tail...);
}
}
int dx[] = {0, 1, -1, 0, 1, -1, 1, -1}; // i<4:4way i<8:8way
int dy[] = {1, 0, 0, -1, 1, -1, -1, 1};
ll PowMod(ll n, ll k, ll mod) {
//繰り返し2乗法
// n^kをmodで求める
ll r = 1;
for (; k > 0; k >>= 1) {
if (k & 1) {
r = (r * n) % mod;
}
n = (n * n) % mod;
}
return r;
}
ll Gcd(ll a, ll b) { //最大公約数
return b != 0 ? Gcd(b, a % b) : a;
}
ll Lcm(ll a, ll b) { //最小公倍数
return a / Gcd(a, b) * b;
}
bool isPrime(ll n) {
//素数かどうかを判定
// true 素数
if (n < 2)
return false;
for (ll i = 2; i * i <= n; i++)
if (!(n % i))
return false;
return true;
}
ll MergeCount(vector<int> &a) {
//反転数を数える
ll count = 0;
int n = a.size();
if (n > 1) {
vector<int> b(a.begin(), a.begin() + n / 2);
vector<int> c(a.begin() + n / 2, a.end());
count += MergeCount(b);
count += MergeCount(c);
for (int i = 0, j = 0, k = 0; i < n; ++i)
if (k == c.size())
a[i] = b[j++];
else if (j == b.size())
a[i] = c[k++];
else if (b[j] <= c[k])
a[i] = b[j++];
else {
a[i] = c[k++];
count += n / 2 - j;
}
}
return count;
}
bool WarshallFloyd(vector<vector<ll>> &c, int V) {
//ワーシャルフロイド法
//全ての頂点間の最短距離を求める
// falseの時、負の閉路検出
for (int i = 0; i < V; i++) {
c[i][i] = 0;
}
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
for (int k = 0; k < V; k++) {
if (c[j][k] > c[j][i] + c[i][k]) {
c[j][k] = c[j][i] + c[i][k];
}
}
}
}
for (int i = 0; i < V; i++) {
if (c[i][i] < 0) {
return false;
}
}
return true;
}
vector<ll> Dijkstra(int i, vector<vector<edge>> graph) {
// i:始点
// graph:重み付きグラフ
int n = graph.size();
vector<ll> d(n, LONGINF);
d[i] = 0;
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>>
q;
q.push(make_pair(0, i)); //第一引数:コスト 第二引数:頂点
while (!q.empty()) {
pair<ll, int> p = q.top();
q.pop();
int v = p.second;
if (d[v] < p.first) {
continue;
}
for (auto x : graph[v]) {
if (d[x.to] > d[v] + x.cost) {
d[x.to] = d[v] + x.cost;
q.push(make_pair(d[x.to], x.to));
}
}
}
return d;
}
bool BellmanFord(int start, int E, int V, vector<edge> Edge, vector<ll> &d) {
//第一引数:start 始点
//第二引数:E 辺の数
//第三引数:V 頂点数
//第四引数:Edge 辺の重み付きのグラフ
//第五引数:d 各頂点への距離を入れる配列(答えが入る)
fill(d.begin(), d.end(), LONGINF);
d[start] = 0;
vector<bool> t(V, false);
/*
for (int i = 0; i < V - 1; i++) {
for (int j = 0; j < E; j++) {
edge e = Edge[j];
if (d[e.from] == LONGINF) { continue; }
if (d[e.to] > d[e.from] + e.cost) {
d[e.to] = d[e.from] + e.cost;
}
}
}
*/
for (int i = 0; i < V; i++) {
for (int j = 0; j < E; j++) {
edge e = Edge[j];
if (d[e.from] == LONGINF) {
continue;
}
if (d[e.to] > d[e.from] + e.cost) {
d[e.to] = d[e.from] + e.cost;
t[e.to] = true;
if (i == V - 1) { //どこかに閉路があることを感知する
return false;
}
}
if (t[e.from]) {
t[e.to] = true;
}
}
}
/*
if (t[V - 1]) {
//V-1は頂点番号n-1で、始点からn-1までに負の閉路を検出したい場合には、
//コメントアウトを解除すること。
return false;
}
*/
return true;
}
bool TopologicalSort(const vector<vector<edge>> &g, vector<int> &ans) {
//トポロジカルソート
// trueが帰る時、トポロジカルソートが成功し、その結果がansに渡される
// falseはトポロジカルソートの失敗
int n = g.size(), k = 0;
vector<int> ord(n), in(n);
for (auto &es : g) {
for (auto &e : es) {
in[e.to]++;
}
}
queue<int> q;
for (int i = 0; i < n; ++i) {
if (in[i] == 0)
q.push(i);
}
while (!q.empty()) {
int v = q.front();
q.pop();
ord[k++] = v;
for (auto &e : g[v]) {
if (--in[e.to] == 0)
q.push(e.to);
}
}
ans = ord;
if (*max_element(in.begin(), in.end()) == 0) {
return true;
}
return false;
}
vector<int> ArticulationNode(const vector<vector<edge>> &g) {
//グラフの関節点を列挙する
//最後の2行で、erace
//uniqueをしない場合は、その分割によって何個のグラフに分かれるかを判定できる(要チェック)。
int n = g.size(), idx;
vector<int> low(n), ord(n), art;
function<void(int)> DFS = [&](int v) {
low[v] = ord[v] = ++idx;
for (auto &e : g[v]) {
int w = e.to;
if (ord[w] == 0) {
DFS(w);
low[v] = min(low[v], low[w]);
if ((ord[v] == 1 && ord[w] != 2) || (ord[v] != 1 && low[w] >= ord[v])) {
art.push_back(v);
}
} else {
low[v] = min(low[v], ord[w]);
}
}
};
for (int u = 0; u < n; u++) {
if (ord[u] == 0) {
idx = 0;
DFS(u);
}
}
sort(art.begin(), art.end()); //与えられた関節点をソート
art.erase(unique(art.begin(), art.end()),
art.end()); //同じ関節点が複数存在することがある,
return art;
}
edge TreeDiameter(const vector<vector<edge>> &g) {
//重み付きグラフ(木)を受け取り、その木の直径を求める
//返り値はfrom,to,costを持った構造体
int start = 0; //どの始点から始めても良いので、0から始める
static const auto bfs = [](const vector<vector<edge>> &g, int s,
queue<int> &q, vector<ll> &dist) {
while (!q.empty()) {
q.pop();
}
q.push(s);
int n = g.size();
dist.assign(n, LONGINF);
dist[s] = 0;
while (q.size()) {
int u = q.front();
q.pop();
for (auto &e : g[u]) {
int v = e.to;
if (dist[v] == LONGINF) {
dist[v] = dist[u] + e.cost;
q.push(v);
}
}
}
return dist;
};
vector<ll> dist;
queue<int> q;
bfs(g, start, q, dist);
int n = g.size(), u = -1, v = -1;
for (int i = 0; i < n; i++)
if (dist[i] != LONGINF && (u == -1 || dist[i] > dist[u]))
u = i;
bfs(g, u, q, dist);
for (int i = 0; i < n; i++)
if (dist[i] != LONGINF && (v == -1 || dist[i] > dist[v]))
v = i;
ll d = dist[v];
if (u > v)
swap(u, v); //念のため辞書順
return edge(u, v, d);
}
class UnionFind {
// satanicさん作 UnionFind
//追加機能:forest forestは、全体に含まれる木の数を表す
private:
std::vector<int> parent;
std::vector<int> height;
std::vector<int> m_size;
int forest_num;
public:
UnionFind(int size_) : parent(size_), height(size_, 0), m_size(size_, 1) {
forest_num = size_;
for (int i = 0; i < size_; ++i)
parent[i] = i;
}
void init(int size_) {
parent.resize(size_);
height.resize(size_, 0);
m_size.resize(size_, 1);
forest_num = size_;
for (int i = 0; i < size_; ++i)
parent[i] = i;
}
int find(int x) {
if (parent[x] == x)
return x;
return parent[x] = find(parent[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return;
int t = size(x) + size(y);
m_size[x] = m_size[y] = t;
if (height[x] < height[y])
parent[x] = y;
else
parent[y] = x;
if (height[x] == height[y])
++height[x];
forest_num--;
}
bool same(int x, int y) { return find(x) == find(y); }
int size(int x) {
if (parent[x] == x)
return m_size[x];
return size(parent[x] = find(parent[x]));
}
int forest() { return forest_num; }
};
class Dinic {
//最大流を求める
private:
int n, s, t;
vector<int> level, prog, que;
vector<vector<ll>> cap, flow;
vector<vector<int>> g;
ll inf;
public:
Dinic(const vector<vector<edge>> &graph)
: n(graph.size()), cap(n, vector<ll>(n)), //
flow(n, vector<ll>(n)), g(n, vector<int>()), inf(LONGINF) {
for (int i = 0; i < n; i++) {
for (auto &e : graph[i]) {
int u = e.from, v = e.to;
ll c = e.capa;
cap[u][v] += c;
cap[v][u] += c;
flow[v][u] += c;
g[u].push_back(v);
g[v].push_back(u);
}
}
}
inline ll residue(int u, int v) { return cap[u][v] - flow[u][v]; }
ll solve(int s_, int t_) {
this->t = t_, this->s = s_;
que.resize(n + 1);
ll res = 0;
while (levelize()) {
prog.assign(n, 0);
res += augment(s, inf);
}
return res;
}
bool levelize() {
int l = 0, r = 0;
level.assign(n, -1);
level[s] = 0;
que[r++] = s;
while (l != r) {
int v = que[l++];
if (v == t)
break;
for (const int &d : g[v])
if (level[d] == -1 && residue(v, d) != 0) {
level[d] = level[v] + 1;
que[r++] = d;
}
}
return level[t] != -1;
}
ll augment(int v, ll lim) {
ll res = 0;
if (v == t)
return lim;
for (int &i = prog[v]; i < (int)g[v].size(); i++) {
const int &d = g[v][i];
if (residue(v, d) == 0 || level[v] >= level[d])
continue;
const ll aug = augment(d, min(lim, residue(v, d)));
flow[v][d] += aug;
flow[d][v] -= aug;
res += aug;
lim -= aug;
if (lim == 0)
break;
}
return res;
}
};
class MinimumCostFlow {
private:
using Flow = ll;
using Cost = ll;
struct Edge {
int d;
Flow c, f;
Cost w;
int r, is_r;
Edge(int d_, Flow c_, Flow f_, Cost w_, int r_, bool is_r_)
: d(d_), c(c_), f(f_), w(w_), r(r_), is_r(is_r_) {}
};
int n;
vector<vector<Edge>> g;
public:
MinimumCostFlow(int n_) : n(n_), g(vector<vector<Edge>>(n_)) {}
void add_edge(int src, int dst, Flow cap, Cost cost) { // 有向辺
int rsrc = g[dst].size();
int rdst = g[src].size();
g[src].emplace_back(dst, cap, 0, cost, rsrc, false);
g[dst].emplace_back(src, cap, cap, -cost, rdst, true);
}
Cost solve(int s, int t, Flow f) {
Cost res = 0;
vector<Cost> h(n + 10), dist(n);
vector<int> prevv(n + 10), preve(n + 10);
using pcv = pair<Cost, int>;
priority_queue<pcv, vector<pcv>, greater<pcv>> q;
fill(h.begin(), h.end(), 0);
while (f > 0) {
fill(dist.begin(), dist.end(), LONGINF);
dist[s] = 0;
q.emplace(0, s);
while (q.size()) {
Cost cd;
int v;
tie(cd, v) = q.top();
q.pop();
if (dist[v] < cd)
continue;
for (int i = 0; i < (int)(g[v].size()); ++i) {
Edge &e = g[v][i];
if (residue(e) == 0)
continue;
if (dist[e.d] + h[e.d] > cd + h[v] + e.w) {
dist[e.d] = dist[v] + e.w + h[v] - h[e.d];
prevv[e.d] = v;
preve[e.d] = i;
q.emplace(dist[e.d], e.d);
}
}
}
if (dist[t] == LONGINF)
return -1; // 経路が見つからなかった
// s-t 間を最短路に沿って目一杯流す
for (int i = 0; i < n; ++i)
h[i] += dist[i];
Flow d = f;
for (int v = t; v != s; v = prevv[v]) {
chmin(d, residue(g[prevv[v]][preve[v]]));
}
f -= d;
res += d * h[t];
for (int v = t; v != s; v = prevv[v]) {
Edge &e = g[prevv[v]][preve[v]];
e.f += d;
g[v][e.r].f -= d;
}
}
return res;
}
Flow residue(const Edge &e) { return e.c - e.f; }
// 流量を表示
void show() {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < (int)(g[i].size()); ++j) {
Edge &e = g[i][j];
if (e.is_r)
continue;
cout << i << "->" << e.d << "(flow:" << e.f << ")" << endl;
}
}
}
};
class BipartiteMatching {
private:
int V;
vector<int> match;
vector<bool> used;
vector<vector<int>> g;
vector<pair<int, int>> match_pair;
bool dfs(int v) {
used[v] = true;
for (int i = 0; i < (int)g[v].size(); i++) {
int u = g[v][i];
int w = match[u];
if (w < 0 || !used[w] && dfs(w)) {
match[v] = u;
match[u] = v;
match_pair.emplace_back(make_pair(u, v));
return true;
}
}
return false;
}
public:
BipartiteMatching(int n) {
V = n;
resize(match, n);
resize(used, n);
resize(g, n);
}
void add_edge(int u, int v) {
g[u].emplace_back(v);
g[v].emplace_back(u);
}
int MatchingSolve() {
int res = 0;
fill(match.begin(), match.end(), -1);
for (int v = 0; v < V; v++) {
if (match[v] < 0) {
fill(used.begin(), used.end(), false);
if (dfs(v)) {
res++;
}
}
}
return res;
}
vector<pair<int, int>> get_pair() {
for (auto x : match_pair) {
cout << x.first << " " << x.second << endl;
}
return match_pair;
}
};
class Lca {
private:
int n;
int log2_n;
vector<vector<int>> parent;
vector<int> depth;
void dfs(const vector<vector<edge>> &g, int v, int p, int d) {
parent[0][v] = p;
depth[v] = d;
for (auto &e : g[v]) {
if (e.to != p) {
dfs(g, e.to, v, d + 1);
}
}
}
public:
Lca(const vector<vector<edge>> &g, int root) {
n = g.size();
log2_n = (int)log2(n) + 1;
resize(parent, log2_n, n);
resize(depth, n);
dfs(g, root, -1, 0);
for (int k = 0; k + 1 < log2_n; k++) {
for (int v = 0; v < (int)g.size(); v++) {
if (parent[k][v] < 0) {
parent[k + 1][v] = -1;
} else {
parent[k + 1][v] = parent[k][parent[k][v]];
}
}
}
}
int get_lca(int u, int v) {
if (depth[u] > depth[v]) {
swap(u, v);
} // u≦v
for (int k = 0; k < log2_n; k++) {
if ((depth[v] - depth[u]) >> k & 1) {
v = parent[k][v];
}
}
if (u == v) {
return u;
}
for (int k = log2_n - 1; k >= 0; k--) {
if (parent[k][u] != parent[k][v]) {
u = parent[k][u];
v = parent[k][v];
}
}
return parent[0][u];
}
int get_depth(int v) { return depth[v]; }
};
vector<vector<edge>> to_roottree(const vector<vector<edge>> &g, int r) {
int n = g.size();
vector<vector<edge>> G(n);
vector<int> ord(n, -1);
queue<int> q;
q.push(r);
int k = 0;
while (q.size()) {
int u = q.front();
q.pop();
for (auto &e : g[u]) {
int v = e.to;
if (ord[v] == -1) {
ord[v] = k;
k++;
q.push(v);
G[u].emplace_back(e);
}
}
}
return G;
}
int main() {
int n;
cin >> n;
vector<vector<edge>> g(n);
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].emplace_back(a, b, 1);
g[b].emplace_back(b, a, 1);
}
int check = TreeDiameter(g).cost;
// cout << check % 3 << endl;
if (check % 3 == 0) {
cout << "First" << endl;
} else if (check % 3 == 1) {
cout << "Second" << endl;
} else {
cout << "First" << endl;
}
return 0;
}
| [
"literal.string.change",
"io.output.change"
] | 870,114 | 870,113 | u385617244 | cpp |
p03055 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <type_traits>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007; //良く出てくるMOD
constexpr ll INF = 1050000000; // intで使うでかい数
constexpr ll LONGINF = 1050000000000000000; // longlongで使うでかい数
const int nCk_MAX = 510000; // nCkの前計算で使うかもしれない 普段は入ってないよ
struct all_init {
//初期化のためだけの構造体
//コンストラクタが呼ばれ、cin,cout高速化がされる
//ついでに少数も出力できるようにしている
all_init() {
cout.tie(nullptr);
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
};
} ALL_INIT;
struct edge {
//辺の重みを管理できるような構造体
//コンストラクタによって簡単に値を入れられるようにしている
// operatorは辺の重みでソート出来るようにしている
int from, to;
ll cost;
ll capa;
edge(int s, int d) : from(s), to(d) {
cost = 0;
capa = 0;
}
edge(int s, int d, ll w) : from(s), to(d), cost(w) { capa = 0; }
edge(int s, int d, ll x, ll y) : from(s), to(d), cost(x), capa(y) {}
bool operator<(const edge &x) const { return cost < x.cost; }
};
#define CIN(vector_array_etc, n) \
for (int loop = 0; loop < n; loop++) { \
cin >> vector_array_etc[loop]; \
}
#define COUT(vector_array_etc, n) \
for (int LOOP = 0; LOOP < n; LOOP++) { \
cout << vector_array_etc[LOOP] << (LOOP == n - 1 ? '\n' : ' '); \
}
#define VC(Type_name) vector<Type_name> // 1次元ならあまり意味ないかも
#define VCVC(Type_name) vector<vector<Type_name>> // 2次元配列定義怠過ぎ問題
#define SORT(vector_etc) sort(vector_etc.begin(), vector_etc.end())
#define ALL(vec_etc) vec_etc.begin(), vec_etc.end()
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
} // aに最大値が入る
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
} // aに最小値が入る
template <typename T> istream &operator>>(istream &is, vector<T> &Vec) {
for (T &x : Vec) {
is >> x;
}
return is;
}
template <typename V, typename H> void resize(vector<V> &vec, const H head) {
vec.resize(head);
}
template <typename V, typename H, typename... T>
void resize(vector<V> &vec, const H &head, const T... tail) {
vec.resize(head);
for (auto &v : vec) {
resize(v, tail...);
}
}
int dx[] = {0, 1, -1, 0, 1, -1, 1, -1}; // i<4:4way i<8:8way
int dy[] = {1, 0, 0, -1, 1, -1, -1, 1};
ll PowMod(ll n, ll k, ll mod) {
//繰り返し2乗法
// n^kをmodで求める
ll r = 1;
for (; k > 0; k >>= 1) {
if (k & 1) {
r = (r * n) % mod;
}
n = (n * n) % mod;
}
return r;
}
ll Gcd(ll a, ll b) { //最大公約数
return b != 0 ? Gcd(b, a % b) : a;
}
ll Lcm(ll a, ll b) { //最小公倍数
return a / Gcd(a, b) * b;
}
bool isPrime(ll n) {
//素数かどうかを判定
// true 素数
if (n < 2)
return false;
for (ll i = 2; i * i <= n; i++)
if (!(n % i))
return false;
return true;
}
ll MergeCount(vector<int> &a) {
//反転数を数える
ll count = 0;
int n = a.size();
if (n > 1) {
vector<int> b(a.begin(), a.begin() + n / 2);
vector<int> c(a.begin() + n / 2, a.end());
count += MergeCount(b);
count += MergeCount(c);
for (int i = 0, j = 0, k = 0; i < n; ++i)
if (k == c.size())
a[i] = b[j++];
else if (j == b.size())
a[i] = c[k++];
else if (b[j] <= c[k])
a[i] = b[j++];
else {
a[i] = c[k++];
count += n / 2 - j;
}
}
return count;
}
bool WarshallFloyd(vector<vector<ll>> &c, int V) {
//ワーシャルフロイド法
//全ての頂点間の最短距離を求める
// falseの時、負の閉路検出
for (int i = 0; i < V; i++) {
c[i][i] = 0;
}
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
for (int k = 0; k < V; k++) {
if (c[j][k] > c[j][i] + c[i][k]) {
c[j][k] = c[j][i] + c[i][k];
}
}
}
}
for (int i = 0; i < V; i++) {
if (c[i][i] < 0) {
return false;
}
}
return true;
}
vector<ll> Dijkstra(int i, vector<vector<edge>> graph) {
// i:始点
// graph:重み付きグラフ
int n = graph.size();
vector<ll> d(n, LONGINF);
d[i] = 0;
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>>
q;
q.push(make_pair(0, i)); //第一引数:コスト 第二引数:頂点
while (!q.empty()) {
pair<ll, int> p = q.top();
q.pop();
int v = p.second;
if (d[v] < p.first) {
continue;
}
for (auto x : graph[v]) {
if (d[x.to] > d[v] + x.cost) {
d[x.to] = d[v] + x.cost;
q.push(make_pair(d[x.to], x.to));
}
}
}
return d;
}
bool BellmanFord(int start, int E, int V, vector<edge> Edge, vector<ll> &d) {
//第一引数:start 始点
//第二引数:E 辺の数
//第三引数:V 頂点数
//第四引数:Edge 辺の重み付きのグラフ
//第五引数:d 各頂点への距離を入れる配列(答えが入る)
fill(d.begin(), d.end(), LONGINF);
d[start] = 0;
vector<bool> t(V, false);
/*
for (int i = 0; i < V - 1; i++) {
for (int j = 0; j < E; j++) {
edge e = Edge[j];
if (d[e.from] == LONGINF) { continue; }
if (d[e.to] > d[e.from] + e.cost) {
d[e.to] = d[e.from] + e.cost;
}
}
}
*/
for (int i = 0; i < V; i++) {
for (int j = 0; j < E; j++) {
edge e = Edge[j];
if (d[e.from] == LONGINF) {
continue;
}
if (d[e.to] > d[e.from] + e.cost) {
d[e.to] = d[e.from] + e.cost;
t[e.to] = true;
if (i == V - 1) { //どこかに閉路があることを感知する
return false;
}
}
if (t[e.from]) {
t[e.to] = true;
}
}
}
/*
if (t[V - 1]) {
//V-1は頂点番号n-1で、始点からn-1までに負の閉路を検出したい場合には、
//コメントアウトを解除すること。
return false;
}
*/
return true;
}
bool TopologicalSort(const vector<vector<edge>> &g, vector<int> &ans) {
//トポロジカルソート
// trueが帰る時、トポロジカルソートが成功し、その結果がansに渡される
// falseはトポロジカルソートの失敗
int n = g.size(), k = 0;
vector<int> ord(n), in(n);
for (auto &es : g) {
for (auto &e : es) {
in[e.to]++;
}
}
queue<int> q;
for (int i = 0; i < n; ++i) {
if (in[i] == 0)
q.push(i);
}
while (!q.empty()) {
int v = q.front();
q.pop();
ord[k++] = v;
for (auto &e : g[v]) {
if (--in[e.to] == 0)
q.push(e.to);
}
}
ans = ord;
if (*max_element(in.begin(), in.end()) == 0) {
return true;
}
return false;
}
vector<int> ArticulationNode(const vector<vector<edge>> &g) {
//グラフの関節点を列挙する
//最後の2行で、erace
//uniqueをしない場合は、その分割によって何個のグラフに分かれるかを判定できる(要チェック)。
int n = g.size(), idx;
vector<int> low(n), ord(n), art;
function<void(int)> DFS = [&](int v) {
low[v] = ord[v] = ++idx;
for (auto &e : g[v]) {
int w = e.to;
if (ord[w] == 0) {
DFS(w);
low[v] = min(low[v], low[w]);
if ((ord[v] == 1 && ord[w] != 2) || (ord[v] != 1 && low[w] >= ord[v])) {
art.push_back(v);
}
} else {
low[v] = min(low[v], ord[w]);
}
}
};
for (int u = 0; u < n; u++) {
if (ord[u] == 0) {
idx = 0;
DFS(u);
}
}
sort(art.begin(), art.end()); //与えられた関節点をソート
art.erase(unique(art.begin(), art.end()),
art.end()); //同じ関節点が複数存在することがある,
return art;
}
edge TreeDiameter(const vector<vector<edge>> &g) {
//重み付きグラフ(木)を受け取り、その木の直径を求める
//返り値はfrom,to,costを持った構造体
int start = 0; //どの始点から始めても良いので、0から始める
static const auto bfs = [](const vector<vector<edge>> &g, int s,
queue<int> &q, vector<ll> &dist) {
while (!q.empty()) {
q.pop();
}
q.push(s);
int n = g.size();
dist.assign(n, LONGINF);
dist[s] = 0;
while (q.size()) {
int u = q.front();
q.pop();
for (auto &e : g[u]) {
int v = e.to;
if (dist[v] == LONGINF) {
dist[v] = dist[u] + e.cost;
q.push(v);
}
}
}
return dist;
};
vector<ll> dist;
queue<int> q;
bfs(g, start, q, dist);
int n = g.size(), u = -1, v = -1;
for (int i = 0; i < n; i++)
if (dist[i] != LONGINF && (u == -1 || dist[i] > dist[u]))
u = i;
bfs(g, u, q, dist);
for (int i = 0; i < n; i++)
if (dist[i] != LONGINF && (v == -1 || dist[i] > dist[v]))
v = i;
ll d = dist[v];
if (u > v)
swap(u, v); //念のため辞書順
return edge(u, v, d);
}
class UnionFind {
// satanicさん作 UnionFind
//追加機能:forest forestは、全体に含まれる木の数を表す
private:
std::vector<int> parent;
std::vector<int> height;
std::vector<int> m_size;
int forest_num;
public:
UnionFind(int size_) : parent(size_), height(size_, 0), m_size(size_, 1) {
forest_num = size_;
for (int i = 0; i < size_; ++i)
parent[i] = i;
}
void init(int size_) {
parent.resize(size_);
height.resize(size_, 0);
m_size.resize(size_, 1);
forest_num = size_;
for (int i = 0; i < size_; ++i)
parent[i] = i;
}
int find(int x) {
if (parent[x] == x)
return x;
return parent[x] = find(parent[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return;
int t = size(x) + size(y);
m_size[x] = m_size[y] = t;
if (height[x] < height[y])
parent[x] = y;
else
parent[y] = x;
if (height[x] == height[y])
++height[x];
forest_num--;
}
bool same(int x, int y) { return find(x) == find(y); }
int size(int x) {
if (parent[x] == x)
return m_size[x];
return size(parent[x] = find(parent[x]));
}
int forest() { return forest_num; }
};
class Dinic {
//最大流を求める
private:
int n, s, t;
vector<int> level, prog, que;
vector<vector<ll>> cap, flow;
vector<vector<int>> g;
ll inf;
public:
Dinic(const vector<vector<edge>> &graph)
: n(graph.size()), cap(n, vector<ll>(n)), //
flow(n, vector<ll>(n)), g(n, vector<int>()), inf(LONGINF) {
for (int i = 0; i < n; i++) {
for (auto &e : graph[i]) {
int u = e.from, v = e.to;
ll c = e.capa;
cap[u][v] += c;
cap[v][u] += c;
flow[v][u] += c;
g[u].push_back(v);
g[v].push_back(u);
}
}
}
inline ll residue(int u, int v) { return cap[u][v] - flow[u][v]; }
ll solve(int s_, int t_) {
this->t = t_, this->s = s_;
que.resize(n + 1);
ll res = 0;
while (levelize()) {
prog.assign(n, 0);
res += augment(s, inf);
}
return res;
}
bool levelize() {
int l = 0, r = 0;
level.assign(n, -1);
level[s] = 0;
que[r++] = s;
while (l != r) {
int v = que[l++];
if (v == t)
break;
for (const int &d : g[v])
if (level[d] == -1 && residue(v, d) != 0) {
level[d] = level[v] + 1;
que[r++] = d;
}
}
return level[t] != -1;
}
ll augment(int v, ll lim) {
ll res = 0;
if (v == t)
return lim;
for (int &i = prog[v]; i < (int)g[v].size(); i++) {
const int &d = g[v][i];
if (residue(v, d) == 0 || level[v] >= level[d])
continue;
const ll aug = augment(d, min(lim, residue(v, d)));
flow[v][d] += aug;
flow[d][v] -= aug;
res += aug;
lim -= aug;
if (lim == 0)
break;
}
return res;
}
};
class MinimumCostFlow {
private:
using Flow = ll;
using Cost = ll;
struct Edge {
int d;
Flow c, f;
Cost w;
int r, is_r;
Edge(int d_, Flow c_, Flow f_, Cost w_, int r_, bool is_r_)
: d(d_), c(c_), f(f_), w(w_), r(r_), is_r(is_r_) {}
};
int n;
vector<vector<Edge>> g;
public:
MinimumCostFlow(int n_) : n(n_), g(vector<vector<Edge>>(n_)) {}
void add_edge(int src, int dst, Flow cap, Cost cost) { // 有向辺
int rsrc = g[dst].size();
int rdst = g[src].size();
g[src].emplace_back(dst, cap, 0, cost, rsrc, false);
g[dst].emplace_back(src, cap, cap, -cost, rdst, true);
}
Cost solve(int s, int t, Flow f) {
Cost res = 0;
vector<Cost> h(n + 10), dist(n);
vector<int> prevv(n + 10), preve(n + 10);
using pcv = pair<Cost, int>;
priority_queue<pcv, vector<pcv>, greater<pcv>> q;
fill(h.begin(), h.end(), 0);
while (f > 0) {
fill(dist.begin(), dist.end(), LONGINF);
dist[s] = 0;
q.emplace(0, s);
while (q.size()) {
Cost cd;
int v;
tie(cd, v) = q.top();
q.pop();
if (dist[v] < cd)
continue;
for (int i = 0; i < (int)(g[v].size()); ++i) {
Edge &e = g[v][i];
if (residue(e) == 0)
continue;
if (dist[e.d] + h[e.d] > cd + h[v] + e.w) {
dist[e.d] = dist[v] + e.w + h[v] - h[e.d];
prevv[e.d] = v;
preve[e.d] = i;
q.emplace(dist[e.d], e.d);
}
}
}
if (dist[t] == LONGINF)
return -1; // 経路が見つからなかった
// s-t 間を最短路に沿って目一杯流す
for (int i = 0; i < n; ++i)
h[i] += dist[i];
Flow d = f;
for (int v = t; v != s; v = prevv[v]) {
chmin(d, residue(g[prevv[v]][preve[v]]));
}
f -= d;
res += d * h[t];
for (int v = t; v != s; v = prevv[v]) {
Edge &e = g[prevv[v]][preve[v]];
e.f += d;
g[v][e.r].f -= d;
}
}
return res;
}
Flow residue(const Edge &e) { return e.c - e.f; }
// 流量を表示
void show() {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < (int)(g[i].size()); ++j) {
Edge &e = g[i][j];
if (e.is_r)
continue;
cout << i << "->" << e.d << "(flow:" << e.f << ")" << endl;
}
}
}
};
class BipartiteMatching {
private:
int V;
vector<int> match;
vector<bool> used;
vector<vector<int>> g;
vector<pair<int, int>> match_pair;
bool dfs(int v) {
used[v] = true;
for (int i = 0; i < (int)g[v].size(); i++) {
int u = g[v][i];
int w = match[u];
if (w < 0 || !used[w] && dfs(w)) {
match[v] = u;
match[u] = v;
match_pair.emplace_back(make_pair(u, v));
return true;
}
}
return false;
}
public:
BipartiteMatching(int n) {
V = n;
resize(match, n);
resize(used, n);
resize(g, n);
}
void add_edge(int u, int v) {
g[u].emplace_back(v);
g[v].emplace_back(u);
}
int MatchingSolve() {
int res = 0;
fill(match.begin(), match.end(), -1);
for (int v = 0; v < V; v++) {
if (match[v] < 0) {
fill(used.begin(), used.end(), false);
if (dfs(v)) {
res++;
}
}
}
return res;
}
vector<pair<int, int>> get_pair() {
for (auto x : match_pair) {
cout << x.first << " " << x.second << endl;
}
return match_pair;
}
};
class Lca {
private:
int n;
int log2_n;
vector<vector<int>> parent;
vector<int> depth;
void dfs(const vector<vector<edge>> &g, int v, int p, int d) {
parent[0][v] = p;
depth[v] = d;
for (auto &e : g[v]) {
if (e.to != p) {
dfs(g, e.to, v, d + 1);
}
}
}
public:
Lca(const vector<vector<edge>> &g, int root) {
n = g.size();
log2_n = (int)log2(n) + 1;
resize(parent, log2_n, n);
resize(depth, n);
dfs(g, root, -1, 0);
for (int k = 0; k + 1 < log2_n; k++) {
for (int v = 0; v < (int)g.size(); v++) {
if (parent[k][v] < 0) {
parent[k + 1][v] = -1;
} else {
parent[k + 1][v] = parent[k][parent[k][v]];
}
}
}
}
int get_lca(int u, int v) {
if (depth[u] > depth[v]) {
swap(u, v);
} // u≦v
for (int k = 0; k < log2_n; k++) {
if ((depth[v] - depth[u]) >> k & 1) {
v = parent[k][v];
}
}
if (u == v) {
return u;
}
for (int k = log2_n - 1; k >= 0; k--) {
if (parent[k][u] != parent[k][v]) {
u = parent[k][u];
v = parent[k][v];
}
}
return parent[0][u];
}
int get_depth(int v) { return depth[v]; }
};
vector<vector<edge>> to_roottree(const vector<vector<edge>> &g, int r) {
int n = g.size();
vector<vector<edge>> G(n);
vector<int> ord(n, -1);
queue<int> q;
q.push(r);
int k = 0;
while (q.size()) {
int u = q.front();
q.pop();
for (auto &e : g[u]) {
int v = e.to;
if (ord[v] == -1) {
ord[v] = k;
k++;
q.push(v);
G[u].emplace_back(e);
}
}
}
return G;
}
int main() {
int n;
cin >> n;
vector<vector<edge>> g(n);
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].emplace_back(a, b, 1);
g[b].emplace_back(b, a, 1);
}
int check = TreeDiameter(g).cost % 3;
if (check % 3 == 0) {
cout << "second" << endl;
} else if (check % 3 == 1) {
cout << "second" << endl;
} else {
cout << "first" << endl;
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <type_traits>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007; //良く出てくるMOD
constexpr ll INF = 1050000000; // intで使うでかい数
constexpr ll LONGINF = 1050000000000000000; // longlongで使うでかい数
const int nCk_MAX = 510000; // nCkの前計算で使うかもしれない 普段は入ってないよ
struct all_init {
//初期化のためだけの構造体
//コンストラクタが呼ばれ、cin,cout高速化がされる
//ついでに少数も出力できるようにしている
all_init() {
cout.tie(nullptr);
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
};
} ALL_INIT;
struct edge {
//辺の重みを管理できるような構造体
//コンストラクタによって簡単に値を入れられるようにしている
// operatorは辺の重みでソート出来るようにしている
int from, to;
ll cost;
ll capa;
edge(int s, int d) : from(s), to(d) {
cost = 0;
capa = 0;
}
edge(int s, int d, ll w) : from(s), to(d), cost(w) { capa = 0; }
edge(int s, int d, ll x, ll y) : from(s), to(d), cost(x), capa(y) {}
bool operator<(const edge &x) const { return cost < x.cost; }
};
#define CIN(vector_array_etc, n) \
for (int loop = 0; loop < n; loop++) { \
cin >> vector_array_etc[loop]; \
}
#define COUT(vector_array_etc, n) \
for (int LOOP = 0; LOOP < n; LOOP++) { \
cout << vector_array_etc[LOOP] << (LOOP == n - 1 ? '\n' : ' '); \
}
#define VC(Type_name) vector<Type_name> // 1次元ならあまり意味ないかも
#define VCVC(Type_name) vector<vector<Type_name>> // 2次元配列定義怠過ぎ問題
#define SORT(vector_etc) sort(vector_etc.begin(), vector_etc.end())
#define ALL(vec_etc) vec_etc.begin(), vec_etc.end()
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
} // aに最大値が入る
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
} // aに最小値が入る
template <typename T> istream &operator>>(istream &is, vector<T> &Vec) {
for (T &x : Vec) {
is >> x;
}
return is;
}
template <typename V, typename H> void resize(vector<V> &vec, const H head) {
vec.resize(head);
}
template <typename V, typename H, typename... T>
void resize(vector<V> &vec, const H &head, const T... tail) {
vec.resize(head);
for (auto &v : vec) {
resize(v, tail...);
}
}
int dx[] = {0, 1, -1, 0, 1, -1, 1, -1}; // i<4:4way i<8:8way
int dy[] = {1, 0, 0, -1, 1, -1, -1, 1};
ll PowMod(ll n, ll k, ll mod) {
//繰り返し2乗法
// n^kをmodで求める
ll r = 1;
for (; k > 0; k >>= 1) {
if (k & 1) {
r = (r * n) % mod;
}
n = (n * n) % mod;
}
return r;
}
ll Gcd(ll a, ll b) { //最大公約数
return b != 0 ? Gcd(b, a % b) : a;
}
ll Lcm(ll a, ll b) { //最小公倍数
return a / Gcd(a, b) * b;
}
bool isPrime(ll n) {
//素数かどうかを判定
// true 素数
if (n < 2)
return false;
for (ll i = 2; i * i <= n; i++)
if (!(n % i))
return false;
return true;
}
ll MergeCount(vector<int> &a) {
//反転数を数える
ll count = 0;
int n = a.size();
if (n > 1) {
vector<int> b(a.begin(), a.begin() + n / 2);
vector<int> c(a.begin() + n / 2, a.end());
count += MergeCount(b);
count += MergeCount(c);
for (int i = 0, j = 0, k = 0; i < n; ++i)
if (k == c.size())
a[i] = b[j++];
else if (j == b.size())
a[i] = c[k++];
else if (b[j] <= c[k])
a[i] = b[j++];
else {
a[i] = c[k++];
count += n / 2 - j;
}
}
return count;
}
bool WarshallFloyd(vector<vector<ll>> &c, int V) {
//ワーシャルフロイド法
//全ての頂点間の最短距離を求める
// falseの時、負の閉路検出
for (int i = 0; i < V; i++) {
c[i][i] = 0;
}
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
for (int k = 0; k < V; k++) {
if (c[j][k] > c[j][i] + c[i][k]) {
c[j][k] = c[j][i] + c[i][k];
}
}
}
}
for (int i = 0; i < V; i++) {
if (c[i][i] < 0) {
return false;
}
}
return true;
}
vector<ll> Dijkstra(int i, vector<vector<edge>> graph) {
// i:始点
// graph:重み付きグラフ
int n = graph.size();
vector<ll> d(n, LONGINF);
d[i] = 0;
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>>
q;
q.push(make_pair(0, i)); //第一引数:コスト 第二引数:頂点
while (!q.empty()) {
pair<ll, int> p = q.top();
q.pop();
int v = p.second;
if (d[v] < p.first) {
continue;
}
for (auto x : graph[v]) {
if (d[x.to] > d[v] + x.cost) {
d[x.to] = d[v] + x.cost;
q.push(make_pair(d[x.to], x.to));
}
}
}
return d;
}
bool BellmanFord(int start, int E, int V, vector<edge> Edge, vector<ll> &d) {
//第一引数:start 始点
//第二引数:E 辺の数
//第三引数:V 頂点数
//第四引数:Edge 辺の重み付きのグラフ
//第五引数:d 各頂点への距離を入れる配列(答えが入る)
fill(d.begin(), d.end(), LONGINF);
d[start] = 0;
vector<bool> t(V, false);
/*
for (int i = 0; i < V - 1; i++) {
for (int j = 0; j < E; j++) {
edge e = Edge[j];
if (d[e.from] == LONGINF) { continue; }
if (d[e.to] > d[e.from] + e.cost) {
d[e.to] = d[e.from] + e.cost;
}
}
}
*/
for (int i = 0; i < V; i++) {
for (int j = 0; j < E; j++) {
edge e = Edge[j];
if (d[e.from] == LONGINF) {
continue;
}
if (d[e.to] > d[e.from] + e.cost) {
d[e.to] = d[e.from] + e.cost;
t[e.to] = true;
if (i == V - 1) { //どこかに閉路があることを感知する
return false;
}
}
if (t[e.from]) {
t[e.to] = true;
}
}
}
/*
if (t[V - 1]) {
//V-1は頂点番号n-1で、始点からn-1までに負の閉路を検出したい場合には、
//コメントアウトを解除すること。
return false;
}
*/
return true;
}
bool TopologicalSort(const vector<vector<edge>> &g, vector<int> &ans) {
//トポロジカルソート
// trueが帰る時、トポロジカルソートが成功し、その結果がansに渡される
// falseはトポロジカルソートの失敗
int n = g.size(), k = 0;
vector<int> ord(n), in(n);
for (auto &es : g) {
for (auto &e : es) {
in[e.to]++;
}
}
queue<int> q;
for (int i = 0; i < n; ++i) {
if (in[i] == 0)
q.push(i);
}
while (!q.empty()) {
int v = q.front();
q.pop();
ord[k++] = v;
for (auto &e : g[v]) {
if (--in[e.to] == 0)
q.push(e.to);
}
}
ans = ord;
if (*max_element(in.begin(), in.end()) == 0) {
return true;
}
return false;
}
vector<int> ArticulationNode(const vector<vector<edge>> &g) {
//グラフの関節点を列挙する
//最後の2行で、erace
//uniqueをしない場合は、その分割によって何個のグラフに分かれるかを判定できる(要チェック)。
int n = g.size(), idx;
vector<int> low(n), ord(n), art;
function<void(int)> DFS = [&](int v) {
low[v] = ord[v] = ++idx;
for (auto &e : g[v]) {
int w = e.to;
if (ord[w] == 0) {
DFS(w);
low[v] = min(low[v], low[w]);
if ((ord[v] == 1 && ord[w] != 2) || (ord[v] != 1 && low[w] >= ord[v])) {
art.push_back(v);
}
} else {
low[v] = min(low[v], ord[w]);
}
}
};
for (int u = 0; u < n; u++) {
if (ord[u] == 0) {
idx = 0;
DFS(u);
}
}
sort(art.begin(), art.end()); //与えられた関節点をソート
art.erase(unique(art.begin(), art.end()),
art.end()); //同じ関節点が複数存在することがある,
return art;
}
edge TreeDiameter(const vector<vector<edge>> &g) {
//重み付きグラフ(木)を受け取り、その木の直径を求める
//返り値はfrom,to,costを持った構造体
int start = 0; //どの始点から始めても良いので、0から始める
static const auto bfs = [](const vector<vector<edge>> &g, int s,
queue<int> &q, vector<ll> &dist) {
while (!q.empty()) {
q.pop();
}
q.push(s);
int n = g.size();
dist.assign(n, LONGINF);
dist[s] = 0;
while (q.size()) {
int u = q.front();
q.pop();
for (auto &e : g[u]) {
int v = e.to;
if (dist[v] == LONGINF) {
dist[v] = dist[u] + e.cost;
q.push(v);
}
}
}
return dist;
};
vector<ll> dist;
queue<int> q;
bfs(g, start, q, dist);
int n = g.size(), u = -1, v = -1;
for (int i = 0; i < n; i++)
if (dist[i] != LONGINF && (u == -1 || dist[i] > dist[u]))
u = i;
bfs(g, u, q, dist);
for (int i = 0; i < n; i++)
if (dist[i] != LONGINF && (v == -1 || dist[i] > dist[v]))
v = i;
ll d = dist[v];
if (u > v)
swap(u, v); //念のため辞書順
return edge(u, v, d);
}
class UnionFind {
// satanicさん作 UnionFind
//追加機能:forest forestは、全体に含まれる木の数を表す
private:
std::vector<int> parent;
std::vector<int> height;
std::vector<int> m_size;
int forest_num;
public:
UnionFind(int size_) : parent(size_), height(size_, 0), m_size(size_, 1) {
forest_num = size_;
for (int i = 0; i < size_; ++i)
parent[i] = i;
}
void init(int size_) {
parent.resize(size_);
height.resize(size_, 0);
m_size.resize(size_, 1);
forest_num = size_;
for (int i = 0; i < size_; ++i)
parent[i] = i;
}
int find(int x) {
if (parent[x] == x)
return x;
return parent[x] = find(parent[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return;
int t = size(x) + size(y);
m_size[x] = m_size[y] = t;
if (height[x] < height[y])
parent[x] = y;
else
parent[y] = x;
if (height[x] == height[y])
++height[x];
forest_num--;
}
bool same(int x, int y) { return find(x) == find(y); }
int size(int x) {
if (parent[x] == x)
return m_size[x];
return size(parent[x] = find(parent[x]));
}
int forest() { return forest_num; }
};
class Dinic {
//最大流を求める
private:
int n, s, t;
vector<int> level, prog, que;
vector<vector<ll>> cap, flow;
vector<vector<int>> g;
ll inf;
public:
Dinic(const vector<vector<edge>> &graph)
: n(graph.size()), cap(n, vector<ll>(n)), //
flow(n, vector<ll>(n)), g(n, vector<int>()), inf(LONGINF) {
for (int i = 0; i < n; i++) {
for (auto &e : graph[i]) {
int u = e.from, v = e.to;
ll c = e.capa;
cap[u][v] += c;
cap[v][u] += c;
flow[v][u] += c;
g[u].push_back(v);
g[v].push_back(u);
}
}
}
inline ll residue(int u, int v) { return cap[u][v] - flow[u][v]; }
ll solve(int s_, int t_) {
this->t = t_, this->s = s_;
que.resize(n + 1);
ll res = 0;
while (levelize()) {
prog.assign(n, 0);
res += augment(s, inf);
}
return res;
}
bool levelize() {
int l = 0, r = 0;
level.assign(n, -1);
level[s] = 0;
que[r++] = s;
while (l != r) {
int v = que[l++];
if (v == t)
break;
for (const int &d : g[v])
if (level[d] == -1 && residue(v, d) != 0) {
level[d] = level[v] + 1;
que[r++] = d;
}
}
return level[t] != -1;
}
ll augment(int v, ll lim) {
ll res = 0;
if (v == t)
return lim;
for (int &i = prog[v]; i < (int)g[v].size(); i++) {
const int &d = g[v][i];
if (residue(v, d) == 0 || level[v] >= level[d])
continue;
const ll aug = augment(d, min(lim, residue(v, d)));
flow[v][d] += aug;
flow[d][v] -= aug;
res += aug;
lim -= aug;
if (lim == 0)
break;
}
return res;
}
};
class MinimumCostFlow {
private:
using Flow = ll;
using Cost = ll;
struct Edge {
int d;
Flow c, f;
Cost w;
int r, is_r;
Edge(int d_, Flow c_, Flow f_, Cost w_, int r_, bool is_r_)
: d(d_), c(c_), f(f_), w(w_), r(r_), is_r(is_r_) {}
};
int n;
vector<vector<Edge>> g;
public:
MinimumCostFlow(int n_) : n(n_), g(vector<vector<Edge>>(n_)) {}
void add_edge(int src, int dst, Flow cap, Cost cost) { // 有向辺
int rsrc = g[dst].size();
int rdst = g[src].size();
g[src].emplace_back(dst, cap, 0, cost, rsrc, false);
g[dst].emplace_back(src, cap, cap, -cost, rdst, true);
}
Cost solve(int s, int t, Flow f) {
Cost res = 0;
vector<Cost> h(n + 10), dist(n);
vector<int> prevv(n + 10), preve(n + 10);
using pcv = pair<Cost, int>;
priority_queue<pcv, vector<pcv>, greater<pcv>> q;
fill(h.begin(), h.end(), 0);
while (f > 0) {
fill(dist.begin(), dist.end(), LONGINF);
dist[s] = 0;
q.emplace(0, s);
while (q.size()) {
Cost cd;
int v;
tie(cd, v) = q.top();
q.pop();
if (dist[v] < cd)
continue;
for (int i = 0; i < (int)(g[v].size()); ++i) {
Edge &e = g[v][i];
if (residue(e) == 0)
continue;
if (dist[e.d] + h[e.d] > cd + h[v] + e.w) {
dist[e.d] = dist[v] + e.w + h[v] - h[e.d];
prevv[e.d] = v;
preve[e.d] = i;
q.emplace(dist[e.d], e.d);
}
}
}
if (dist[t] == LONGINF)
return -1; // 経路が見つからなかった
// s-t 間を最短路に沿って目一杯流す
for (int i = 0; i < n; ++i)
h[i] += dist[i];
Flow d = f;
for (int v = t; v != s; v = prevv[v]) {
chmin(d, residue(g[prevv[v]][preve[v]]));
}
f -= d;
res += d * h[t];
for (int v = t; v != s; v = prevv[v]) {
Edge &e = g[prevv[v]][preve[v]];
e.f += d;
g[v][e.r].f -= d;
}
}
return res;
}
Flow residue(const Edge &e) { return e.c - e.f; }
// 流量を表示
void show() {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < (int)(g[i].size()); ++j) {
Edge &e = g[i][j];
if (e.is_r)
continue;
cout << i << "->" << e.d << "(flow:" << e.f << ")" << endl;
}
}
}
};
class BipartiteMatching {
private:
int V;
vector<int> match;
vector<bool> used;
vector<vector<int>> g;
vector<pair<int, int>> match_pair;
bool dfs(int v) {
used[v] = true;
for (int i = 0; i < (int)g[v].size(); i++) {
int u = g[v][i];
int w = match[u];
if (w < 0 || !used[w] && dfs(w)) {
match[v] = u;
match[u] = v;
match_pair.emplace_back(make_pair(u, v));
return true;
}
}
return false;
}
public:
BipartiteMatching(int n) {
V = n;
resize(match, n);
resize(used, n);
resize(g, n);
}
void add_edge(int u, int v) {
g[u].emplace_back(v);
g[v].emplace_back(u);
}
int MatchingSolve() {
int res = 0;
fill(match.begin(), match.end(), -1);
for (int v = 0; v < V; v++) {
if (match[v] < 0) {
fill(used.begin(), used.end(), false);
if (dfs(v)) {
res++;
}
}
}
return res;
}
vector<pair<int, int>> get_pair() {
for (auto x : match_pair) {
cout << x.first << " " << x.second << endl;
}
return match_pair;
}
};
class Lca {
private:
int n;
int log2_n;
vector<vector<int>> parent;
vector<int> depth;
void dfs(const vector<vector<edge>> &g, int v, int p, int d) {
parent[0][v] = p;
depth[v] = d;
for (auto &e : g[v]) {
if (e.to != p) {
dfs(g, e.to, v, d + 1);
}
}
}
public:
Lca(const vector<vector<edge>> &g, int root) {
n = g.size();
log2_n = (int)log2(n) + 1;
resize(parent, log2_n, n);
resize(depth, n);
dfs(g, root, -1, 0);
for (int k = 0; k + 1 < log2_n; k++) {
for (int v = 0; v < (int)g.size(); v++) {
if (parent[k][v] < 0) {
parent[k + 1][v] = -1;
} else {
parent[k + 1][v] = parent[k][parent[k][v]];
}
}
}
}
int get_lca(int u, int v) {
if (depth[u] > depth[v]) {
swap(u, v);
} // u≦v
for (int k = 0; k < log2_n; k++) {
if ((depth[v] - depth[u]) >> k & 1) {
v = parent[k][v];
}
}
if (u == v) {
return u;
}
for (int k = log2_n - 1; k >= 0; k--) {
if (parent[k][u] != parent[k][v]) {
u = parent[k][u];
v = parent[k][v];
}
}
return parent[0][u];
}
int get_depth(int v) { return depth[v]; }
};
vector<vector<edge>> to_roottree(const vector<vector<edge>> &g, int r) {
int n = g.size();
vector<vector<edge>> G(n);
vector<int> ord(n, -1);
queue<int> q;
q.push(r);
int k = 0;
while (q.size()) {
int u = q.front();
q.pop();
for (auto &e : g[u]) {
int v = e.to;
if (ord[v] == -1) {
ord[v] = k;
k++;
q.push(v);
G[u].emplace_back(e);
}
}
}
return G;
}
int main() {
int n;
cin >> n;
vector<vector<edge>> g(n);
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].emplace_back(a, b, 1);
g[b].emplace_back(b, a, 1);
}
int check = TreeDiameter(g).cost;
// cout << check % 3 << endl;
if (check % 3 == 0) {
cout << "First" << endl;
} else if (check % 3 == 1) {
cout << "Second" << endl;
} else {
cout << "First" << endl;
}
return 0;
}
| [
"expression.operation.binary.remove",
"literal.string.change",
"io.output.change",
"literal.string.case.change"
] | 870,115 | 870,113 | u385617244 | cpp |
p03055 | ////////////////////////////////////////////
/// ///
/// Template ver. 1 rapel ///
/// Fear is Temporary, Regret is Forever ///
/// Must Try and Get AC ///
/// ///
////////////////////////////////////////////
#include <iomanip>
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <complex>
#include <math.h>
#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>
#include <bitset>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
void desperate_optimization(int precision) {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(precision);
}
const int N = 2e5;
int dist[N + 5];
vector<int> lst[N + 5];
queue<int> q;
int diameter(int n) {
memset(dist, -1, sizeof dist);
int pos;
q.push(1);
dist[1] = 0;
while (!q.empty()) {
pos = q.front();
q.pop();
for (auto x : lst[pos]) {
if (dist[x] == 0)
continue;
dist[x] = 0;
q.push(x);
}
}
q.push(pos);
dist[pos] = 1;
while (!q.empty()) {
pos = q.front();
q.pop();
for (auto x : lst[pos]) {
if (dist[x] != 0)
continue;
dist[x] = dist[pos] + 1;
q.push(x);
}
}
return dist[pos] % 3;
}
void hora(int tc) {
int n;
cin >> n;
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
lst[u].PB(v);
lst[v].PB(u);
}
int l = diameter(n);
if (l == 1)
cout << "Second" << endl;
else
cout << "First" << endl;
}
int main() {
desperate_optimization(10);
int ntc = 1;
// cin>>ntc;
for (int tc = 1; tc <= ntc; tc++)
hora(tc);
return 0;
}
| ////////////////////////////////////////////
/// ///
/// Template ver. 1 rapel ///
/// Fear is Temporary, Regret is Forever ///
/// Must Try and Get AC ///
/// ///
////////////////////////////////////////////
#include <iomanip>
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <complex>
#include <math.h>
#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>
#include <bitset>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
void desperate_optimization(int precision) {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(precision);
}
const int N = 2e5;
int dist[N + 5];
vector<int> lst[N + 5];
queue<int> q;
int diameter(int n) {
memset(dist, -1, sizeof dist);
int pos;
q.push(1);
dist[1] = 0;
while (!q.empty()) {
pos = q.front();
q.pop();
for (auto x : lst[pos]) {
if (dist[x] == 0)
continue;
dist[x] = 0;
q.push(x);
}
}
q.push(pos);
dist[pos] = 1;
while (!q.empty()) {
pos = q.front();
q.pop();
for (auto x : lst[pos]) {
if (dist[x] != 0)
continue;
dist[x] = dist[pos] + 1;
q.push(x);
}
}
return dist[pos] % 3;
}
void hora(int tc) {
int n;
cin >> n;
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
lst[u].PB(v);
lst[v].PB(u);
}
int l = diameter(n);
if (l == 2)
cout << "Second" << endl;
else
cout << "First" << endl;
}
int main() {
desperate_optimization(10);
int ntc = 1;
// cin>>ntc;
for (int tc = 1; tc <= ntc; tc++)
hora(tc);
return 0;
}
| [
"literal.number.change",
"control_flow.branch.if.condition.change"
] | 870,116 | 870,117 | u236830524 | cpp |
p03055 | #include "bits/stdc++.h"
using ll = long long;
using namespace std;
#define int ll
// 0 -> a-1
#define rep(i, a) for (int i = 0; (i) < (int)(a); (i)++)
// a -> b-1
#define reps(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++)
// a-1 -> 0
#define rrep(i, a) for (int i = (int)a - 1; (i) >= 0; (i)--)
// a-1 -> b
#define rreps(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
// next_permutation(all(v))
#define PERM(v) next_permutation(all(v))
/*sort(all(v));
(v).erase(unique(all(v)), v.end())*/
#define UNIQUE(v) \
sort(all(v)); \
(v).erase(unique(all(v)), v.end())
#define CIN(type, x) \
type x; \
cin >> x
#define YES(f) \
if ((f)) { \
cout << "YES" << endl; \
} else { \
cout << "NO" << endl; \
}
#define Yes(f) \
if ((f)) { \
cout << "Yes" << endl; \
} else { \
cout << "No" << endl; \
}
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
// b is [a, c)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
// c is [a, e) && d is [b, f)
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(12)
#define RS resize
#define CINV(v, N) \
do { \
v.RS(N); \
rep(i, N) cin >> v[i]; \
} while (0);
#define RCINV(v, N) \
do { \
v.RS(N); \
rrep(i, N) cin >> v[i]; \
} while (0);
#define MOD 1000000007
template <class T> inline T GET() {
T x;
cin >> x;
return x;
}
bool init();
void solve();
signed main() {
if (!init())
cout << "First" << endl;
else
cout << "Second" << endl;
solve();
}
template <class T, char d = '\n'> struct Vector {
vector<T> v;
Vector(int sz) : v(sz) {}
Vector(int sz, T t) : v(sz, t) {}
Vector() : v(0) {}
Vector(vector<T> t) : v(t) {}
inline auto begin() { return v.begin(); }
inline auto end() { return v.end(); }
inline auto rbegin() { return v.rbegin(); }
inline auto rend() { return v.rend(); }
inline int size() { return v.size(); }
inline auto resize(int sz) { v.resize(sz); }
inline auto resize(int sz, T t) { v.resize(sz, t); }
inline auto empty() { v.empty(); }
inline auto reserve(int sz) { v.reserve(sz); }
inline auto push_back(T t) { v.push_back(t); }
inline auto pop_back() { v.pop_back(); }
inline auto assign(int sz, const T &t) { v.assign(sz, t); }
inline auto &front() { return v.front(); }
inline auto &back() { return v.back(); }
inline auto insert(const typename vector<T>::iterator p, const T &t) {
v.insert(p, t);
}
inline auto insert(const typename vector<T>::iterator p,
typename vector<T>::iterator f,
typename vector<T>::iterator l) {
v.insert(p, f, l);
}
inline auto erase(const typename vector<T>::iterator p) { v.erase(p); }
inline auto erase(const typename vector<T>::iterator f,
const typename vector<T>::iterator s) {
v.erase(f, s);
}
inline auto emplace_back(T &t) { v.emplace_back(t); }
inline auto swap(Vector<T> &f) { v.swap(f.v); }
inline auto clear() { v.clear(); }
inline auto &operator[](size_t pos) { return v[pos]; }
inline auto operator<(const Vector &a) { return v < a.v; }
inline auto operator>(const Vector &a) { return a < (*this); }
inline auto operator>=(const Vector &a) { return !((*this) < a); }
inline auto operator<=(const Vector &a) { return !(a < (*this)); }
inline auto operator==(const Vector &a) {
return !(a < (*this)) && !((*this) < a);
}
inline friend istream &operator>>(istream &lhs, Vector &rhs) {
for (auto &x : rhs)
lhs >> x;
return lhs;
}
inline friend ostream &operator<<(ostream &lhs, Vector &rhs) {
for (int i = 0; i + 1 < rhs.size(); i++)
lhs << rhs[i] << d;
if (rhs.size())
lhs << rhs.back();
return lhs;
}
inline auto make_accumulate_sum(T init) {
Vector<T> res;
res.push_back(init);
for (auto x : v) {
auto y = res.back();
res.push_back(y + x);
}
return res;
}
};
template <class T> struct WG {
int to;
T cost;
WG(int a, T b) : to(a), cost(b) {}
};
template <typename T>
pair<T, int> dfs(const vector<vector<WG<T>>> &g, int idx, int par) {
pair<T, int> ret(0, idx);
for (auto &e : g[idx]) {
if (e.to == par)
continue;
auto cost = dfs(g, e.to, idx);
cost.first += e.cost;
ret = max(ret, cost);
}
return ret;
}
template <typename T> T tree_diameter(const vector<vector<WG<T>>> &g) {
auto p = dfs(g, 0, -1);
auto q = dfs(g, p.second, -1);
return (q.first);
}
bool init() {
int N;
cin >> N;
vector<vector<WG<int>>> g(N);
rep(i, N - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].emplace_back(b, 1);
g[b].emplace_back(a, 1);
}
int r = tree_diameter(g);
vector<bool> dp(r + 10);
dp[0] = true;
dp[1] = false;
dp[2] = true;
dp[3] = true;
reps(i, 4, r) {
if (dp[i - 1] && dp[i - 2])
dp[i] = false;
else
dp[i] = true;
}
return dp[r - 1];
}
void solve() {}
| #include "bits/stdc++.h"
using ll = long long;
using namespace std;
#define int ll
// 0 -> a-1
#define rep(i, a) for (int i = 0; (i) < (int)(a); (i)++)
// a -> b-1
#define reps(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++)
// a-1 -> 0
#define rrep(i, a) for (int i = (int)a - 1; (i) >= 0; (i)--)
// a-1 -> b
#define rreps(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
// next_permutation(all(v))
#define PERM(v) next_permutation(all(v))
/*sort(all(v));
(v).erase(unique(all(v)), v.end())*/
#define UNIQUE(v) \
sort(all(v)); \
(v).erase(unique(all(v)), v.end())
#define CIN(type, x) \
type x; \
cin >> x
#define YES(f) \
if ((f)) { \
cout << "YES" << endl; \
} else { \
cout << "NO" << endl; \
}
#define Yes(f) \
if ((f)) { \
cout << "Yes" << endl; \
} else { \
cout << "No" << endl; \
}
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
// b is [a, c)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
// c is [a, e) && d is [b, f)
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(12)
#define RS resize
#define CINV(v, N) \
do { \
v.RS(N); \
rep(i, N) cin >> v[i]; \
} while (0);
#define RCINV(v, N) \
do { \
v.RS(N); \
rrep(i, N) cin >> v[i]; \
} while (0);
#define MOD 1000000007
template <class T> inline T GET() {
T x;
cin >> x;
return x;
}
bool init();
void solve();
signed main() {
if (init())
cout << "First" << endl;
else
cout << "Second" << endl;
solve();
}
template <class T, char d = '\n'> struct Vector {
vector<T> v;
Vector(int sz) : v(sz) {}
Vector(int sz, T t) : v(sz, t) {}
Vector() : v(0) {}
Vector(vector<T> t) : v(t) {}
inline auto begin() { return v.begin(); }
inline auto end() { return v.end(); }
inline auto rbegin() { return v.rbegin(); }
inline auto rend() { return v.rend(); }
inline int size() { return v.size(); }
inline auto resize(int sz) { v.resize(sz); }
inline auto resize(int sz, T t) { v.resize(sz, t); }
inline auto empty() { v.empty(); }
inline auto reserve(int sz) { v.reserve(sz); }
inline auto push_back(T t) { v.push_back(t); }
inline auto pop_back() { v.pop_back(); }
inline auto assign(int sz, const T &t) { v.assign(sz, t); }
inline auto &front() { return v.front(); }
inline auto &back() { return v.back(); }
inline auto insert(const typename vector<T>::iterator p, const T &t) {
v.insert(p, t);
}
inline auto insert(const typename vector<T>::iterator p,
typename vector<T>::iterator f,
typename vector<T>::iterator l) {
v.insert(p, f, l);
}
inline auto erase(const typename vector<T>::iterator p) { v.erase(p); }
inline auto erase(const typename vector<T>::iterator f,
const typename vector<T>::iterator s) {
v.erase(f, s);
}
inline auto emplace_back(T &t) { v.emplace_back(t); }
inline auto swap(Vector<T> &f) { v.swap(f.v); }
inline auto clear() { v.clear(); }
inline auto &operator[](size_t pos) { return v[pos]; }
inline auto operator<(const Vector &a) { return v < a.v; }
inline auto operator>(const Vector &a) { return a < (*this); }
inline auto operator>=(const Vector &a) { return !((*this) < a); }
inline auto operator<=(const Vector &a) { return !(a < (*this)); }
inline auto operator==(const Vector &a) {
return !(a < (*this)) && !((*this) < a);
}
inline friend istream &operator>>(istream &lhs, Vector &rhs) {
for (auto &x : rhs)
lhs >> x;
return lhs;
}
inline friend ostream &operator<<(ostream &lhs, Vector &rhs) {
for (int i = 0; i + 1 < rhs.size(); i++)
lhs << rhs[i] << d;
if (rhs.size())
lhs << rhs.back();
return lhs;
}
inline auto make_accumulate_sum(T init) {
Vector<T> res;
res.push_back(init);
for (auto x : v) {
auto y = res.back();
res.push_back(y + x);
}
return res;
}
};
template <class T> struct WG {
int to;
T cost;
WG(int a, T b) : to(a), cost(b) {}
};
template <typename T>
pair<T, int> dfs(const vector<vector<WG<T>>> &g, int idx, int par) {
pair<T, int> ret(0, idx);
for (auto &e : g[idx]) {
if (e.to == par)
continue;
auto cost = dfs(g, e.to, idx);
cost.first += e.cost;
ret = max(ret, cost);
}
return ret;
}
template <typename T> T tree_diameter(const vector<vector<WG<T>>> &g) {
auto p = dfs(g, 0, -1);
auto q = dfs(g, p.second, -1);
return (q.first);
}
bool init() {
int N;
cin >> N;
vector<vector<WG<int>>> g(N);
rep(i, N - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].emplace_back(b, 1);
g[b].emplace_back(a, 1);
}
int r = tree_diameter(g);
r++;
// cout << r << endl;
vector<bool> dp(r + 10);
dp[0] = true;
dp[1] = false;
dp[2] = true;
dp[3] = true;
reps(i, 4, r) {
if (dp[i - 1] && dp[i - 2])
dp[i] = false;
else
dp[i] = true;
}
return dp[r - 1];
}
void solve() {}
| [
"expression.operation.unary.logical.remove",
"control_flow.branch.if.condition.change",
"expression.unary.arithmetic.add"
] | 870,120 | 870,121 | u946322619 | cpp |
p03055 | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, rt, tot, d[N], head[N], nex[2 * N], to[2 * N];
void add(int u, int v) {
to[++tot] = v;
nex[tot] = head[u];
head[u] = tot;
}
void dfs(int u, int fa) {
d[u] = d[fa] + 1;
if (d[u] > d[rt])
rt = u;
for (int i = head[u]; i; i = nex[i]) {
int v = to[i];
if (v == fa)
continue;
dfs(v, u);
}
}
int main() {
scanf("%d", &n);
for (int i = 1; i < n; i++) {
int u, v;
scanf("%d%d", &u, &v);
add(u, v);
add(v, u);
}
dfs(1, 0);
d[rt] = 0;
dfs(rt, 0);
if (d[rt] % 4 != 1)
printf("First\n");
else
printf("Second\n");
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, rt, tot, d[N], head[N], nex[2 * N], to[2 * N];
void add(int u, int v) {
to[++tot] = v;
nex[tot] = head[u];
head[u] = tot;
}
void dfs(int u, int fa) {
d[u] = d[fa] + 1;
if (d[u] > d[rt])
rt = u;
for (int i = head[u]; i; i = nex[i]) {
int v = to[i];
if (v == fa)
continue;
dfs(v, u);
}
}
int main() {
scanf("%d", &n);
for (int i = 1; i < n; i++) {
int u, v;
scanf("%d%d", &u, &v);
add(u, v);
add(v, u);
}
dfs(1, 0);
d[rt] = 0;
dfs(rt, 0);
if (d[rt] % 3 != 2)
printf("First\n");
else
printf("Second\n");
}
| [
"literal.number.change",
"control_flow.branch.if.condition.change"
] | 870,132 | 870,133 | u676323984 | cpp |
p03055 | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, rt, tot, d[N], head[N], nex[2 * N], to[2 * N];
void add(int u, int v) {
to[++tot] = v;
nex[tot] = head[u];
head[u] = tot;
}
void dfs(int u, int fa) {
d[u] = d[fa] + 1;
if (d[u] > d[rt])
rt = u;
for (int i = head[u]; i; i = nex[i]) {
int v = to[i];
if (v == fa)
continue;
dfs(v, u);
}
}
int main() {
scanf("%d", &n);
for (int i = 1; i < n; i++) {
int u, v;
scanf("%d%d", &u, &v);
add(u, v);
add(v, u);
}
dfs(1, 0);
d[rt] = 0;
dfs(rt, 0);
if (d[rt] % 3 == 0)
printf("First\n");
else
printf("Second\n");
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, rt, tot, d[N], head[N], nex[2 * N], to[2 * N];
void add(int u, int v) {
to[++tot] = v;
nex[tot] = head[u];
head[u] = tot;
}
void dfs(int u, int fa) {
d[u] = d[fa] + 1;
if (d[u] > d[rt])
rt = u;
for (int i = head[u]; i; i = nex[i]) {
int v = to[i];
if (v == fa)
continue;
dfs(v, u);
}
}
int main() {
scanf("%d", &n);
for (int i = 1; i < n; i++) {
int u, v;
scanf("%d%d", &u, &v);
add(u, v);
add(v, u);
}
dfs(1, 0);
d[rt] = 0;
dfs(rt, 0);
if (d[rt] % 3 != 2)
printf("First\n");
else
printf("Second\n");
}
| [] | 870,134 | 870,133 | u676323984 | cpp |
p03055 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
template <typename T> struct edge {
int src, to;
T cost;
edge(int to, T cost) : src(-1), to(to), cost(cost) {}
edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
edge &operator=(const int &x) {
to = x;
return *this;
}
operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
template <typename T> using UnweightedGraph = vector<vector<T>>;
template <typename T> using Matrix = vector<vector<T>>;
template <typename T>
pair<T, int> dfs(const WeightedGraph<T> &G, int v, int par) {
pair<T, int> res = {0, v};
for (auto &e : G[v]) {
if (e.to == par)
continue;
auto dist = dfs(G, e.to, v);
dist.first += e.cost;
res = max(res, dist);
}
return res;
}
template <typename T> T tree_diameter(const WeightedGraph<T> &G) {
auto p = dfs(G, 0, -1);
auto q = dfs(G, p.second, -1);
return q.first;
}
int main() {
int N;
cin >> N;
WeightedGraph<int> G(N);
for (int i = 0; i + 1 < N; i++) {
int x, y;
cin >> x >> y;
x--, y--;
G[x].emplace_back(y, 1);
G[y].emplace_back(x, 1);
}
cout << (tree_diameter(G) % 2 == 0 ? "First" : "Second") << "\n";
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
template <typename T> struct edge {
int src, to;
T cost;
edge(int to, T cost) : src(-1), to(to), cost(cost) {}
edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
edge &operator=(const int &x) {
to = x;
return *this;
}
operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
template <typename T> using UnweightedGraph = vector<vector<T>>;
template <typename T> using Matrix = vector<vector<T>>;
template <typename T>
pair<T, int> dfs(const WeightedGraph<T> &G, int v, int par) {
pair<T, int> res = {0, v};
for (auto &e : G[v]) {
if (e.to == par)
continue;
auto dist = dfs(G, e.to, v);
dist.first += e.cost;
res = max(res, dist);
}
return res;
}
template <typename T> T tree_diameter(const WeightedGraph<T> &G) {
auto p = dfs(G, 0, -1);
auto q = dfs(G, p.second, -1);
return q.first;
}
int main() {
int N;
cin >> N;
WeightedGraph<int> G(N);
for (int i = 0; i + 1 < N; i++) {
int x, y;
cin >> x >> y;
x--, y--;
G[x].emplace_back(y, 1);
G[y].emplace_back(x, 1);
}
cout << (tree_diameter(G) % 3 != 1 ? "First" : "Second") << "\n";
} | [] | 870,142 | 870,143 | u394482932 | cpp |
p03055 | #include <iostream>
#include <queue>
#include <vector>
using namespace std;
pair<int, int> bfs(const vector<vector<int>> &g, int start) {
const int n = g.size();
vector<int> step(n, 1000000007);
queue<int> qu;
qu.push(start);
step[start] = 0;
pair<int, int> res = make_pair(start, 0);
while (!qu.empty()) {
int p = qu.front();
qu.pop();
for (auto &dst : g[p]) {
if (step[p] + 1 < step[dst]) {
step[dst] = step[p] + 1;
qu.push(dst);
if (res.second < step[dst]) {
res = make_pair(dst, step[dst]);
}
}
}
}
return res;
}
int main() {
int N;
while (cin >> N) {
vector<vector<int>> g(N);
for (int i = 0; i < N - 1; i++) {
int a, b;
cin >> a >> b;
--a;
--b;
g[a].push_back(b);
g[b].push_back(a);
}
cout << (bfs(g, bfs(g, 0).first).second % 3 == 2 ? "First" : "Second")
<< endl;
}
} | #include <iostream>
#include <queue>
#include <vector>
using namespace std;
pair<int, int> bfs(const vector<vector<int>> &g, int start) {
const int n = g.size();
vector<int> step(n, 1000000007);
queue<int> qu;
qu.push(start);
step[start] = 0;
pair<int, int> res = make_pair(start, 0);
while (!qu.empty()) {
int p = qu.front();
qu.pop();
for (auto &dst : g[p]) {
if (step[p] + 1 < step[dst]) {
step[dst] = step[p] + 1;
qu.push(dst);
if (res.second < step[dst]) {
res = make_pair(dst, step[dst]);
}
}
}
}
return res;
}
int main() {
int N;
while (cin >> N) {
vector<vector<int>> g(N);
for (int i = 0; i < N - 1; i++) {
int a, b;
cin >> a >> b;
--a;
--b;
g[a].push_back(b);
g[b].push_back(a);
}
cout << (bfs(g, bfs(g, 0).first).second % 3 == 1 ? "Second" : "First")
<< endl;
}
} | [
"literal.number.change",
"control_flow.loop.condition.change"
] | 870,147 | 870,148 | u002023395 | cpp |
p03055 | #include <bits/stdc++.h>
#include <type_traits>
using namespace std;
using ll = long long;
#define int ll
#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) FOR(i, 0, b)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
auto &errStream = cerr;
#ifdef LOCAL
#define cerr (cerr << "-- line " << __LINE__ << " -- ")
#else
class CerrDummy {
} cerrDummy;
template <class T> CerrDummy &operator<<(CerrDummy &cd, const T &) {
return cd;
}
using charTDummy = char;
using traitsDummy = char_traits<charTDummy>;
CerrDummy &operator<<(CerrDummy &cd,
basic_ostream<charTDummy, traitsDummy> &(
basic_ostream<charTDummy, traitsDummy> &)) {
return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr << "reached" << endl
#define DMP(x) cerr << #x << ":" << x << endl
#define ZERO(x) memset(x, 0, sizeof(x))
#define ONE(x) memset(x, -1, sizeof(x))
#define fs first
#define sc second
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
rep(i, (int)v.size()) {
if (i)
os << ",";
os << v[i];
}
os << "}";
return os;
}
template <int i, class T> void print_tuple(ostream &, const T &) {}
template <int i, class T, class H, class... Args>
void print_tuple(ostream &os, const T &t) {
if (i)
os << ",";
os << get<i>(t);
print_tuple<i + 1, T, Args...>(os, t);
}
template <class... Args>
ostream &operator<<(ostream &os, const tuple<Args...> &t) {
os << "(";
print_tuple<0, tuple<Args...>, Args...>(os, t);
return os << ")";
}
ll read() {
ll i;
scanf("%lld", &i);
return i;
}
void printSpace() { printf(" "); }
void printEoln() { printf("\n"); }
void print(ll x, int suc = 1) {
printf("%lld", x);
if (suc == 1)
printEoln();
if (suc == 2)
printSpace();
}
template <class T> void print(const vector<T> &v, int suc = 1) {
rep(i, v.size()) print(v[i], i == int(v.size()) - 1 ? suc : 2);
}
string readString() {
static char buf[3341000];
scanf("%s", buf);
return string(buf);
}
char *readCharArray() {
static char buf[3341000];
static int bufUsed = 0;
char *ret = buf + bufUsed;
scanf("%s", ret);
bufUsed += strlen(ret) + 1;
return ret;
}
template <class T, class U> void chmax(T &a, U b) {
if (a < b)
a = b;
}
template <class T, class U> void chmin(T &a, U b) {
if (b < a)
a = b;
}
template <class T> T Sq(const T &t) { return t * t; }
#define CAPITAL
void Yes(bool ex = true) {
#ifdef CAPITAL
cout << "YES" << endl;
#else
cout << "Yes" << endl;
#endif
if (ex)
exit(0);
}
void No(bool ex = true) {
#ifdef CAPITAL
cout << "NO" << endl;
#else
cout << "No" << endl;
#endif
if (ex)
exit(0);
}
const ll infLL = LLONG_MAX / 3;
#ifdef int
const int inf = infLL;
#else
const int inf = INT_MAX / 2 - 100;
#endif
constexpr ll TEN(int n) { return n == 0 ? 1 : TEN(n - 1) * 10; }
template <class T> vector<T> Uniqued(const vector<T> &vv) {
auto v(vv);
sort(all(v));
v.erase(unique(all(v)), v.end());
return v;
}
template <class T> void MakeUniqued(vector<T> &v) {
sort(all(v));
v.erase(unique(all(v)), v.end());
}
const int Nmax = 200010;
vi tr[Nmax];
void dfs(int v, int p, int d, vi &dst) {
dst[v] = d;
for (auto to : tr[v])
if (to != p) {
dfs(to, v, d + 1, dst);
}
}
signed main() {
int n = read();
rep(_, n - 1) {
int a = read() - 1, b = read() - 1;
tr[a].pb(b);
tr[b].pb(a);
}
vi d(n);
dfs(0, -1, 0, d);
int r1 = max_element(all(d)) - d.begin();
dfs(r1, -1, 0, d);
int dia = *max_element(all(d)) + 1;
if (dia % 3 == 0)
cout << "First" << endl;
else
cout << "Second" << endl;
}
| #include <bits/stdc++.h>
#include <type_traits>
using namespace std;
using ll = long long;
#define int ll
#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) FOR(i, 0, b)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
auto &errStream = cerr;
#ifdef LOCAL
#define cerr (cerr << "-- line " << __LINE__ << " -- ")
#else
class CerrDummy {
} cerrDummy;
template <class T> CerrDummy &operator<<(CerrDummy &cd, const T &) {
return cd;
}
using charTDummy = char;
using traitsDummy = char_traits<charTDummy>;
CerrDummy &operator<<(CerrDummy &cd,
basic_ostream<charTDummy, traitsDummy> &(
basic_ostream<charTDummy, traitsDummy> &)) {
return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr << "reached" << endl
#define DMP(x) cerr << #x << ":" << x << endl
#define ZERO(x) memset(x, 0, sizeof(x))
#define ONE(x) memset(x, -1, sizeof(x))
#define fs first
#define sc second
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
rep(i, (int)v.size()) {
if (i)
os << ",";
os << v[i];
}
os << "}";
return os;
}
template <int i, class T> void print_tuple(ostream &, const T &) {}
template <int i, class T, class H, class... Args>
void print_tuple(ostream &os, const T &t) {
if (i)
os << ",";
os << get<i>(t);
print_tuple<i + 1, T, Args...>(os, t);
}
template <class... Args>
ostream &operator<<(ostream &os, const tuple<Args...> &t) {
os << "(";
print_tuple<0, tuple<Args...>, Args...>(os, t);
return os << ")";
}
ll read() {
ll i;
scanf("%lld", &i);
return i;
}
void printSpace() { printf(" "); }
void printEoln() { printf("\n"); }
void print(ll x, int suc = 1) {
printf("%lld", x);
if (suc == 1)
printEoln();
if (suc == 2)
printSpace();
}
template <class T> void print(const vector<T> &v, int suc = 1) {
rep(i, v.size()) print(v[i], i == int(v.size()) - 1 ? suc : 2);
}
string readString() {
static char buf[3341000];
scanf("%s", buf);
return string(buf);
}
char *readCharArray() {
static char buf[3341000];
static int bufUsed = 0;
char *ret = buf + bufUsed;
scanf("%s", ret);
bufUsed += strlen(ret) + 1;
return ret;
}
template <class T, class U> void chmax(T &a, U b) {
if (a < b)
a = b;
}
template <class T, class U> void chmin(T &a, U b) {
if (b < a)
a = b;
}
template <class T> T Sq(const T &t) { return t * t; }
#define CAPITAL
void Yes(bool ex = true) {
#ifdef CAPITAL
cout << "YES" << endl;
#else
cout << "Yes" << endl;
#endif
if (ex)
exit(0);
}
void No(bool ex = true) {
#ifdef CAPITAL
cout << "NO" << endl;
#else
cout << "No" << endl;
#endif
if (ex)
exit(0);
}
const ll infLL = LLONG_MAX / 3;
#ifdef int
const int inf = infLL;
#else
const int inf = INT_MAX / 2 - 100;
#endif
constexpr ll TEN(int n) { return n == 0 ? 1 : TEN(n - 1) * 10; }
template <class T> vector<T> Uniqued(const vector<T> &vv) {
auto v(vv);
sort(all(v));
v.erase(unique(all(v)), v.end());
return v;
}
template <class T> void MakeUniqued(vector<T> &v) {
sort(all(v));
v.erase(unique(all(v)), v.end());
}
const int Nmax = 200010;
vi tr[Nmax];
void dfs(int v, int p, int d, vi &dst) {
dst[v] = d;
for (auto to : tr[v])
if (to != p) {
dfs(to, v, d + 1, dst);
}
}
signed main() {
int n = read();
rep(_, n - 1) {
int a = read() - 1, b = read() - 1;
tr[a].pb(b);
tr[b].pb(a);
}
vi d(n);
dfs(0, -1, 0, d);
int r1 = max_element(all(d)) - d.begin();
dfs(r1, -1, 0, d);
int dia = *max_element(all(d)) + 1;
if (dia % 3 != 2)
cout << "First" << endl;
else
cout << "Second" << endl;
}
| [] | 870,152 | 870,153 | u354336886 | cpp |
p03055 | #include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i, N) for (LL i = 0; i < N; ++i)
typedef long long int LL;
std::vector<std::vector<LL>> G;
std::vector<LL> dist;
void dfs(LL v, LL d, LL p) {
dist[v] = d;
for (LL u : G[v]) {
if (u != p)
dfs(u, d + 1, v);
}
}
int main() {
LL N;
in >> N;
std::vector<LL> a(N), b(N);
rep(i, N) in >> a[i] >> b[i];
G.resize(N + 1);
dist.resize(N + 1);
LL maxD_num = 0, maxD_index, diameter = 0;
rep(i, N) {
G[a[i]].push_back(b[i]);
G[b[i]].push_back(a[i]);
}
dfs(1, 0, -1);
for (LL i = 1; i <= N; ++i) {
if (maxD_num < dist[i]) {
maxD_num = dist[i];
maxD_index = i;
}
}
dfs(maxD_index, 0, -1);
for (LL i = 1; i <= N; ++i)
diameter = std::max(diameter, dist[i]);
out << (diameter % 3 == 2 ? "First" : "Second") << std::endl;
}
| #include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i, N) for (LL i = 0; i < N; ++i)
typedef long long int LL;
std::vector<std::vector<LL>> G;
std::vector<LL> dist;
void dfs(LL v, LL d, LL p) {
dist[v] = d;
for (LL u : G[v]) {
if (u != p)
dfs(u, d + 1, v);
}
}
int main() {
LL N;
in >> N;
std::vector<LL> a(N), b(N);
rep(i, N) in >> a[i] >> b[i];
G.resize(N + 1);
dist.resize(N + 1);
LL maxD_num = 0, maxD_index, diameter = 0;
rep(i, N) {
G[a[i]].push_back(b[i]);
G[b[i]].push_back(a[i]);
}
dfs(1, 0, -1);
for (LL i = 1; i <= N; ++i) {
if (maxD_num < dist[i]) {
maxD_num = dist[i];
maxD_index = i;
}
}
dfs(maxD_index, 0, -1);
for (LL i = 1; i <= N; ++i)
diameter = std::max(diameter, dist[i]);
out << (diameter % 3 == 1 ? "Second" : "First") << std::endl;
}
| [
"literal.number.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change",
"literal.string.change"
] | 870,158 | 870,159 | u660613376 | cpp |
p03055 | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) \
sort(x.begin(), x.end()); \
x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int(i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int(i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) \
cerr << "(" << #x << ", " << #y << ") = " \
<< "(" << x << ", " << y << ")" << endl;
#define dbg3(x, y, z) \
cerr << "(" << #x << ", " << #y << ", " << #z << ") = " \
<< "(" << x << ", " << y << ", " << z << ")" << endl;
#define dbgB(value, size) cerr << #value << ": " << bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <typename T> void print1(T begin, T end) {
while (begin != end) {
cerr << (*begin) << " ";
*begin++;
}
cerr << endl;
}
template <typename T> void print2(T Array, int height, int width) {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
cerr << " " << Array[i][j];
}
cerr << endl;
}
}
void print() { std::cerr << endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
std::cerr << head << " ";
print(std::forward<Tail>(tail)...);
}
template <class T> void Add(T &a, const T &b, const T &mod = 1000000007) {
int val = ((a % mod) + (b % mod)) % mod;
if (val < 0) {
val += mod;
}
a = val;
}
template <typename X, typename T> auto vectors(X x, T a) {
return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
auto cont = vectors(y, z, zs...);
return vector<decltype(cont)>(x, cont);
}
// ------------------------------------------------------------------------------------------
int N;
const int maxV = 222222;
vector<int> G[maxV]; // 頂点情報のみのグラフ
// treeDFS(親, 現在地, 根から現在地までの距離, 根からの最大の距離,
// 根から最大の距離となる頂点
void treeDFS(int from, int current, int dist, int &maxDist, int &maxVertex) {
// 距離と終点を更新
if (dist > maxDist) {
maxDist = dist;
maxVertex = current;
}
for (auto to : G[current]) {
// 逆流を防ぐ
if (to == from)
continue;
treeDFS(current, to, dist + 1, maxDist, maxVertex);
}
}
int getTreeDiameter() {
int start = 0, end = 0, maxDist = 0;
treeDFS(-1, start, 0, maxDist, end);
start = end, end = 0, maxDist = 0;
treeDFS(-1, start, 0, maxDist, end);
return maxDist;
}
signed main() {
cin >> N;
rep(i, N - 1) {
int a, b;
cin >> a >> b;
a--, b--;
G[a].push_back(b);
G[b].push_back(a);
}
int dia = getTreeDiameter();
dbg(dia)
puts(dia % 3 == 2 ? "First" : "Second");
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) \
sort(x.begin(), x.end()); \
x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int(i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int(i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) \
cerr << "(" << #x << ", " << #y << ") = " \
<< "(" << x << ", " << y << ")" << endl;
#define dbg3(x, y, z) \
cerr << "(" << #x << ", " << #y << ", " << #z << ") = " \
<< "(" << x << ", " << y << ", " << z << ")" << endl;
#define dbgB(value, size) cerr << #value << ": " << bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <typename T> void print1(T begin, T end) {
while (begin != end) {
cerr << (*begin) << " ";
*begin++;
}
cerr << endl;
}
template <typename T> void print2(T Array, int height, int width) {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
cerr << " " << Array[i][j];
}
cerr << endl;
}
}
void print() { std::cerr << endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
std::cerr << head << " ";
print(std::forward<Tail>(tail)...);
}
template <class T> void Add(T &a, const T &b, const T &mod = 1000000007) {
int val = ((a % mod) + (b % mod)) % mod;
if (val < 0) {
val += mod;
}
a = val;
}
template <typename X, typename T> auto vectors(X x, T a) {
return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
auto cont = vectors(y, z, zs...);
return vector<decltype(cont)>(x, cont);
}
// ------------------------------------------------------------------------------------------
int N;
const int maxV = 222222;
vector<int> G[maxV]; // 頂点情報のみのグラフ
// treeDFS(親, 現在地, 根から現在地までの距離, 根からの最大の距離,
// 根から最大の距離となる頂点
void treeDFS(int from, int current, int dist, int &maxDist, int &maxVertex) {
// 距離と終点を更新
if (dist > maxDist) {
maxDist = dist;
maxVertex = current;
}
for (auto to : G[current]) {
// 逆流を防ぐ
if (to == from)
continue;
treeDFS(current, to, dist + 1, maxDist, maxVertex);
}
}
int getTreeDiameter() {
int start = 0, end = 0, maxDist = 0;
treeDFS(-1, start, 0, maxDist, end);
start = end, end = 0, maxDist = 0;
treeDFS(-1, start, 0, maxDist, end);
return maxDist;
}
signed main() {
cin >> N;
rep(i, N - 1) {
int a, b;
cin >> a >> b;
a--, b--;
G[a].push_back(b);
G[b].push_back(a);
}
int dia = getTreeDiameter();
// int dia;
// cin >> dia;
dbg(dia) puts(dia % 3 == 1 ? "Second" : "First");
return 0;
}
| [
"literal.number.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"call.arguments.change",
"expression.operation.binary.change",
"io.output.change",
"literal.string.change"
] | 870,162 | 870,163 | u219873012 | cpp |
p03055 | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) \
sort(x.begin(), x.end()); \
x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int(i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int(i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) \
cerr << "(" << #x << ", " << #y << ") = " \
<< "(" << x << ", " << y << ")" << endl;
#define dbg3(x, y, z) \
cerr << "(" << #x << ", " << #y << ", " << #z << ") = " \
<< "(" << x << ", " << y << ", " << z << ")" << endl;
#define dbgB(value, size) cerr << #value << ": " << bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <typename T> void print1(T begin, T end) {
while (begin != end) {
cerr << (*begin) << " ";
*begin++;
}
cerr << endl;
}
template <typename T> void print2(T Array, int height, int width) {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
cerr << " " << Array[i][j];
}
cerr << endl;
}
}
void print() { std::cerr << endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
std::cerr << head << " ";
print(std::forward<Tail>(tail)...);
}
template <class T> void Add(T &a, const T &b, const T &mod = 1000000007) {
int val = ((a % mod) + (b % mod)) % mod;
if (val < 0) {
val += mod;
}
a = val;
}
template <typename X, typename T> auto vectors(X x, T a) {
return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
auto cont = vectors(y, z, zs...);
return vector<decltype(cont)>(x, cont);
}
// ------------------------------------------------------------------------------------------
int N;
const int maxV = 222222;
vector<int> G[maxV]; // 頂点情報のみのグラフ
// treeDFS(親, 現在地, 根から現在地までの距離, 根からの最大の距離,
// 根から最大の距離となる頂点
void treeDFS(int from, int current, int dist, int &maxDist, int &maxVertex) {
// 距離と終点を更新
if (dist > maxDist) {
maxDist = dist;
maxVertex = current;
}
for (auto to : G[current]) {
// 逆流を防ぐ
if (to == from)
continue;
treeDFS(current, to, dist + 1, maxDist, maxVertex);
}
}
int getTreeDiameter() {
int start = 0, end = 0, maxDist = 0;
treeDFS(-1, start, 0, maxDist, end);
start = end, end = 0, maxDist = 0;
treeDFS(-1, start, 0, maxDist, end);
return maxDist;
}
signed main() {
cin >> N;
rep(i, N - 1) {
int a, b;
cin >> a >> b;
a--, b--;
G[a].push_back(b);
G[b].push_back(a);
}
int dia = getTreeDiameter();
dbg(dia)
puts(dia % 3 == 2 ? "First" : "Second");
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) \
sort(x.begin(), x.end()); \
x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int(i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int(i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) \
cerr << "(" << #x << ", " << #y << ") = " \
<< "(" << x << ", " << y << ")" << endl;
#define dbg3(x, y, z) \
cerr << "(" << #x << ", " << #y << ", " << #z << ") = " \
<< "(" << x << ", " << y << ", " << z << ")" << endl;
#define dbgB(value, size) cerr << #value << ": " << bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <typename T> void print1(T begin, T end) {
while (begin != end) {
cerr << (*begin) << " ";
*begin++;
}
cerr << endl;
}
template <typename T> void print2(T Array, int height, int width) {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
cerr << " " << Array[i][j];
}
cerr << endl;
}
}
void print() { std::cerr << endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
std::cerr << head << " ";
print(std::forward<Tail>(tail)...);
}
template <class T> void Add(T &a, const T &b, const T &mod = 1000000007) {
int val = ((a % mod) + (b % mod)) % mod;
if (val < 0) {
val += mod;
}
a = val;
}
template <typename X, typename T> auto vectors(X x, T a) {
return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
auto cont = vectors(y, z, zs...);
return vector<decltype(cont)>(x, cont);
}
// ------------------------------------------------------------------------------------------
int N;
const int maxV = 222222;
vector<int> G[maxV]; // 頂点情報のみのグラフ
// treeDFS(親, 現在地, 根から現在地までの距離, 根からの最大の距離,
// 根から最大の距離となる頂点
void treeDFS(int from, int current, int dist, int &maxDist, int &maxVertex) {
// 距離と終点を更新
if (dist > maxDist) {
maxDist = dist;
maxVertex = current;
}
for (auto to : G[current]) {
// 逆流を防ぐ
if (to == from)
continue;
treeDFS(current, to, dist + 1, maxDist, maxVertex);
}
}
int getTreeDiameter() {
int start = 0, end = 0, maxDist = 0;
treeDFS(-1, start, 0, maxDist, end);
start = end, end = 0, maxDist = 0;
treeDFS(-1, start, 0, maxDist, end);
return maxDist;
}
signed main() {
cin >> N;
rep(i, N - 1) {
int a, b;
cin >> a >> b;
a--, b--;
G[a].push_back(b);
G[b].push_back(a);
}
int dia = getTreeDiameter();
// int dia;
// cin >> dia;
dbg(dia) dia++;
puts(dia % 3 == 2 ? "Second" : "First");
return 0;
} | [
"expression.unary.arithmetic.add",
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 870,162 | 870,164 | u219873012 | cpp |
p03055 | #define DEBUG 0
/**
* File : C2.cpp
* Author : Kazune Takahashi
* Created : 2019-5-21 22:20:49
* Powered by Visual Studio Code
*/
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
#include <complex>
#include <functional>
#include <iomanip> // << fixed << setprecision(xxx)
#include <iostream>
#include <map> // if (M.find(key) != M.end()) { }
#include <queue>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(10101010));
#include <set>
#include <stack>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <tuple>
#include <vector>
// start = std::chrono::system_clock::now();
// double elapsed =
// std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
typedef long long ll;
// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};
// const int C = 1e6+10;
// const ll M = 1000000007;
int N;
vector<int> V[200010];
int visited[200010];
void dfs(int v, int d) {
if (visited[v] >= 0) {
return;
}
visited[v] = d;
for (auto x : V[v]) {
dfs(x, d + 1);
}
}
int main() {
cin >> N;
for (auto i = 0; i < N - 1; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
V[a].push_back(b);
V[b].push_back(a);
}
fill(visited, visited + N, -1);
dfs(0, 0);
int maxi = 0;
int ind = 0;
for (auto i = 0; i < N; i++) {
if (visited[i] > maxi) {
maxi = visited[i];
ind = i;
}
}
fill(visited, visited + N, -1);
dfs(ind, 0);
maxi = 0;
for (auto i = 0; i < N; i++) {
if (visited[i] > maxi) {
maxi = visited[i];
}
}
if (maxi % 3 == 2) {
cout << "First" << endl;
} else {
cout << "Second" << endl;
}
} | #define DEBUG 0
/**
* File : C2.cpp
* Author : Kazune Takahashi
* Created : 2019-5-21 22:20:49
* Powered by Visual Studio Code
*/
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
#include <complex>
#include <functional>
#include <iomanip> // << fixed << setprecision(xxx)
#include <iostream>
#include <map> // if (M.find(key) != M.end()) { }
#include <queue>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(10101010));
#include <set>
#include <stack>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <tuple>
#include <vector>
// start = std::chrono::system_clock::now();
// double elapsed =
// std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
typedef long long ll;
// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};
// const int C = 1e6+10;
// const ll M = 1000000007;
int N;
vector<int> V[200010];
int visited[200010];
void dfs(int v, int d) {
if (visited[v] >= 0) {
return;
}
visited[v] = d;
for (auto x : V[v]) {
dfs(x, d + 1);
}
}
int main() {
cin >> N;
for (auto i = 0; i < N - 1; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
V[a].push_back(b);
V[b].push_back(a);
}
fill(visited, visited + N, -1);
dfs(0, 0);
int maxi = 0;
int ind = 0;
for (auto i = 0; i < N; i++) {
if (visited[i] > maxi) {
maxi = visited[i];
ind = i;
}
}
fill(visited, visited + N, -1);
dfs(ind, 0);
maxi = 0;
for (auto i = 0; i < N; i++) {
if (visited[i] > maxi) {
maxi = visited[i];
}
}
if (maxi % 3 == 1) {
cout << "Second" << endl;
} else {
cout << "First" << endl;
}
} | [
"literal.number.change",
"control_flow.branch.if.condition.change",
"literal.string.change",
"io.output.change"
] | 870,165 | 870,166 | u521272340 | cpp |
p03055 |
#if 1
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define int long long
#define uint unsigned long long
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int INF = 1145141919810893;
//
struct Edge {
int next;
int w = 1;
};
template <class T> struct Vertex {
std::vector<Edge> edges;
T val = {};
};
template <class T> struct Graph {
std::vector<Vertex<T>> vertex;
public:
Graph(size_t n = 0) : vertex(n) {}
void setArray(int u, int v, int w = 1) {
vertex[u].edges.push_back(Edge{v, w});
}
void setConnect(int u, int v, int w = 1) {
setArray(u, v, w);
setArray(v, u, w);
}
T &val(int u) { return vertex[u].val; }
void dfsImpl(int pos, int prev,
std::function<void(int now, int next, int w)> func) {
for (auto &e : vertex[pos].edges) {
if (e.next == prev)
continue;
func(pos, e.next, e.w);
dfsImpl(e.next, pos, func);
}
}
void dfs(int pos, std::function<void(int now, int next, int w)> func) {
dfsImpl(pos, -1, func);
}
// graph.dfs(0, [](Vertex<int>& now, Vertex<int>& next, int w) {});
int radius() {
if (vertex.size() <= 1)
return 0;
int farestID = -1;
int far = -1;
val(0) = 0;
dfs(0, [&](int now, int next, int w) {
val(next) = 1 + val(now);
if (val(next) > far) {
far = val(next);
farestID = next;
}
});
far = -1;
val(farestID) = 0;
dfs(farestID, [&](int now, int next, int w) {
val(next) = 1 + val(now);
if (val(next) > far) {
far = val(next);
farestID = next;
}
});
return far;
}
};
#define LOADVEC(type, name, N) \
std::vector<type> name(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
cin >> name[nnn]; \
}
#define LOADVEC2(type, name0, name1, N) \
std::vector<type> name0(N), name1(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
cin >> name0[nnn]; \
cin >> name1[nnn]; \
}
#define LOADVEC3(type, name0, name1, name2, N) \
std::vector<type> name0(N), name1(N), name2(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
cin >> name0[nnn]; \
cin >> name1[nnn]; \
cin >> name2[nnn]; \
}
#define LOAD(type, name) \
type name; \
cin >> name;
void proc();
signed main() {
ios::sync_with_stdio(false);
proc();
return 0;
}
/*
--------------------------------------------------------
--------------------------------------------------------
--------------- template ----------------------
--------------------------------------------------------
--------------------------------------------------------
*/
void proc() {
LOAD(int, N);
Graph<int> graph(N);
for (int i = 0; i < N - 1; ++i) {
int a, b;
cin >> a >> b;
graph.setConnect(a - 1, b - 1);
}
if (graph.radius() % 3 == 2) {
cout << "First" << endl;
} else {
cout << "Second" << endl;
}
}
#endif
|
#if 1
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define int long long
#define uint unsigned long long
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int INF = 1145141919810893;
//
struct Edge {
int next;
int w = 1;
};
template <class T> struct Vertex {
std::vector<Edge> edges;
T val = {};
};
template <class T> struct Graph {
std::vector<Vertex<T>> vertex;
public:
Graph(size_t n = 0) : vertex(n) {}
void setArray(int u, int v, int w = 1) {
vertex[u].edges.push_back(Edge{v, w});
}
void setConnect(int u, int v, int w = 1) {
setArray(u, v, w);
setArray(v, u, w);
}
T &val(int u) { return vertex[u].val; }
void dfsImpl(int pos, int prev,
std::function<void(int now, int next, int w)> func) {
for (auto &e : vertex[pos].edges) {
if (e.next == prev)
continue;
func(pos, e.next, e.w);
dfsImpl(e.next, pos, func);
}
}
void dfs(int pos, std::function<void(int now, int next, int w)> func) {
dfsImpl(pos, -1, func);
}
// graph.dfs(0, [](Vertex<int>& now, Vertex<int>& next, int w) {});
int radius() {
if (vertex.size() <= 1)
return 0;
int farestID = -1;
int far = -1;
val(0) = 0;
dfs(0, [&](int now, int next, int w) {
val(next) = 1 + val(now);
if (val(next) > far) {
far = val(next);
farestID = next;
}
});
far = -1;
val(farestID) = 0;
dfs(farestID, [&](int now, int next, int w) {
val(next) = 1 + val(now);
if (val(next) > far) {
far = val(next);
farestID = next;
}
});
return far;
}
};
#define LOADVEC(type, name, N) \
std::vector<type> name(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
cin >> name[nnn]; \
}
#define LOADVEC2(type, name0, name1, N) \
std::vector<type> name0(N), name1(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
cin >> name0[nnn]; \
cin >> name1[nnn]; \
}
#define LOADVEC3(type, name0, name1, name2, N) \
std::vector<type> name0(N), name1(N), name2(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
cin >> name0[nnn]; \
cin >> name1[nnn]; \
cin >> name2[nnn]; \
}
#define LOAD(type, name) \
type name; \
cin >> name;
void proc();
signed main() {
ios::sync_with_stdio(false);
proc();
return 0;
}
/*
--------------------------------------------------------
--------------------------------------------------------
--------------- template ----------------------
--------------------------------------------------------
--------------------------------------------------------
*/
void proc() {
LOAD(int, N);
Graph<int> graph(N);
for (int i = 0; i < N - 1; ++i) {
int a, b;
cin >> a >> b;
graph.setConnect(a - 1, b - 1);
}
if (graph.radius() % 3 == 1) {
cout << "Second" << endl;
} else {
cout << "First" << endl;
}
}
#endif
| [
"literal.number.change",
"control_flow.branch.if.condition.change",
"literal.string.change",
"io.output.change"
] | 870,169 | 870,170 | u154068540 | cpp |
p03055 | #include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 10;
vector<int> adj[N];
bool vis[N];
int d[N];
void dfs(int u) {
vis[u] = 1;
for (int v : adj[u]) {
if (!vis[v]) {
d[v] = d[u] + 1;
dfs(v);
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
u--;
v--;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(0);
int u = max_element(d, d + n) - d;
d[u] = 0;
memset(vis, 0, sizeof vis);
dfs(u);
int diam = *max_element(d, d + n);
puts(diam % 3 == 1 ? "First" : "Second");
return 0;
}
| #include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 10;
vector<int> adj[N];
bool vis[N];
int d[N];
void dfs(int u) {
vis[u] = 1;
for (int v : adj[u]) {
if (!vis[v]) {
d[v] = d[u] + 1;
dfs(v);
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
u--;
v--;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(0);
int u = max_element(d, d + n) - d;
d[u] = 0;
memset(vis, 0, sizeof vis);
dfs(u);
int diam = *max_element(d, d + n);
puts(diam % 3 != 1 ? "First" : "Second");
return 0;
}
| [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"call.arguments.change",
"expression.operation.binary.change",
"io.output.change"
] | 870,174 | 870,175 | u404421571 | cpp |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.