#include <bits/stdc++.h>
#define ll long long
#define int ll
using namespace std;
ifstream f ("test.in");
ofstream g ("test.out");
int teste=1;
int n,m,q;
int dp[500005];
vector < array < int ,2 > > G[500005];
set < array < int ,2 > > s;
void calc()
{
s.insert({-(100000000),1});
while(s.size())
{
auto marcel = *(s.begin());
int mnDrum= -marcel[0];
int nod = marcel[1];
s.erase(s.begin());
for(auto x:G[nod])
{
int vecin = x[1];
int costDrum = -x[0];
if(min(costDrum,mnDrum) > dp[vecin])
{
s.erase({-dp[vecin],vecin});
dp[vecin] = min(costDrum,mnDrum);
s.insert({-dp[vecin],vecin});
}
}
}
}
void solve()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>q;
for(int i=1;i<=m;++i)
{
int a,b,c;
cin>>a>>b>>c;
G[a].push_back({-c,b});
G[b].push_back({-c,a});
}
for(int i=1;i<=n;++i)
{ dp[i] = 0;
sort(G[i].begin() , G[i].end());
}
calc();
for(;q--;)
{
int x;
cin>>x;
cout<<dp[x]<< '\n';
}
}
main()
{
while(teste--)
{
solve();
}
return 0;
}
Compilation message
sightseeing.cpp:77:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
77 | main()
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11980 KB |
Output is correct |
2 |
Correct |
6 ms |
12072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12236 KB |
Output is correct |
2 |
Correct |
7 ms |
12080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
15552 KB |
Output is correct |
2 |
Correct |
35 ms |
14860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3549 ms |
177624 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |