Submission #273370

# Submission time Handle Problem Language Result Execution time Memory
273370 2020-08-19T05:04:02 Z 최은수(#5105) Mountains and Valleys (CCO20_day1problem3) C++17
0 / 25
14 ms 12672 KB
#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18;
vector<int>adj[500010];
int dep[500010];
void dfs(int x,int p)
{
    dep[x]=dep[p]+1;
    for(int&t:adj[x])
        if(t!=p)
            dfs(t,x);
    return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v,w;
        cin>>u>>v>>w;
        if(w==1)
            adj[u].eb(v),adj[v].eb(u);
    }
    dfs(1,0);
    int d1=max_element(dep+1,dep+n+1)-dep;
    dfs(d1,0);
    cout<<2*n-1-*max_element(dep+1,dep+n+1)<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12032 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12032 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 12672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12032 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12032 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12032 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12032 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12032 KB Output isn't correct
2 Halted 0 ms 0 KB -