#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define pb push_back
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ii = pair<int,int>;
using iii = tuple<int,int,int>;
const int inf = 2e9+1;
const int mod = 1e9+7;
const int maxn = 5005;
template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; }
template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; }
vector<int>g[maxn];
int deg[maxn], vis[maxn];
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
int n = sz(a), m = sz(u);
for(int i=0;i<m;++i){
int x = u[i], y = v[i];
if(x==y&&r[x]==1&&a[x]==0)continue;
g[y].pb(x);
}
vector<int>resp(n);
queue<int>q;
for(int i=0;i<n;++i){
if(r[i]==1){
//adendo: so vale se existe i->i
//checar essa condicao em O(n)
for(auto j:g[i]){
if(a[j]==1||sz(g[j])==1){
q.push(j);
vis[j] = 1;
}
}
while(!q.empty()){
int x = q.front();q.pop();
for(auto y:g[x]){
++deg[y];
if(!vis[y]&&(a[y]==1||deg[y]==sz(g[y]))){
vis[y] = 1;
q.push(y);
}
}
}
if(vis[i]){
q.push(i);
resp[i] = 1;
}
for(int j=0;j<n;++j)vis[j] = deg[j] = 0;
}
}
while(!q.empty()){
int x = q.front(); q.pop();
for(auto y:g[x]){
++deg[y];
if(!resp[y]&&(a[y]==1||deg[y]==sz(g[y]))){
resp[y] = 1;
q.push(y);
}
}
}
return resp;
}
// int main() {
// int n, m;
// assert(2 == scanf("%d %d", &n, &m));
// vector<int> 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<int> 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;
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
724 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
980 KB |
Output is correct |
2 |
Correct |
97 ms |
1236 KB |
Output is correct |
3 |
Correct |
127 ms |
1280 KB |
Output is correct |
4 |
Incorrect |
285 ms |
1264 KB |
3rd lines differ - on the 3822nd token, expected: '1', found: '0' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
852 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
980 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
724 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |