Submission #1045381

#TimeUsernameProblemLanguageResultExecution timeMemory
1045381TobSeptember (APIO24_september)C++17
100 / 100
94 ms15784 KiB
#include <bits/stdc++.h> #include "september.h" #define F first #define S second #define all(x) x.begin(), x.end() #define pb push_back #define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) using namespace std; typedef long long ll; typedef pair <ll, ll> pii; const int N = 1e5 + 7; int bio[N]; vector <int> adj[N]; int dfs(int x) { bio[x] = 1; int cnt = 1; for (int y : adj[x]) if (!bio[y]) cnt += dfs(y); return cnt; } int solve(int n, int m, vector <int> p, vector <vector <int> > a) { for (int i = 0; i < n; i++) { bio[i] = 0; adj[i].clear(); } for (int i = 1; i < n; i++) adj[p[i]].pb(i); int cnt = 0, x = 0, rem = 0; while (x < n-1) { cnt++; do { for (int i = 0; i < m; i++) { if (bio[a[i][x]]) rem--; else rem += m*dfs(a[i][x])-1; } x++; } while (rem); } return cnt; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...