제출 #1286730

#제출 시각아이디문제언어결과실행 시간메모리
1286730LIA시간이 돈 (balkan11_timeismoney)C++17
0 / 100
183 ms131072 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
struct Dsu {
  vll p, sz;

  Dsu(ll n) : p(n), sz(n, 1) {
    iota(p.begin(), p.end(), 0);
  }

  ll find(ll v) {
    if (p[v] == v)
      return v;
    return p[v] = find(p[v]);
  }

  bool uni(ll a, ll b) {
    ll x = find(a), y = find(b);
    if (x == y)
      return 0;
    if (sz[x] < sz[y])
      swap(x, y);
    sz[x] += sz[y];
    p[y] = x;
    return 1;
  }
};

int main() {
  freopen("timeismoney.in", "r", stdin);
  freopen("timeismoney.out", "w", stdout);
  ll n, m;
  cin >> n >> m;
  vector<tuple<ll, ll, ll>> vec;

  for (ll i = 0; i < m; ++i) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    vec.push_back({c, a, b});
  }

  sort(vec.begin(), vec.end());
  Dsu dsu(n + 1);
  ll sum = 0;
  vector<pair<ll, ll>> pairs;
  for (auto [c, a, b] : vec) {
    if (dsu.uni(a, b)) {
      sum += c;
      pairs.push_back({a, b});
    }
  }
  cout << sum << " " << sum << "\n";
  for (auto [a, b] : pairs)
    cout << a << " " << b << "\n";
}

컴파일 시 표준 에러 (stderr) 메시지

timeismoney.cpp: In function 'int main()':
timeismoney.cpp:31:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |   freopen("timeismoney.in", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
timeismoney.cpp:32:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |   freopen("timeismoney.out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...