답안 #1088366

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1088366 2024-09-14T10:02:37 Z Rolo678 Aesthetic (NOI20_aesthetic) C++14
0 / 100
306 ms 38992 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<vector<pair<int,int>>>g(3e5+5);
vector<long long>dp2(3e5+5,-1);
 vector<long long>dp(3e5+5,-1);
 
signed main()
{
  int n,m;
  cin >> n>>m;
 // cin >> n >> m;
  vector<pair<int,int>>e(m);
  for(int i = 1;i<=m;i++)
  {
    int a,b,w;
    cin >> a >> b >> w;
    //cout << 'o';
    g[a].push_back({b,i});
    g[b].push_back({a,i});
    e[i] = {a,b};
//cout << 'o';
  }
 
  //dfs();
  dp[1] =0;
  queue<int>q;
  q.push(1);
  while(!q.empty())
  {
   int v = q.front();
    q.pop();
    for(auto u : g[v])
    {
      if(dp[u.first] == -1)
      {
        q.push(u.first);
        dp[u.first] = dp[v] + 1;
      }
    }
  }
    dp2[n] =0;
  //queue<int>q;
  q.push(n);
  while(!q.empty())
  {
    int v = q.front();
    q.pop();
    for(auto u : g[v])
    {
      if(dp2[u.first] == -1)
      {
        q.push(u.first);
        dp2[u.first] = dp2[v] + 1;
      }
    }
  }
  int mn = 1e9+5;
  int num = 0;
  int mn2 = 1e9+5;
  int s =0;
  for(int i = 1;i<=m;i++)
  {
    int v = e[i].first;
    int u = e[i].second;
    if(dp[u] == mn && dp2[v]== mn2)
    {
      num++;
    }
    else if(dp[u] + dp2[v]+1 <mn+mn2+1)
    {
       mn = dp[u];
       mn2 =  dp2[v];
     num = 1;
    }
     if(i==m && dp[u] + dp2[v]+1 <=mn+mn2+1)
    {
      num++;
       s= 1;
    }
   // cout <<  dp[i.first] + dp2[i.second]+1 << '\n';
  }
   cout << mn+mn2+1 + (num == 1&& !s);
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 21 ms 24156 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 21 ms 24156 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 301 ms 38328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 306 ms 38992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 223 ms 36772 KB Output is correct
2 Incorrect 179 ms 34644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 223 ms 36772 KB Output is correct
2 Incorrect 179 ms 34644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 21 ms 24156 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -