#include "train.h"
#include <bits/stdc++.h>
//#define int long long
#define pb push_back
using namespace std;
const int N=5005;
int n,vis[N];
bool a[N],c[N],cyc[N],h,self[N],par[N],sz[N];
vector<int> adj[2][N],t;
void dfs0(int x){
vis[x]=1;
for (auto u:adj[0][x]){
if (vis[u]) continue;
dfs0(u);
}t.pb(x);
return;
}
int getpar(int x){
if (par[x]==x) return x;
return par[x]=getpar(par[x]);
}
void link(int x,int y){
x=getpar(x);
y=getpar(y);
if (x==y) return;
if (sz[x]>sz[y]) swap(x,y);
sz[y]+=sz[x];
par[x]=y;
return;
}
void dfs1(int x,int p){
vis[x]=1;
link(x,p);
for (auto u:adj[1][x]) if (!vis[u]) dfs1(u,p);
return;
}
bool getans(int s){
queue<int> q;
q.push(s);
vis[s]=1;
bool ok=0;
while (!q.empty()){
int x=q.front();
//cout<<x<<' ';
q.pop();
if (c[x]){
if (sz[getpar(x)]>1) ok=1;
if (self[x]==1) ok=1;
}
for (auto u:adj[0][x]){
if (vis[u]) continue;
else{
vis[u]=1;
q.push(u);
}
}
}//cout<<endl;
return ok;
}
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) {
n=A.size();
for (int i=1;i<=n;i++) a[i]=A[i-1],c[i]=r[i-1],par[i]=i,sz[i]=1;
for (int i=0;i<u.size();i++){
adj[0][u[i]+1].pb(v[i]+1);
adj[1][v[i]+1].pb(u[i]+1);
if (u[i]==v[i]) self[u[i]+1]=1;
}
vector<int> ans(n);
for (int i=1;i<=n;i++){
if (vis[i]) continue;
dfs0(i);
}
memset(vis,0,sizeof(vis));
reverse(t.begin(),t.end());
for (auto u:t) if (!vis[u]) dfs1(u,u);
memset(vis,0,sizeof(vis));
for (int i=1;i<=n;i++){
ans[i-1]=getans(i);
memset(vis,0,sizeof(vis));
}
return ans;
}
Compilation message
train.cpp: In function 'bool getans(int)':
train.cpp:47:21: warning: comparison of constant '1' with boolean expression is always false [-Wbool-compare]
47 | if (sz[getpar(x)]>1) ok=1;
| ~~~~~~~~~~~~~^~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:63:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for (int i=0;i<u.size();i++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
149 ms |
1368 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
600 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
106 ms |
1760 KB |
Output is correct |
2 |
Correct |
106 ms |
1728 KB |
Output is correct |
3 |
Correct |
98 ms |
1624 KB |
Output is correct |
4 |
Incorrect |
706 ms |
1712 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
521 ms |
1524 KB |
3rd lines differ - on the 696th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
635 ms |
1628 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
149 ms |
1368 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |