This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "train.h"
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pii pair<int, int>
#define szof(s) (int)s.size()
#define all(s) s.begin(), s.end()
using namespace std;
typedef vector<int> vi;
const int MAXN = 5001;
struct LineSolve {
vi a, r, u, v;
int n, m;
vector <int> g[MAXN];
vector <int> rg[MAXN];
LineSolve (vi A, vi R, vi U, vi V) {
a = A;
r = R;
u = U;
v = V;
n = szof(a);
m = szof(u);
for (int i = 0; i < m; i++) {
g[u[i]].push_back(v[i]);
rg[v[i]].push_back(u[i]);
}
}
void solve(vector <int> &ans) {
vector <bool> used(MAXN, false);
vector <int> ends;
for (int i = 0; i < m; i++) {
if (u[i] == v[i]) {
ends.push_back(u[i]);
}
}
for (int x : ends) {
vector <int> path = {};
int answer = r[x];
ans[x] = answer;
if (szof(rg[x]) == 2) {
int v =(rg[x][0] == x ? rg[x][1] : rg[x][0]);
while(1) {
ans[v] = answer;
if (szof(rg[v]) == 0) {
break;
}
assert(v != rg[v][0]);
v = rg[v][0];
}
}
}
}
};
vi who_wins(vi a, vi r, vi u, vi v) {
vi res(a.size(), -1);
LineSolve subtask1(a, r, u, v);
subtask1.solve(res);
return res;
}
//signed main() {
//int n, m;
//cin >> n >> m;
//vector <int> a(n), r(n);
//vector <int> u(m), v(m);
//for (int i = 0; i < n; i++) {
//cin >> a[i];
//}
//for (int i = 0; i < n; i++) {
//cin >> r[i];
//}
//for (int i = 0; i < m; i++) {
//cin >> u[i];
//}
//for (int i = 0; i < m; i++) {
//cin >> v[i];
//}
//vector <int> ans = who_wins(a, r, u, v);
//for (int i = 0; i < n; i++) {
//cout << i << ": " << ans[i] << endl;
//}
//}
/*
7 7
0 1 0 1 0 1 0
1 0 0 0 1 0 1
0 1 2 3 4 5 6
0 2 3 4 4 6 6
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |