This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC diagnostic warning "-std=c++11"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define flush fflush(stdout)
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pii pair<int,int>
using namespace std;
const int N=1e5+5;
int T,k,sz[N],p[N];
vector<int> g[N];
void make_set(int v) {
p[v]=v; sz[v]=1;
}
int find_set(int v) {
if (p[v]==v) return v;
return p[v]=find_set(p[v]);
}
void merge(int a, int b) {
a=find_set(a); b=find_set(b);
if (a==b) return;
if (sz[a]<sz[b]) swap(a,b);
sz[a]+=sz[b]; p[b]=a;
}
void add_edges(int v) {
for (auto u:g[v]) if (p[u]>=0) merge(u,v);
}
int solve(int n, int m, vector<int> F,vector<vector<int>> S) {
for (int i=0; i<n; i++) {
p[i]=-1;
g[i].clear();
}
for (int i=1; i<n; i++) {
g[i].pb(F[i]); g[F[i]].pb(i);
}
int ans=0;
make_set(0);
for (int i=n-2; i>=0; i--) {
int x=S[0][i];
make_set(x);
add_edges(x);
if (sz[find_set(x)]==n-i) ans++;
}
return ans;
}
Compilation message (stderr)
september.cpp:1:32: warning: '-std=c++11' is not an option that controls warnings [-Wpragmas]
1 | #pragma GCC diagnostic warning "-std=c++11"
| ^~~~~~~~~~~~
# | 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... |