#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
const int INF = 2147483645;
const int maxN = (int)1e5+5;
const ll LLINF = LLONG_MAX;
//const ll mod = 998244353;
const ll mod = 1000000007;
vector<int> adj[maxN];
int dist[maxN];
bool vis[maxN], bck[maxN];
void dfs(int s) {
for (auto i: adj[s]) {
if (vis[i]) continue;
vis[i] = true;
dist[i] = dist[s]+1;
dfs(i);
}
}
void solv() {
int n, m, a, b, mx=0;
cin>>n>>m;
for (int i=0;i<m;i++) {
cin>>a>>b;
bck[b] = true;
adj[a].pb(b);
}
for (int i=1;i<=n;i++) {
if (!bck[i]) {
dfs(i);
}
}
for (int i=1;i<=n;i++) {
mx = max(mx, dist[i]);
}
cout<<mx+1<<'\n';
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int t=1;
// cin>>t;
while (t--) solv();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
3672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
11096 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
3160 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
3164 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
3672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |