이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "train.h"
#include<bits/stdc++.h>
using namespace std;
const int MN=5000+100;
bool g[MN][MN];
vector<int> adj[MN],radj[MN];
vector<int> topol;
bool mark[MN];
int cmp[MN],szcmp[MN];
int n,m;
void dfs(int v){
mark[v]=1;
for(int u:adj[v]){
if(!mark[u]){
dfs(u);
}
}
topol.push_back(v);
}
void dfs2(int v,int cmpn){
mark[v]=1;
cmp[v]=cmpn;
szcmp[cmpn]++;
for(int u:radj[v]){
if(!mark[u]){
dfs2(u,cmpn);
}
}
}
void scc(){
for(int i=0;i<n;i++){
if(!mark[i]){
dfs(i);
}
}
memset(mark,0,sizeof mark);
int cnt=0;
for(int i=n-1;i>=0;i--){
if(!mark[topol[i]]){
dfs2(topol[i],cnt);
cnt++;
}
}
}
void dfs3(int v){
mark[v]=1;
for(int i=0;i<n;i++){
if(!mark[i] && g[i][v]){
dfs3(i);
}
}
}
vector<int> who_wins(vector<int> a,vector<int> r,vector<int> u,vector<int> v) {
vector<int> res(a.size());
n=a.size(),m=v.size();
for(int i=0;i<m;i++){
g[u[i]][v[i]]=1;
adj[u[i]].push_back(v[i]);
radj[v[i]].push_back(u[i]);
}
scc();
memset(mark,0,sizeof mark);
for(int i=0;i<n;i++){
if(!mark[i] && r[i] && szcmp[cmp[i]]>1){
dfs3(i);
}
}
for(int i=0;i<n;i++){
res[i]=mark[i];
}
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... |