Submission #273407

# Submission time Handle Problem Language Result Execution time Memory
273407 2020-08-19T05:11:38 Z 최은수(#5105) Mountains and Valleys (CCO20_day1problem3) C++17
0 / 25
12 ms 12544 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);
        else if(w<(n+1)/2||w>n)
            return 1/0;
    }
    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;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:38:21: warning: division by zero [-Wdiv-by-zero]
   38 |             return 1/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 12 ms 12544 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 -