# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1085360 | IUA_Hasin | September (APIO24_september) | C++17 | 371 ms | 39232 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "september.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
using namespace std;
using namespace __gnu_pbds;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
int solve(int N, int M, std::vector<int> F, std::vector<std::vector<int>> S) {
ll deg[N], vis[N];
for(int i=0; i<N; i++){
deg[i] = 0;
vis[i] = 0;
}
for(int i=1; i<F.size(); i++){
ll a = F[i];
deg[i]++;
deg[a]++;
}
if(M==0){
ll ans = 0;
set<ll> s;
for(int i=0; i<S.size(); i++){
for(int j=0; j<S[i].size(); j++){
ll a = S[i][j];
ll parnt = F[a];
deg[a]--;
deg[parnt]--;
//cout << deg[a] << " " << deg[parnt] << endl;
auto it = s.find(parnt);
if(deg[a]!=0){
s.insert(a);
}
if(it!=s.end()){
if(deg[parnt]==0){
s.erase(it);
}
}
if(s.size()==0){
ans++;
}
for(auto u : s){
cout << u << " ";
}
//cout << i << " " << 59;
cout<<endl;
}
}
return ans;
} else {
set<ll> world;
set<ll> s[M];
set<ll> check;
ll ans = 0;
for(int i=0; i<S[0].size(); i++){
for(int j=0; j<M; j++){
ll a = S[j][i];
ll parnt = F[a];
world.insert(a);
s[j].insert(a);
if(vis[a]==0){
deg[a]--;
deg[parnt]--;
auto it = check.find(parnt);
if(deg[a]!=0){
check.insert(a);
}
if(it!=check.end()){
if(deg[parnt]==0){
check.erase(it);
}
}
vis[a] = 1;
}
// for(auto u : check){
// cout << u << " ";
// }
// cout<<endl;
}
ll status = 1;
ll siz = world.size();
for(int j=0; j<M; j++){
ll a = s[j].size();
if(a!=siz){
status = -1;
break;
}
}
if(status==1 && check.size()==0){
ans++;
}
// cout<<endl;
// for(auto u : check){
// cout << u << " ";
// }
// cout<<endl;
}
return ans;
}
}
Compilation message (stderr)
# | 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... |
# | 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... |