Submission #996871


Source Code Expand

    #include <string>
    #include <vector>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>
    #include <queue>
    #include <map>
    #include <set>
    #include <iostream>
    #include <sstream>
    #include <cstring>
    #include <numeric>
    using namespace std;
    typedef long long ll;
    typedef pair<int,int> pii;
    #define F0(i,n) for (int i = 0; i < n; i++)
    #define F1(i,n) for (int i = 1; i <= n; i++)
    #define CL(a,x) memset(x, a, sizeof(x));
    #define SZ(x) ((int)x.size())
    const double eps = 1e-10;
    const int inf = 1000000009;
    int i, j, k, m, n, l;
    int ans;
    string s;
    const int N = 500000;
    int a[N], b[N], c[N], id[N], p[N];
     
    int cc(int x, int y) {
    	return c[x] < c[y];
    }
     
    int main() {
    	//freopen("x.in", "r", stdin);
     
    	cin >> n >> m;
    	F0(i, m) cin >> a[i] >> b[i] >> c[i];
    	F0(i, m) id[i] = i;
    	sort(id, id + m, cc);
     
    	int Q, S, T;
    	cin >> Q;
    	while (Q--) {
    		cin >> S >> T;
    		F1(i, n) p[i] = i;
    		p[T] = S;
    		int disc = n - 2;
    		ll ans = 0;
    		F0(uu, m) {
   int i = id[uu];
    			if (!disc) break;
    			int x = a[i];
    			int y = b[i];
    			while (x != p[x]) x = p[x];
    			while (y != p[y]) y = p[y];
    			if (x == y) continue;
    			ans += c[i];
    			if (rand() & 1) p[x] = y; else p[y] = x;
    		}
    		cout << ans << endl;
    	}
    	
    	return 0;
    }

Submission Info

Submission Time
Task A - Graph
User USA
Language C++14 (GCC 5.4.1)
Score 200
Code Size 1533 Byte
Status TLE
Exec Time 3154 ms
Memory 6528 KB

Judge Result

Set Name Sample subtask1 subtask2 All
Score / Max Score 0 / 0 200 / 200 0 / 300 0 / 200
Status
AC × 2
AC × 12
AC × 14
TLE × 7
AC × 14
TLE × 15
Set Name Test Cases
Sample sample_1.txt, sample_2.txt
subtask1 sample_2.txt, subtask_1_1.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_2.txt, subtask_1_3.txt, subtask_1_4.txt, subtask_1_5.txt, subtask_1_6.txt, subtask_1_7.txt, subtask_1_8.txt, subtask_1_9.txt
subtask2 sample_1.txt, sample_2.txt, subtask_1_1.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_2.txt, subtask_1_3.txt, subtask_1_4.txt, subtask_1_5.txt, subtask_1_6.txt, subtask_1_7.txt, subtask_1_8.txt, subtask_1_9.txt, subtask_2_1.txt, subtask_2_2.txt, subtask_2_3.txt, subtask_2_4.txt, subtask_2_5.txt, subtask_2_6.txt, subtask_2_7.txt, subtask_2_8.txt
All sample_1.txt, sample_2.txt, subtask_1_1.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_2.txt, subtask_1_3.txt, subtask_1_4.txt, subtask_1_5.txt, subtask_1_6.txt, subtask_1_7.txt, subtask_1_8.txt, subtask_1_9.txt, subtask_2_1.txt, subtask_2_2.txt, subtask_2_3.txt, subtask_2_4.txt, subtask_2_5.txt, subtask_2_6.txt, subtask_2_7.txt, subtask_2_8.txt, subtask_3_1.txt, subtask_3_2.txt, subtask_3_3.txt, subtask_3_4.txt, subtask_3_5.txt, subtask_3_6.txt, subtask_3_7.txt, subtask_3_8.txt
Case Name Status Exec Time Memory
sample_1.txt AC 3 ms 256 KB
sample_2.txt AC 2 ms 256 KB
subtask_1_1.txt AC 3 ms 256 KB
subtask_1_10.txt AC 627 ms 3456 KB
subtask_1_11.txt AC 3 ms 256 KB
subtask_1_2.txt AC 115 ms 896 KB
subtask_1_3.txt AC 1261 ms 6528 KB
subtask_1_4.txt AC 7 ms 384 KB
subtask_1_5.txt AC 10 ms 384 KB
subtask_1_6.txt AC 306 ms 1792 KB
subtask_1_7.txt AC 1242 ms 6528 KB
subtask_1_8.txt AC 7 ms 384 KB
subtask_1_9.txt AC 24 ms 384 KB
subtask_2_1.txt TLE 3154 ms 6528 KB
subtask_2_2.txt TLE 3154 ms 6528 KB
subtask_2_3.txt TLE 3154 ms 6528 KB
subtask_2_4.txt TLE 3154 ms 6528 KB
subtask_2_5.txt AC 946 ms 384 KB
subtask_2_6.txt TLE 3154 ms 640 KB
subtask_2_7.txt TLE 3154 ms 1792 KB
subtask_2_8.txt TLE 3154 ms 6528 KB
subtask_3_1.txt TLE 3154 ms 6528 KB
subtask_3_2.txt TLE 3154 ms 6528 KB
subtask_3_3.txt TLE 3154 ms 512 KB
subtask_3_4.txt TLE 3154 ms 384 KB
subtask_3_5.txt TLE 3154 ms 3456 KB
subtask_3_6.txt TLE 3154 ms 4992 KB
subtask_3_7.txt TLE 3154 ms 6528 KB
subtask_3_8.txt TLE 3154 ms 6528 KB