#include "train.h"
#include "bits/stdc++.h"
using namespace std;
#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
void dfs(int c, vb& vis, vvi& adj) {
assert(!vis[c]);
vis[c] = true;
for(int i : adj[c]) if(!vis[i]) {
dfs(i, vis, adj);
}
}
const int MN = 5010;
int dfn[MN], mi[MN], gi[MN], gsiz[MN];
vector<int> stk;
vvi gp;
bool vis[MN];
int cdfn;
void tarjan(int c, vvi& adj) {
assert(!vis[c]);
vis[c] = true;
dfn[c] = mi[c] = cdfn++;
stk.push_back(c);
for(int i : adj[c]) {
if(!vis[i]) {
tarjan(i, adj);
mi[c] = min(mi[c], mi[i]);
} else {
mi[c] = min(mi[c], dfn[i]);
}
}
if(dfn[c] == mi[c]) {
int cur;
gp.push_back({});
do{
cur = stk.back();
gi[cur] = gp.size() - 1;
++gsiz[(int) gp.size() - 1];
stk.pop_back();
gp.back().push_back(cur);
} while(cur != c);
}
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
int n = a.size(), m=u.size();
vvi adj(n);
vvi rAdj(n);
vb toSelf(n);
forR(i, m) {
adj[u[i]].push_back(v[i]);
rAdj[v[i]].push_back(u[i]);
if(u[i] == v[i]) toSelf[u[i]] = true;
}
cdfn = 1;
forR(i, n) {
if(!vis[i]) {
tarjan(i, adj);
}
}
vb vis(n, false);
forR(i, n) {
if(r[i] && !vis[i] && (gsiz[gi[i]] > 1 || toSelf[i])) {
dfs(i, vis, rAdj);
}
}
vector<int> ret(n);
forR(i, n) ret[i] = vis[i] ? 1 : 0;
return ret;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
2140 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2040 KB |
Output is correct |
2 |
Correct |
3 ms |
1884 KB |
Output is correct |
3 |
Correct |
4 ms |
1628 KB |
Output is correct |
4 |
Correct |
4 ms |
1884 KB |
Output is correct |
5 |
Incorrect |
4 ms |
1628 KB |
3rd lines differ - on the 11th token, expected: '0', found: '1' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
1624 KB |
3rd lines differ - on the 696th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
1628 KB |
3rd lines differ - on the 2nd token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
2140 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |