이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "train.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define all(x) (x).begin(),(x).end()
#define X first
#define Y second
#define sep ' '
#define endl '\n'
#define SZ(x) ll(x.size())
const ll MAXN = 5010;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; //998244353; //1e9 + 9;
int n , m , A[MAXN] , R[MAXN] , cnt[MAXN] , ans[MAXN];
vector<int> adj[MAXN] , radj[MAXN];
void Solve(){
queue<int> Q;
for(int i = 0 ; i < n ; i++){
if(cnt[i] <= 0){
Q.push(i);
}
}
while(!Q.empty()){
int v = Q.front(); Q.pop();
for(int u : radj[v]){
cnt[u]--;
if(cnt[u] == 0){
Q.push(u);
}
}
}
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
n = SZ(a); m = SZ(u);
for(int i = 0 ; i < n ; i++){
A[i] = a[i];
}
for(int i = 0 ; i < n ; i++){
R[i] = r[i];
}
for(int i = 0 ; i < m ; i++){
adj[u[i]].push_back(v[i]);
radj[v[i]].push_back(u[i]);
}
for(int i = 0 ; i < n ; i++){
for(int j = 0 ; j < n ; j++){
if(i == j){
cnt[j] = 0;
}
else if(A[j]){
cnt[j] = 1;
}
else{
cnt[j] = SZ(adj[j]);
}
}
Solve();
cnt[i] = (A[i] ? 1 : SZ(adj[i]));
for(int j : adj[i]){
if(i == j || cnt[j] <= 0){
cnt[i]--;
}
}
for(int j = 0 ; j < n ; j++){
if(R[j] && cnt[j] <= 0){
cnt[j] = 0;
}
else if(A[j]){
cnt[j] = 1;
}
else{
cnt[j] = SZ(adj[j]);
}
}
Solve();
if(cnt[i] <= 0){
ans[i] = 1;
}
}
for(int i = 0 ; i < n ; i++){
if(ans[i]){
cnt[i] = 0;
}
else if(A[i]){
cnt[i] = 1;
}
else{
cnt[i] = SZ(adj[i]);
}
}
Solve();
vector<int> res;
for(int i = 0 ; i < n ; i++){
res.push_back((cnt[i] <= 0 ? 1 : 0));
}
return res;
}
# | 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... |