#include <bits/stdc++.h>
#include "train.h"
/// 500 485 462 A4
using namespace std;
typedef long long int ll;
typedef complex<double> point;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
//#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
const int N=5e3+10,inf=(ll)1e15;
ll vis[N];
ll t[N];
vector <int> g[N],in[N];
std::vector<int32_t> who_wins(std::vector<int32_t> A, std::vector<int32_t> R, std::vector<int32_t> U, std::vector<int32_t> V) {
ll n=A.size(),m=U.size();
for (int i=0;i<n;i++){
g[i].clear();
in[i].clear();
}
for (int i=0;i<U.size();i++){
g[U[i]].pb(V[i]);
in[V[i]].pb(U[i]);
}
while(true){
queue <int> q;
for (int i=0;i<n;i++){
t[i]=g[i].size();
if (vis[i]==0 && R[i]==1){
q.push(i);
t[i]=0;
}
}
while(q.size()){
ll v=q.front();
t[v]=0;
q.pop();
for (auto u : in[v]){
// cout << u << " " << v << " " << A[u] << " " << t[u] << endl;
if (A[u]==1 && t[u]!=0){
t[u]=0;
q.push(u);
}
else if (t[u]!=0){
t[u]--;
if (t[u]==0) q.push(u);
}
}
}
ll p1=0;
for (int i=0;i<n;i++){
if (vis[i] || R[i]==0) continue;
ll p2=0;
for (auto u : g[i]){
if (t[u]==0) p2=1;
}
if (p2==0){
p1=1;
vis[i]=1;
}
}
if (p1==0) break;
}
ll p1=0;
for (int i=0;i<n;i++){
if (vis[i]==0 && R[i]==1) p1=1;
}
vector <int32_t> ans;
for (int i=0;i<n;i++){
if (p1==0) ans.pb(0);
else {
if (t[i]==0) ans.pb(1);
else ans.pb(0);
}
}
return ans;
}
/*
int32_t main() {
int n, m;
assert(2 == scanf("%d %d", &n, &m));
vector<int32_t> a(n), r(n), u(m), v(m);
for(int i = 0; i < n; i++)
assert(1 == scanf("%d", &a[i]));
for(int i = 0; i < n; i++)
assert(1 == scanf("%d", &r[i]));
for(int i = 0; i < m; i++)
assert(2 == scanf("%d %d", &u[i], &v[i]));
vector<int32_t> res = who_wins(a, r, u, v);
for(int i = 0; i < (int)res.size(); i++)
printf(i ? " %d" : "%d", res[i]);
printf("\n");
return 0;
}
*/
/*
2 4
0 1
1 0
0 0
0 1
1 0
1 1
*/
Compilation message
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:27:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for (int i=0;i<U.size();i++){
| ~^~~~~~~~~
train.cpp:22:16: warning: unused variable 'm' [-Wunused-variable]
22 | ll n=A.size(),m=U.size();
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
1100 KB |
3rd lines differ - on the 42nd token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Incorrect |
1 ms |
460 KB |
3rd lines differ - on the 3rd token, expected: '0', found: '1' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
1636 KB |
Output is correct |
2 |
Correct |
135 ms |
1628 KB |
Output is correct |
3 |
Correct |
183 ms |
1612 KB |
Output is correct |
4 |
Correct |
9 ms |
1612 KB |
Output is correct |
5 |
Correct |
13 ms |
1616 KB |
Output is correct |
6 |
Correct |
10 ms |
1612 KB |
Output is correct |
7 |
Correct |
9 ms |
1644 KB |
Output is correct |
8 |
Correct |
9 ms |
1484 KB |
Output is correct |
9 |
Correct |
8 ms |
1480 KB |
Output is correct |
10 |
Correct |
8 ms |
1484 KB |
Output is correct |
11 |
Correct |
8 ms |
1484 KB |
Output is correct |
12 |
Correct |
8 ms |
1532 KB |
Output is correct |
13 |
Correct |
9 ms |
1636 KB |
Output is correct |
14 |
Correct |
9 ms |
1612 KB |
Output is correct |
15 |
Correct |
9 ms |
1628 KB |
Output is correct |
16 |
Correct |
9 ms |
1688 KB |
Output is correct |
17 |
Correct |
9 ms |
1612 KB |
Output is correct |
18 |
Correct |
368 ms |
1176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
1356 KB |
3rd lines differ - on the 696th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1628 KB |
Output is correct |
2 |
Correct |
12 ms |
1612 KB |
Output is correct |
3 |
Correct |
10 ms |
1612 KB |
Output is correct |
4 |
Correct |
8 ms |
1488 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
7 ms |
1100 KB |
Output is correct |
7 |
Correct |
6 ms |
1228 KB |
Output is correct |
8 |
Correct |
6 ms |
1336 KB |
Output is correct |
9 |
Correct |
6 ms |
1356 KB |
Output is correct |
10 |
Correct |
2 ms |
716 KB |
Output is correct |
11 |
Correct |
5 ms |
1228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
1100 KB |
3rd lines differ - on the 42nd token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |