#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<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 && R[i]==0 && g[i].size()>1) cout << 1/0;
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:23:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for (int i=0;i<U.size();i++){
| ~^~~~~~~~~
train.cpp:74:63: warning: division by zero [-Wdiv-by-zero]
74 | if (t[i]==0 && R[i]==0 && g[i].size()>1) cout << 1/0;
| ~^~
train.cpp:22:16: warning: unused variable 'm' [-Wunused-variable]
22 | ll n=A.size(),m=U.size();
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
1996 KB |
Execution killed with signal 8 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
844 KB |
Execution killed with signal 8 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
1636 KB |
Output is correct |
2 |
Correct |
137 ms |
1608 KB |
Output is correct |
3 |
Correct |
214 ms |
1612 KB |
Output is correct |
4 |
Runtime error |
10 ms |
3020 KB |
Execution killed with signal 8 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
9 ms |
2636 KB |
Execution killed with signal 8 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
10 ms |
3020 KB |
Execution killed with signal 8 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
1996 KB |
Execution killed with signal 8 |
2 |
Halted |
0 ms |
0 KB |
- |