답안 #900572

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
900572 2024-01-08T14:45:31 Z HamzaT Cijanobakterije (COCI21_cijanobakterije) C++14
6 / 70
19 ms 16476 KB
//struct Edge {int u, v, weight;bool operator<(Edge const& other) {return weight < other.weight;}};
#include <bits/stdc++.h>
#define endl "\n"
#define ll long long
#define sp ' '
#define pb push_back
#define ar for(int i=1;i<=n;i++)
using namespace std;
ll t=1;
const ll N=3e5+100;
ll n,m,q,k;
ll a[N],b[N],c[N];
bool vis[N];
ll mx=0;
vector<int>v[N];
void dfs(ll x,ll y)
{
    vis[x]=1;mx=max(mx,y);
    for(auto i:v[x])
    {
        if(!vis[i]){dfs(i,y+1);}
    }
}
ll ans=0;
void solve()
{
    cin>>n>>m;
    while(m--)
    {
        ll x,y;cin>>x>>y;
        v[x].push_back(y);
    }
    for(int i=1;i<=n;i++)
    {
        if(!vis[i]&&v[i].size()<=1)
        {mx=0;
            dfs(i,1);
            ans+=mx;
        }
    }
    cout<<ans<<endl;return;
}
int main()
{
    //freopen("shell.in", "r", stdin);
   // freopen("shell.out", "w", stdout);
    ios::sync_with_stdio(NULL);
    cin.tie(NULL);cout.tie(NULL);
    // cin>>t;
    while(t--){solve();}
    return 0;
}
//09:00 :: 9:45
//10:30 ::
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 9048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 16476 KB Output is correct
2 Correct 3 ms 9052 KB Output is correct
3 Correct 4 ms 9308 KB Output is correct
4 Correct 6 ms 9820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Incorrect 2 ms 8796 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8792 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 9048 KB Output isn't correct
2 Halted 0 ms 0 KB -