# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1046043 |
2024-08-06T09:23:17 Z |
becaido |
Toy Train (IOI17_train) |
C++17 |
|
5 ms |
1884 KB |
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;
#ifdef WAIMAI
#include "grader.cpp"
#else
#include "train.h"
#endif
#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif
#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second
const int SIZE = 5005;
int n, m;
int sz[SIZE];
vector<int> adj[SIZE], rev[SIZE];
bool alice[SIZE], is[SIZE], self[SIZE], dp[SIZE], vs[SIZE];
struct SCC {
int n, dfcnt = 0, sccnt = 0;
vector<int> dfn, low, scc, st, ist;
vector<vector<int>> scc_adj;
SCC() {}
SCC(int n) : n(n) {
dfn = low = scc = ist = vector<int>(n + 1, 0);
scc_adj = vector<vector<int>>(n + 1, vector<int>());
}
void tarjan(int pos) {
dfn[pos] = low[pos] = ++dfcnt;
st.emplace_back(pos);
ist[pos] = 1;
for (int np : adj[pos]) {
if (dfn[np] == 0) {
tarjan(np);
low[pos] = min(low[pos], low[np]);
} else if (ist[np] == 1) {
low[pos] = min(low[pos], dfn[np]);
}
}
if (dfn[pos] == low[pos]) {
sccnt++;
while (1) {
int x = st.back();
ist[x] = 0;
scc[x] = sccnt;
st.pop_back();
if (x == pos) {
break;
}
}
}
}
void work() {
for (int i = 1; i <= n; i++) {
if (dfn[i] == 0) {
tarjan(i);
}
}
}
void build_adj() {
for (int i = 1; i <= n; i++) {
for (int j : adj[i]) {
if (scc[i] != scc[j]) {
scc_adj[scc[i]].emplace_back(scc[j]);
}
}
}
}
vector<int> cal() {
FOR (i, 1, n) sz[scc[i]]++;
queue<int> q;
FOR (i, 1, n) if (is[i] == 0 && (sz[scc[i]] > 1 || self[i])) vs[i] = 1, q.push(i);
while (q.size()) {
int pos = q.front();
q.pop();
for (int np : rev[pos]) if (vs[np] == 0) {
vs[np] = 1;
q.push(np);
}
}
vector<int> ans;
FOR (i, 1, n) ans.pb(!vs[scc[i]]);
return ans;
}
} g;
vector<int> who_wins(vector<int> a_, vector<int> r_, vector<int> u_, vector<int> v_) {
n = a_.size();
m = u_.size();
FOR (i, 1, n) {
alice[i] = a_[i - 1];
is[i] = r_[i - 1];
adj[i].clear();
rev[i].clear();
self[i] = dp[i] = vs[i] = sz[i] = 0;
}
FOR (i, 0, m - 1) {
u_[i]++, v_[i]++;
if (u_[i] == v_[i]) self[u_[i]] = 1;
else {
if (is[u_[i]] == 0 && is[v_[i]] == 0) adj[u_[i]].pb(v_[i]);
rev[v_[i]].pb(u_[i]);
}
}
g = SCC(n);
g.work();
g.build_adj();
return g.cal();
}
/*
in1
2 4
0 1
1 0
0 0
0 1
1 0
1 1
out1
1 1
*/
Compilation message
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:111:41: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
111 | self[i] = dp[i] = vs[i] = sz[i] = 0;
| ~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1372 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
600 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1884 KB |
Output is correct |
2 |
Correct |
4 ms |
1884 KB |
Output is correct |
3 |
Correct |
5 ms |
1628 KB |
Output is correct |
4 |
Incorrect |
4 ms |
1648 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
1372 KB |
3rd lines differ - on the 691st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
1884 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1372 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |