# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
47740 | Just_Solve_The_Problem | Bitaro’s Party (JOI18_bitaro) | C++11 | 14 ms | 10780 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 <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define ll long long
#define pii pair < int, int >
#define fr first
#define sc second
#define mk make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define ok puts("ok");
#define whatis(x) cerr << #x << " = " << x << endl;
#define pause system("pause");
#define random (rand() ^ (rand() << 15))
const int N = (int)1e5 + 7;
const int inf = (int)1e9 + 7;
int n, m, q;
vector < int > gr[N];
vector < int > revgr[N];
int used[N], h[N];
vector < int > order;
void dfs1(int v) {
used[v] = 1;
for (int to : gr[v]) {
if (!used[to])
dfs1(to);
}
order.pb(v);
}
void dfs(int v) {
for (int to : gr[v]) {
dfs(to);
h[v] = max(h[to] + 1, h[v]);
}
}
main() {
scanf("%d %d %d", &n, &m, &q);
if (q != 1) return 0;
for (int i = 1; i <= m; i++) {
int u, v;
scanf("%d %d", &u, &v);
gr[u].pb(v);
revgr[v].pb(u);
}
int t, y;
while (q--) {
scanf("%d %d", &t, &y);
for (int i = 1; i <= y; i++) {
int x;
scanf("%d", &x);
used[x] = 1;
}
}
for (int i = 1; i <= n; i++) {
if (!used[i]) {
dfs1(i);
}
}
memset(used, 0, sizeof used);
for (int i = 1; i <= n; i++) {
if (!used[order[i - 1]]) {
dfs(order[i - 1]);
}
}
memset(used, 0, sizeof used);
for (int i = 1; i <= n; i++) {
if (!used[order[i - 1]]) {
dfs(order[i - 1]);
}
}
int mx = 0;
for (int i = 1; i <= n; i++) {
if (!used[i]) {
mx = max(mx, h[i]);
}
}
cout << mx;
}
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... |