Submission #6618

# Submission time Handle Problem Language Result Execution time Memory
6618 2014-07-02T15:32:47 Z mrcamel 비용 (KOI11_cost) C++
0 / 24
0 ms 4404 KB
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;

ifstream fin("in.txt");

#define in fin
#define out cout
#define DIV 1000000000
#define int64 long long int

struct LL
{
    int s, e, w;
}L[100001];

struct VV
{
    int subN;
    int parent;
}Vtx[100001];

int cmp(const LL &a, const LL &b)
{
    return a.w > b.w;
}

int find(int idx)
{
	if(idx != Vtx[idx].parent) Vtx[idx].parent = find(Vtx[idx].parent);
	return Vtx[idx].parent;
}

int64 sum[100001]; //합

int main()
{
    int n, k;
    in >> n >> k; //정점, 간선

    for(int i=0; i<k; i++)
        in >> L[i].s >> L[i].e >> L[i].w;

    sort(L, L+k, cmp);

    for(int i=1; i<=n; i++)
    {
        Vtx[i].parent = i;
        Vtx[i].subN = 1;
    }

    for(int i=0; i<k; i++) {
        if(i != 0) sum[i] = sum[i-1] + L[k-i-1].w;
        else sum[i] = L[k-1].w;

        sum[i] %= DIV;
    } reverse(sum, sum+k);

    int64 res = 0;
    for(int i=0; i<k; i++)
    {
        int v1 = L[i].s;
        int v2 = L[i].e;

        int p1 = find(v1);
        int p2 = find(v2);

        if(p1 != p2)
        {
            res += (Vtx[p1].subN * Vtx[p2].subN * sum[i]);
            res %= DIV;

            Vtx[p1].subN += Vtx[p2].subN;
            Vtx[p2].parent = p1;
        }
    }

    out << res << endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 4404 KB open (syscall #2) was called by the program (disallowed syscall)
2 Runtime error 0 ms 4404 KB open (syscall #2) was called by the program (disallowed syscall)
3 Runtime error 0 ms 4404 KB open (syscall #2) was called by the program (disallowed syscall)
4 Runtime error 0 ms 4404 KB open (syscall #2) was called by the program (disallowed syscall)
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 4404 KB open (syscall #2) was called by the program (disallowed syscall)
2 Runtime error 0 ms 4404 KB open (syscall #2) was called by the program (disallowed syscall)
3 Runtime error 0 ms 4404 KB open (syscall #2) was called by the program (disallowed syscall)
4 Runtime error 0 ms 4404 KB open (syscall #2) was called by the program (disallowed syscall)
5 Runtime error 0 ms 4404 KB open (syscall #2) was called by the program (disallowed syscall)
6 Runtime error 0 ms 4404 KB open (syscall #2) was called by the program (disallowed syscall)
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 4404 KB open (syscall #2) was called by the program (disallowed syscall)
2 Runtime error 0 ms 4404 KB open (syscall #2) was called by the program (disallowed syscall)
3 Runtime error 0 ms 4404 KB open (syscall #2) was called by the program (disallowed syscall)
4 Runtime error 0 ms 4404 KB open (syscall #2) was called by the program (disallowed syscall)
5 Runtime error 0 ms 4404 KB open (syscall #2) was called by the program (disallowed syscall)
6 Runtime error 0 ms 4404 KB open (syscall #2) was called by the program (disallowed syscall)
7 Runtime error 0 ms 4404 KB open (syscall #2) was called by the program (disallowed syscall)
8 Runtime error 0 ms 4404 KB open (syscall #2) was called by the program (disallowed syscall)
9 Runtime error 0 ms 4404 KB open (syscall #2) was called by the program (disallowed syscall)
10 Runtime error 0 ms 4404 KB open (syscall #2) was called by the program (disallowed syscall)