結果

問題 No.317 辺の追加
ユーザー lgswdnlgswdn
提出日時 2023-10-13 16:49:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 1,913 bytes
コンパイル時間 3,584 ms
コンパイル使用メモリ 200,304 KB
実行使用メモリ 4,836 KB
最終ジャッジ日時 2023-10-13 16:49:13
合計ジャッジ時間 7,018 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 20 ms
4,436 KB
testcase_03 AC 19 ms
4,456 KB
testcase_04 AC 30 ms
4,636 KB
testcase_05 AC 17 ms
4,368 KB
testcase_06 AC 22 ms
4,368 KB
testcase_07 AC 8 ms
4,368 KB
testcase_08 AC 48 ms
4,764 KB
testcase_09 AC 25 ms
4,620 KB
testcase_10 AC 28 ms
4,664 KB
testcase_11 AC 19 ms
4,628 KB
testcase_12 AC 27 ms
4,680 KB
testcase_13 AC 25 ms
4,760 KB
testcase_14 AC 24 ms
4,708 KB
testcase_15 AC 27 ms
4,640 KB
testcase_16 AC 31 ms
4,764 KB
testcase_17 AC 26 ms
4,704 KB
testcase_18 AC 27 ms
4,836 KB
testcase_19 AC 27 ms
4,724 KB
testcase_20 AC 36 ms
4,680 KB
testcase_21 AC 8 ms
4,376 KB
testcase_22 AC 5 ms
4,372 KB
testcase_23 AC 6 ms
4,372 KB
testcase_24 AC 11 ms
4,784 KB
testcase_25 AC 9 ms
4,576 KB
testcase_26 AC 9 ms
4,492 KB
testcase_27 AC 8 ms
4,372 KB
testcase_28 AC 6 ms
4,372 KB
testcase_29 AC 2 ms
4,372 KB
testcase_30 AC 61 ms
4,760 KB
testcase_31 AC 54 ms
4,628 KB
testcase_32 AC 53 ms
4,620 KB
testcase_33 AC 54 ms
4,660 KB
testcase_34 AC 53 ms
4,620 KB
testcase_35 AC 54 ms
4,660 KB
testcase_36 AC 54 ms
4,616 KB
testcase_37 AC 55 ms
4,696 KB
testcase_38 AC 60 ms
4,660 KB
testcase_39 AC 54 ms
4,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//vanitas vanitatum et omnia
#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128; 
template<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}      
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x)  {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x)  {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x)  {return (x==0?-1:__builtin_ctzll(x));}

#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii; 
typedef vector<int> vi;  
typedef vector<pii> vp; 
typedef tuple<int,int,int> tiii;
int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
  return x*w;
}

const int N=1e5+5;
int n,m,sz[N],f[N],id[N],c[N];

int find(int x) {return x==id[x]?x:id[x]=find(id[x]);}
void upd(int x,int y) {
  per(i,n,x) chmin(f[i],f[i-x]+y);
}

signed main() {
  n=read(), m=read();
  rep(i,1,n) id[i]=i;
  rep(i,1,m) {
    int u=read(), v=read();
    u=find(u),v=find(v);
    if(u!=v) id[u]=v;
  }
  rep(i,1,n) sz[find(i)]++;
  rep(i,1,n) if(sz[i]) c[sz[i]]++;
  rep(i,1,n) f[i]=N;
  rep(i,1,n) if(c[i]) {
    rep(h,0,20) 
      if((1<<h)<=c[i])
        upd(i<<h,1<<h), c[i]-=(1<<h);
    if(c[i]) upd(c[i]*i,c[i]);
  }
  rep(i,1,n) {
    if(f[i]==N) puts("-1");
    else printf("%d\n",f[i]-1);
  }
  return 0;
}
0