답안 #666932

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
666932 2022-11-30T00:31:14 Z irmuun 도로 폐쇄 (APIO21_roads) C++17
0 / 100
2000 ms 7804 KB
#include <bits/stdc++.h>
#include "roads.h"
using namespace std;
#define ll long long
#define pb push_back 
struct dsu{
    vector<ll>p,sz;
    dsu(ll n){
        p.resize(n+1);
        iota(p.begin(),p.end(),0);
        sz.resize(n+1);
        fill(sz.begin(),sz.end(),1);
    }
    ll find(ll x){
        if(p[x]==x){
            return x;
        }
        return p[x]=find(p[x]);
    }
    ll size(ll x){
        return sz[find(x)];
    }
    bool same(ll x,ll y){
        x=find(x);
        y=find(y);
        if(x==y){
            return true;
        }
        else{
            return false;
        }
    }
    void merge(ll x,ll y){
        x=find(x);
        y=find(y);
        if(x!=y){
            if(sz[x]<sz[y]){
                swap(x,y);
            }
            sz[x]+=sz[y];
            p[y]=x;
        }
    }
};
vector<ll>minimum_closure_costs(int n,vector<int>v,vector<int>u,vector<int>w){
    ll total=0;
    vector<tuple<ll,ll,ll>>dist;
    for(int i=0;i<v.size();i++){
        dist.pb({w[i],v[i],u[i]});
        total+=w[i];
    }
    sort(dist.begin(),dist.end());
    vector<ll>ans;
    for(int k=0;k<n;k++){
        dsu ds(n+5);
        ll cur=0;
        for(int i=dist.size()-1;i>=0;i--){
            ll x=get<1>(dist[i]),y=get<2>(dist[i]),dis=get<0>(dist[i]);
            if(ds.same(x,y)==false&&ds.size(x)+ds.size(y)<=k+1){
                ds.merge(x,y);
                cur+=dis;
            }
        }
        ans.pb(total-cur);
    }
    return ans;
}

Compilation message

roads.cpp: In function 'std::vector<long long int> minimum_closure_costs(int, std::vector<int>, std::vector<int>, std::vector<int>)':
roads.cpp:48:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 31 ms 468 KB Output is correct
3 Correct 34 ms 440 KB Output is correct
4 Correct 32 ms 484 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 25 ms 444 KB Output is correct
9 Correct 32 ms 472 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Execution timed out 2064 ms 4856 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 2048 ms 7420 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2055 ms 7804 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2055 ms 7804 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 31 ms 468 KB Output is correct
3 Correct 34 ms 440 KB Output is correct
4 Correct 32 ms 484 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 25 ms 444 KB Output is correct
9 Correct 32 ms 472 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Execution timed out 2064 ms 4856 KB Time limit exceeded
13 Halted 0 ms 0 KB -