# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22447 | 도치피치피보족 (#40) | Logistical Metropolis (KRIII5_LM) | C++14 | 2000 ms | 36652 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <vector>
#include <queue>
#include <functional>
using namespace std;
typedef pair<int, long long> P;
vector<P> vec[100001];
int visit[100001] = { 0 };
long long solve(int index){
long long ans = 0;
queue<P> q;
priority_queue<P, vector<P>, greater<P> > pq;
visit[index] = 1;
for (auto i : vec[index]){
q.push(i);
visit[i.second] = 1;
ans += i.first;
}
while (!q.empty()){
for (auto next : vec[q.front().second])
pq.push(next);
q.pop();
}
while (!pq.empty()){
long long cost = pq.top().first;
int curr = pq.top().second;
pq.pop();
if (visit[curr]) continue;
visit[curr] = 1;
ans += cost;
for (auto next : vec[curr]) pq.push(next);
}
return ans;
}
int main(){
int N, M;
scanf("%d%d", &N, &M);
for (int m = 0; m < M; m++){
int s, e;
long long v;
scanf("%d%d%d", &s, &e, &v);
vec[s].push_back({ v, e });
vec[e].push_back({ v, s });
}
for (int n = 1; n <= N; n++){
for (int v = 1; v <= N; v++) visit[v] = 0;
printf("%lld\n",solve(n));
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |