Submission #480733

# Submission time Handle Problem Language Result Execution time Memory
480733 2021-10-18T01:51:18 Z socpite timeismoney (balkan11_timeismoney) C++14
60 / 100
35 ms 684 KB
#include<bits/stdc++.h>
using namespace std;

#define oo 1000000000000000
#define f first
#define s second

vector<int> up;

int Find(int x){
    if(up[x] < 0)return x;
    else{
        up[x]=Find(up[x]);
        return up[x];
    }
}

void Union(int a, int b){
    a = Find(a);
    b = Find(b);
    up[b]=a;
}

long long n, m;
vector<pair<pair<int, int>,pair<long long, long long>>> edges;
vector<pair<int, int>> ans;
long long tim = 0, money = 0, currpos, best;

int main(){
    cin >> n >> m;
    edges.resize(m);
    up.assign(n, -1);
    for(int i = 0; i < m; i++){
        cin >> edges[i].f.f >> edges[i].f.s >> edges[i].s.f >> edges[i].s.s;
    }
    for(int j = 0; j < n-1; j++){
        best = oo;
        for(int i = 0; i < m; i++){
            if(Find(edges[i].f.f) == Find(edges[i].f.s))continue;
            else{
                if(tim*edges[i].s.s + money*edges[i].s.f + edges[i].s.s*edges[i].s.f < best){
                    best = tim*edges[i].s.s + money*edges[i].s.f + edges[i].s.s*edges[i].s.f;
                    currpos = i;
                }
            }
        }
        tim += edges[currpos].s.f;
        money += edges[currpos].s.s;
        Union(edges[currpos].f.f, edges[currpos].f.s);
        ans.push_back(edges[currpos].f);
    }
    cout << tim << " " << money << endl;
    for(int i =0; i < ans.size(); i++){
        cout << ans[i].f << " " << ans[i].s << endl;
    }
}

Compilation message

timeismoney.cpp: In function 'int main()':
timeismoney.cpp:53:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     for(int i =0; i < ans.size(); i++){
      |                   ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 204 KB Output is correct
7 Correct 8 ms 304 KB Output is correct
8 Correct 35 ms 676 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Incorrect 1 ms 204 KB Output isn't correct
14 Incorrect 2 ms 204 KB Output isn't correct
15 Incorrect 1 ms 204 KB Output isn't correct
16 Incorrect 8 ms 332 KB Output isn't correct
17 Incorrect 7 ms 332 KB Output isn't correct
18 Incorrect 7 ms 304 KB Output isn't correct
19 Incorrect 34 ms 684 KB Output isn't correct
20 Incorrect 32 ms 676 KB Output isn't correct