#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;
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';
}
for(int i = n-1;i> 0;i--)
{
}
//dfs();
dp[1] =0;
queue<int>q;
q.push(1);
while(!q.empty())
{
v = q.top();
q.pop();
for(auto i : g[v])
{
if(dp[u] == -1)
{
q.push(u);
dp[u] = dp[v] + 1;
}
}
}
dp2[n] =0;
//queue<int>q;
q.push(n);
while(!q.empty())
{
int v = q.front();
q.pop();
for(auto i : g[v])
{
if(dp2[u] == -1)
{
q.push(u);
dp2[u] = dp2[v] + 1;
}
}
}
int mn = 1e9+5;
int num = 0;
for(auto i : e)
{
if(dp[i.first] + dp2[i.second]+1 == mn)
{
num++;
}
else if(dp[i.first] + dp2[i.second+1 <mn)
{
int mn = dp[i.first] + dp2[i.second] +1 ;
num = 1;
}
}
cout << mn + (num > 1);
}
Compilation message
Aesthetic.cpp: In function 'int main()':
Aesthetic.cpp:36:5: error: 'v' was not declared in this scope
36 | v = q.top();
| ^
Aesthetic.cpp:36:11: error: 'class std::queue<long long int>' has no member named 'top'; did you mean 'pop'?
36 | v = q.top();
| ^~~
| pop
Aesthetic.cpp:40:13: error: 'u' was not declared in this scope
40 | if(dp[u] == -1)
| ^
Aesthetic.cpp:56:14: error: 'u' was not declared in this scope
56 | if(dp2[u] == -1)
| ^
Aesthetic.cpp:71:45: error: expected ']' before ')' token
71 | else if(dp[i.first] + dp2[i.second+1 <mn)
| ^
| ]
Aesthetic.cpp:73:12: warning: unused variable 'mn' [-Wunused-variable]
73 | int mn = dp[i.first] + dp2[i.second] +1 ;
| ^~