#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<int,int>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
#include "train.h"
ll comp[5005];
bool v[5005] = {0};
ll posoi[5005] = {0};
vector<vll>adj;
vll nodes;
vll epia;
void solve(ll idx,bool V){
if(V){
nodes.pb(idx);
}
else{
epia.pb(idx);
}
for(auto x:adj[idx]){
if(!v[x]){
v[x] = 1;
solve(x,V);
}
}
}vector<vll>adj2;
void dfs(ll idx){
v[idx] = 1;
for(auto x:adj2[idx]){
if(!v[x]){
dfs(x);
}
}
}
vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
vector<int> res(a.size());
ll n = a.size();
ll m = u.size();
adj.assign(n+5,vll());
f(i,0,m){
adj[u[i]].pb(v[i]);
}
f(i,0,n){
if(!v[i]){
v[i] = 1;
solve(i,1);
}
}
reverse(all(nodes));
f(j,0,n){
v[j] = 0;
}
for(auto x:nodes){
if(!v[x]){
v[x] = 1;
epia.clear();
solve(x,0);
for(auto y:epia){
comp[y] = x;
}
}
}
bool ok[n] = {0};
bool self[n] = {0};
f(i,0,n){
posoi[comp[i]]++;
ok[comp[i]] |= r[i];
for(auto x:adj[i]){
adj[comp[i]].pb(comp[x]);
if(x == i){
self[comp[i]] = 1;
}
}
}
f(i,0,n){
f(j,0,n){
v[j] = 0;
}
if(posoi[comp[i]] == 1){
dfs(comp[i]);
}
res[i] = 0;
f(j,0,n){
if((v[j] && ok[j]) && (posoi[j] > 1 || self[j])){
res[i] = 1;
}
}
}
return res;
}
/*
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;
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
40 ms |
972 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
9 ms |
3252 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
2508 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
9 ms |
2892 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
40 ms |
972 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |