Submission #22447

#TimeUsernameProblemLanguageResultExecution timeMemory
22447도치피치피보족 (#40)Logistical Metropolis (KRIII5_LM)C++14
2 / 7
2000 ms36652 KiB
#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)

LM.cpp: In function 'int main()':
LM.cpp:42:29: warning: format '%d' expects argument of type 'int*', but argument 4 has type 'long long int*' [-Wformat=]
   scanf("%d%d%d", &s, &e, &v);
                             ^
LM.cpp:38:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
                       ^
LM.cpp:42:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &s, &e, &v);
                              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...