Submission #1000504

# Submission time Handle Problem Language Result Execution time Memory
1000504 2024-06-17T15:55:37 Z De3b0o Reconstruction Project (JOI22_reconstruction) C++14
7 / 100
5000 ms 9052 KB
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define in insert
#define pb push_back
#define ppb pop_back()
#define d3 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define cans cout << ans << "\n";
#define yes cout << "Yes" << "\n";
#define no cout << "No" << "\n";
#define pll pair<ll,ll>
#define lin cout << "\n";
#define sqr 340
#define mod 1000000007
#define mid ((l+r)/2)
#define lc (2*x)
#define rc (2*x+1)

using namespace std;

ll n , m , q;
ll dsu[509];
ll sz[509];
ll e1[100009] , e2[100009] , c[100009];

ll gp(ll u)
{
    if(dsu[u]==u)
        return u;
    return dsu[u]=gp(dsu[u]);
}

void merg(ll u , ll v)
{
    u = gp(u);
    v = gp(v);
    if(sz[v]>sz[u])
        swap(u,v);
    sz[u]+=sz[v];
    dsu[v]=u;
}

ll mst(ll x)
{
    for(int i = 1 ; n>=i ; i++)
    {
        dsu[i]=i;
        sz[i]=1;
    }
    vector<pair<ll,pll>> v;
    for(int i = 0 ; m>i ; i++)
        v.pb({abs(c[i]-x),{e1[i],e2[i]}});
    sort(v.begin(),v.end());
    ll ans = 0;
    ll mx = 1;
    for(auto it : v)
    {
        if(mx==n)
            break;
        if(gp(it.S.F)==gp(it.S.S))
            continue;
        merg(it.S.F,it.S.S);
        mx=max(mx,sz[gp(it.S.F)]);
        mx=max(mx,sz[gp(it.S.S)]);
        ans+=it.F;
    }
    return ans;
}

int main()
{
    d3
    cin >> n >> m;
    for(int i = 0 ; m>i ; i++)
    {
        ll u , v , w;
        cin >> u >> v >> w;
        e1[i]=u;
        e2[i]=v;
        c[i]=w;
    }
    cin >> q;
    while(q--)
    {
        ll x;
        cin >> x;
        ll ans = mst(x);
        cans
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 98 ms 8248 KB Output is correct
21 Correct 99 ms 8740 KB Output is correct
22 Correct 98 ms 8992 KB Output is correct
23 Correct 99 ms 8252 KB Output is correct
24 Correct 98 ms 8236 KB Output is correct
25 Correct 104 ms 8376 KB Output is correct
26 Correct 99 ms 8256 KB Output is correct
27 Correct 108 ms 8224 KB Output is correct
28 Correct 115 ms 8216 KB Output is correct
29 Correct 141 ms 8868 KB Output is correct
30 Correct 96 ms 8476 KB Output is correct
31 Correct 105 ms 8248 KB Output is correct
32 Correct 110 ms 9052 KB Output is correct
33 Correct 100 ms 8256 KB Output is correct
34 Correct 123 ms 8252 KB Output is correct
35 Correct 100 ms 8260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Execution timed out 5085 ms 8280 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Execution timed out 5077 ms 4948 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 98 ms 8248 KB Output is correct
21 Correct 99 ms 8740 KB Output is correct
22 Correct 98 ms 8992 KB Output is correct
23 Correct 99 ms 8252 KB Output is correct
24 Correct 98 ms 8236 KB Output is correct
25 Correct 104 ms 8376 KB Output is correct
26 Correct 99 ms 8256 KB Output is correct
27 Correct 108 ms 8224 KB Output is correct
28 Correct 115 ms 8216 KB Output is correct
29 Correct 141 ms 8868 KB Output is correct
30 Correct 96 ms 8476 KB Output is correct
31 Correct 105 ms 8248 KB Output is correct
32 Correct 110 ms 9052 KB Output is correct
33 Correct 100 ms 8256 KB Output is correct
34 Correct 123 ms 8252 KB Output is correct
35 Correct 100 ms 8260 KB Output is correct
36 Execution timed out 5045 ms 8428 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 98 ms 8248 KB Output is correct
21 Correct 99 ms 8740 KB Output is correct
22 Correct 98 ms 8992 KB Output is correct
23 Correct 99 ms 8252 KB Output is correct
24 Correct 98 ms 8236 KB Output is correct
25 Correct 104 ms 8376 KB Output is correct
26 Correct 99 ms 8256 KB Output is correct
27 Correct 108 ms 8224 KB Output is correct
28 Correct 115 ms 8216 KB Output is correct
29 Correct 141 ms 8868 KB Output is correct
30 Correct 96 ms 8476 KB Output is correct
31 Correct 105 ms 8248 KB Output is correct
32 Correct 110 ms 9052 KB Output is correct
33 Correct 100 ms 8256 KB Output is correct
34 Correct 123 ms 8252 KB Output is correct
35 Correct 100 ms 8260 KB Output is correct
36 Correct 1 ms 2392 KB Output is correct
37 Correct 1 ms 2392 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Execution timed out 5085 ms 8280 KB Time limit exceeded
40 Halted 0 ms 0 KB -