# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1076896 |
2024-08-26T18:16:34 Z |
Gray |
Toy Train (IOI17_train) |
C++17 |
|
8 ms |
2652 KB |
#include "train.h"
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define ff first
#define ss second
#define ln "\n"
#define ld long double
vector<ll> are;
vector<ll> isc;
vector<pair<ll, ll>> edge;
vector<vector<ll>> A;
vector<vector<ll>> rA;
vector<vector<ll>> cA;
vector<ll> spec;
vector<ll> rspec;
ll n, m;
void dfs1(ll u, vector<bool> &vis, vector<ll> &ord){
vis[u]=1;
for (auto i:A[u]){
ll v = edge[i].ff^edge[i].ss^u;
if (!vis[v]) dfs1(v, vis, ord);
}
ord.push_back(u);
}
void dfs2(ll u, vector<ll> &comp, ll cc, ll &sz){
comp[u]=cc;
sz++;
if (isc[u]) spec[cc]=1;
for (auto i:rA[u]){
ll v = edge[i].ff^edge[i].ss^u;
if (comp[v]==-1) dfs2(v, comp, cc, sz);
}
}
void dfs(ll u, vector<ll> &dp){
dp[u]=0;
for (auto v:cA[u]){
if (dp[v]==-1) dfs(v, dp);
dp[u]|=dp[v];
}
if (spec[u]) dp[u]=1;
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
n=a.size(); m=v.size();
isc=r; are=a;
cA.clear(); spec.clear();
rA.clear(); rA.resize(n);
A.clear(); A.resize(n);
edge.clear(); edge.resize(m);
rspec.clear(); rspec.resize(n);
for (ll i=0; i<m; i++){
edge[i] = {u[i], v[i]};
if (u[i]==v[i]) rspec[u[i]]=1;
A[u[i]].push_back(i);
rA[v[i]].push_back(i);
}
vector<bool> vis(n);
vector<ll> ord;
for (ll i=0; i<n; i++){
if (!vis[i]){
dfs1(i, vis, ord);
}
}
reverse(ord.begin(), ord.end());
vector<ll> comp(n, -1);
ll cc=0;
for (auto i:ord){
if (comp[i]==-1){
ll sz=0;
spec.push_back(0);
dfs2(i, comp, cc++, sz);
if (sz==1 and !rspec[i]) spec[comp[i]]=0;
}
}
cA.resize(cc);
for (ll i=0; i<m; i++){
if (comp[edge[i].ff]!=comp[edge[i].ss]) cA[comp[edge[i].ff]].push_back(comp[edge[i].ss]);
}
vector<ll> dp(cc, -1);
for (ll i=0; i<cc; i++){
if (dp[i]==-1) dfs(i, dp);
}
vector<ll> ans(n);
for (ll i=0; i<n; i++){
ans[i]=dp[comp[i]];
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
2140 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 8th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2652 KB |
Output is correct |
2 |
Correct |
5 ms |
2372 KB |
Output is correct |
3 |
Correct |
5 ms |
2508 KB |
Output is correct |
4 |
Correct |
7 ms |
2140 KB |
Output is correct |
5 |
Correct |
7 ms |
2112 KB |
Output is correct |
6 |
Correct |
6 ms |
1880 KB |
Output is correct |
7 |
Correct |
6 ms |
1988 KB |
Output is correct |
8 |
Correct |
6 ms |
1956 KB |
Output is correct |
9 |
Correct |
7 ms |
1988 KB |
Output is correct |
10 |
Correct |
6 ms |
2136 KB |
Output is correct |
11 |
Correct |
6 ms |
1884 KB |
Output is correct |
12 |
Correct |
7 ms |
2160 KB |
Output is correct |
13 |
Correct |
7 ms |
2136 KB |
Output is correct |
14 |
Correct |
8 ms |
2136 KB |
Output is correct |
15 |
Correct |
7 ms |
2136 KB |
Output is correct |
16 |
Correct |
7 ms |
2140 KB |
Output is correct |
17 |
Correct |
6 ms |
2140 KB |
Output is correct |
18 |
Correct |
4 ms |
1884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
1884 KB |
3rd lines differ - on the 696th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
2140 KB |
3rd lines differ - on the 2nd token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
2140 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |