Submission #546249

# Submission time Handle Problem Language Result Execution time Memory
546249 2022-04-06T21:03:18 Z leaked Reconstruction Project (JOI22_reconstruction) C++14
7 / 100
2519 ms 26588 KB
#include <bits/stdc++.h>

#define f first
#define s second
#define vec vector
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pw(x) (1LL<<(x))
#define sz(x) (int)(x).size()
#define m_p make_pair
#define fast_prep ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;
template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);}
template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);}
const int N=501;
int p[N],sz[N];
void make(int v){
    p[v]=v;sz[v]=1;
}
int get(int v){
    return p[v]=(p[v]==v?v:get(p[v]));
}
bool mg(int a,int b){
    a=get(a),b=get(b);
    if(a==b) return 0;
    if(sz[a]<sz[b]) swap(a,b);
    p[b]=a;sz[a]+=sz[b];
    return 1;
}


signed main(){
    fast_prep;
    int n,m;
    cin>>n>>m;
    vec<array<int,3>> arr;
    for(int i=0;i<m;i++){
        int v,u,w;
        cin>>v>>u>>w;--v;--u;
        arr.pb({w,v,u});
    }
    sort(all(arr));
    vec<array<ll,3>> change;

    for(int i=0;i<m;i++){
        for(int j=0;j<n;j++) make(j);
        int j=i+1;
        while(j<m){
            mg(arr[j][1],arr[j][2]);
            if(get(arr[i][1])==get(arr[i][2])) break;
            ++j;
        }
        int x=(j==m?1e9:(arr[j][0]+arr[i][0]+1)/2);
        ///
        change.pb({x,-1,arr[i][0]});

        for(int j=0;j<n;j++) make(j);
        j=i-1;
        while(j>=0){
            mg(arr[j][1],arr[j][2]);
            if(get(arr[i][1])==get(arr[i][2])) break;
            --j;
        }
        x=(j==-1?-1:(arr[j][0]+arr[i][0]+1)/2);

        change.pb({x,-1,arr[i][0]});

        change.pb({arr[i][0],2,-2ll*arr[i][0]});
    }
    sort(all(change));
    int q;
    cin>>q;
    ll a=0,b=0;
    int j=0;
    for(int i=0;i<q;i++){
        int x;
        cin>>x;
        while(j<sz(change) && x>=change[j][0]){
            a+=change[j][1];b+=change[j][2];
            ++j;
        }
        cout<<1ll*a*x+b<<'\n';
    }
    return 0;
}
/*
5 10
1 2 8
1 3 13
1 4 5
1 5 11
1 5 3
2 3 7
2 4 15
3 4 6
3 5 6
4 5 2
1
10
17
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2496 ms 20368 KB Output is correct
5 Correct 2519 ms 24216 KB Output is correct
6 Correct 2471 ms 24456 KB Output is correct
7 Correct 1407 ms 26316 KB Output is correct
8 Correct 1122 ms 26448 KB Output is correct
9 Correct 1075 ms 26588 KB Output is correct
10 Correct 2452 ms 24656 KB Output is correct
11 Correct 1128 ms 26284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -