Submission #222982

# Submission time Handle Problem Language Result Execution time Memory
222982 2020-04-14T12:44:13 Z brcode timeismoney (balkan11_timeismoney) C++14
0 / 100
18 ms 1148 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 210;
vector<pair<pair<long long,long long>,pair<long long,long long>>> edges;
long long par[MAXN];
long long sz[MAXN];
long long getpar(long long a){
    if(par[a] == a){
        return a;
    }
    return par[a] = getpar(par[a]);
}
void merge(long long a,long long b){
    a = getpar(a);
    b = getpar(b);
    if(a==b){
        return;
    }
    if(sz[a]>sz[b]){
        swap(a,b);
    }
    par[a] = b;
    sz[b]+=sz[a];
}
int main(){
    long long n,m;
    cin>>n>>m;
    long long sum1 = 0;
    long long sum2 = 0;
    for(long long i=1;i<=m;i++){
        long long x,y;
        cin>>x>>y;
        long long w1,w2;
        cin>>w1>>w2;
        edges.push_back(make_pair(make_pair(w1,w2),make_pair(x,y)));
        sum1+=w1;
        sum2+=w2;
    }
    for(long long i=0;i<=n;i++){
        par[i] = i;
        sz[i] = 1;
    }
    if(n==m-1){
        cout<<sum1*sum2<<endl;
        return 0;
    }
    sort(edges.begin(),edges.end());
    long long res = 0;
    for(auto e:edges){
        long long x = e.second.first;
        long long y = e.second.second;
        long long w = e.first.first;
        if(getpar(x)!=getpar(y)){
            merge(x,y);
            res+=w;
        }
    }
    cout<<res*res<<endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Unexpected end of file - int64 expected
2 Incorrect 5 ms 256 KB Unexpected end of file - int64 expected
3 Incorrect 5 ms 256 KB Unexpected end of file - int64 expected
4 Incorrect 5 ms 384 KB Unexpected end of file - int64 expected
5 Incorrect 5 ms 384 KB Unexpected end of file - int64 expected
6 Incorrect 5 ms 384 KB Unexpected end of file - int64 expected
7 Incorrect 7 ms 512 KB Unexpected end of file - int64 expected
8 Incorrect 18 ms 1148 KB Unexpected end of file - int64 expected
9 Incorrect 5 ms 256 KB Unexpected end of file - int64 expected
10 Incorrect 5 ms 384 KB Unexpected end of file - int64 expected
11 Incorrect 5 ms 256 KB Unexpected end of file - int64 expected
12 Incorrect 5 ms 256 KB Unexpected end of file - int64 expected
13 Incorrect 5 ms 256 KB Unexpected end of file - int64 expected
14 Incorrect 5 ms 384 KB Unexpected end of file - int64 expected
15 Incorrect 5 ms 384 KB Unexpected end of file - int64 expected
16 Incorrect 7 ms 512 KB Unexpected end of file - int64 expected
17 Incorrect 7 ms 512 KB Unexpected end of file - int64 expected
18 Incorrect 8 ms 512 KB Unexpected end of file - int64 expected
19 Incorrect 18 ms 1148 KB Unexpected end of file - int64 expected
20 Incorrect 18 ms 1148 KB Unexpected end of file - int64 expected