Unfortunately we were unable to fully decode your file, as it is not encoded in UTF-8.
You can try to decode it yourself by downloading it here.
//test sprawdzaj�cy szybko�� find-union z biblioteczki earla //Krzysztof Kleiner #include<cstdio> #include<algorithm> #define FOR(i, b, n) for ( int (i) = b; (i) < (n); (i)++) #define FORR(i, b, n) for ( (i) = b; (i) < (n); (i)++) #define REP(i, n) for ( int (i) = 0; (i) < (n); (i)++) #define SC(n) scanf("%d", &(n)) #define SC2(n, m) scanf("%d%d", &(n), &(m)) #define SCLL(n) scanf("%lld", &(n)) #define PRT(n) printf("%d ", (n)) #define PRTLL(n) printf("%lld ", (n)) #define NXL printf("\n") typedef long long LL; typedef unsigned long long ULL; using namespace std; const int MAXM = 4100001, MAXN=2020; struct edge { short a, b; int w; }; edge e[MAXM]; short parent[MAXN]; int size[MAXN]; inline bool operator < (edge x, edge y) { return x.w < y.w; } short Find(short u) { if(parent[u] == u) return u; return parent[u] = Find(parent[u]); } inline void Union(short u, short v) { if(size[v] < size[u]) swap(u, v); parent[u] = v; size[v] += size[u]; } int main() { int n; long long cost = 0; SC(n); FOR(i, 1, n+1) { parent[i] = i; size[i] = 1; } int i = 0; for(short j=0; j<n; j++) { for (short k=j+1; k<=n; k++, i++) { e[i].a = j; e[i].b = k; scanf("%d", &e[i].w); } } int m = i; sort(e, e+m); REP(i, m) { short u = Find(e[i].a), v = Find(e[i].b); if(u!=v) { cost += e[i].w; Union(u, v); } } PRTLL(cost); NXL; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | //test sprawdzaj�cy szybko�� find-union z biblioteczki earla //Krzysztof Kleiner #include<cstdio> #include<algorithm> #define FOR(i, b, n) for ( int (i) = b; (i) < (n); (i)++) #define FORR(i, b, n) for ( (i) = b; (i) < (n); (i)++) #define REP(i, n) for ( int (i) = 0; (i) < (n); (i)++) #define SC(n) scanf("%d", &(n)) #define SC2(n, m) scanf("%d%d", &(n), &(m)) #define SCLL(n) scanf("%lld", &(n)) #define PRT(n) printf("%d ", (n)) #define PRTLL(n) printf("%lld ", (n)) #define NXL printf("\n") typedef long long LL; typedef unsigned long long ULL; using namespace std; const int MAXM = 4100001, MAXN=2020; struct edge { short a, b; int w; }; edge e[MAXM]; short parent[MAXN]; int size[MAXN]; inline bool operator < (edge x, edge y) { return x.w < y.w; } short Find(short u) { if(parent[u] == u) return u; return parent[u] = Find(parent[u]); } inline void Union(short u, short v) { if(size[v] < size[u]) swap(u, v); parent[u] = v; size[v] += size[u]; } int main() { int n; long long cost = 0; SC(n); FOR(i, 1, n+1) { parent[i] = i; size[i] = 1; } int i = 0; for(short j=0; j<n; j++) { for (short k=j+1; k<=n; k++, i++) { e[i].a = j; e[i].b = k; scanf("%d", &e[i].w); } } int m = i; sort(e, e+m); REP(i, m) { short u = Find(e[i].a), v = Find(e[i].b); if(u!=v) { cost += e[i].w; Union(u, v); } } PRTLL(cost); NXL; return 0; } |