#include <bits/stdc++.h>
#define f first
#define s second
#define N 500010
using namespace std;
typedef pair<int, int> pii;
int n, m, q, pai[N], peso[N], ans[N];
vector<pii> grafo[N];
vector< pair<int, pii> > A;
int Find(int x)
{
if(x == pai[x]) return x;
return pai[x] = Find(pai[x]);
}
void join(int a, int b)
{
if(peso[a] >= peso[b]) swap(a, b);
pai[a] = b;
if(peso[a] == peso[b]) peso[b] ++;
}
void getans()
{
memset(ans, 0x3f3f3f3f, sizeof ans);
queue<pii> fila;
fila.push(pii(1, 1));
while(!fila.empty())
{
int x = fila.front().f, p = fila.front().s;
fila.pop();
for(auto v: grafo[x])
{
if(v.f == p) continue;
ans[v.f] = min(ans[x], v.s);
fila.push(pii(v.f, x));
}
}
}
int main()
{
//ios::sync_with_stdio(false); cin.tie(0);
scanf("%d %d %d", &n, &m, &q);
for(int i = 1, a, b, c; i <= m; i++)
{
scanf("%d %d %d", &a, &b, &c);
A.push_back(make_pair(c, pii(a, b)));
}
sort(A.rbegin(), A.rend());
for(int i = 1; i <= n; i++) pai[i] = i;
for(auto p: A)
{
int a = Find(p.s.f), b = Find(p.s.s);
if(a == b) continue;
join(a, b);
grafo[a].push_back(pii(b, p.f));
grafo[b].push_back(pii(a, p.f));
}
memset(ans, 0x3f3f3f3f, sizeof ans);
queue<pii> fila;
fila.push(pii(1, 1));
while(!fila.empty())
{
int x = fila.front().f, p = fila.front().s;
fila.pop();
for(auto v: grafo[x])
{
if(v.f == p) continue;
ans[v.f] = min(ans[x], v.s);
fila.push(pii(v.f, x));
}
}
while(q--)
{
int x;
scanf("%d", &x);;
printf("%d\n", ans[x]);
}
}
Compilation message
sightseeing.cpp: In function 'int main()':
sightseeing.cpp:59:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &n, &m, &q);
^
sightseeing.cpp:63:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &a, &b, &c);
^
sightseeing.cpp:110:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &x);;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
19600 KB |
Output is correct |
2 |
Correct |
3 ms |
19600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
19772 KB |
Output is correct |
2 |
Correct |
3 ms |
19600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
21952 KB |
Output is correct |
2 |
Correct |
26 ms |
21796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2309 ms |
93412 KB |
Output is correct |
2 |
Runtime error |
0 ms |
0 KB |
-1: Interrupted system call
|