Submission #6606

#TimeUsernameProblemLanguageResultExecution timeMemory
6606mrcamel비용 (KOI11_cost)C++98
Compilation error
0 ms0 KiB
#include <iostream> #include <algorithm> using namespace std; #define in cin #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; } int64 sum[100001]; //합 int main() { int n, k; in >> n >> k; //정점, 간선 //scanf("%d %d", &n, &k); for(int i=0; i<k; i++) //scanf("%d %d %d", &L[i].s, &L[i].e, &L[i].w); 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; } 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 = v1, p2 = v2; while( p1 != Vtx[p1].parent ) p1 = Vtx[p1].parent; while( p2 != Vtx[p2].parent ) p2 = Vtx[p2].parent; if(p1 != p2) { res += (Vtx[p1].subN * Vtx[p2].subN * sum[i]); res %= DIV; Vtx[p1].subN += Vtx[p2].subN; Vtx[p2].parent = p1; } } printf("%d", res); return 0; }

Compilation message (stderr)

cost.cpp: In function 'int main()':
cost.cpp:71:21: error: 'printf' was not declared in this scope