#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
int n,m,T,d[500005];
vector<ii> g[500005];
priority_queue<ii> Q;
void ReadInt(int &number)
{
number=0;
int c=getchar();
while(c<'0'||c>'9')
c=getchar();
for (;('0'<=c&&c<='9');c=getchar())
number=number*10+c-48;
}
int main()
{
ios_base::sync_with_stdio(false);
//freopen("TEST.INP","r",stdin);
ReadInt(n);
ReadInt(m);
ReadInt(T);
int u,v,w;
while(m--)
{
ReadInt(u);
ReadInt(v);
ReadInt(w);
g[u].push_back(ii(v,w));
g[v].push_back(ii(u,w));
}
d[1]=1e9;
Q.push(ii(1e9,1));
while(Q.size()>0)
{
int u=Q.top().second;
int val=Q.top().first;
Q.pop();
if(d[u]==val)
for(int i=0; i<g[u].size(); i++)
{
int v=g[u][i].first;
int w=g[u][i].second;
if(d[v]<min(d[u],w))
{
d[v]=min(d[u],w);
Q.push(ii(d[v],v));
}
}
}
while(T--)
{
ReadInt(u);
printf("%d\n",d[u]);
}
}
Compilation message
sightseeing.cpp: In function 'int main()':
sightseeing.cpp:46:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<g[u].size(); i++)
~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
12152 KB |
Output is correct |
2 |
Correct |
13 ms |
12256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
12304 KB |
Output is correct |
2 |
Correct |
17 ms |
12304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
14324 KB |
Output is correct |
2 |
Correct |
45 ms |
14324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3131 ms |
106220 KB |
Output is correct |
2 |
Execution timed out |
3541 ms |
153268 KB |
Time limit exceeded |