結果

問題 No.317 辺の追加
ユーザー 小指が強い人小指が強い人
提出日時 2016-02-14 03:31:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 471 ms / 2,000 ms
コード長 2,848 bytes
コンパイル時間 1,584 ms
コンパイル使用メモリ 173,848 KB
実行使用メモリ 35,316 KB
最終ジャッジ日時 2023-10-22 05:05:49
合計ジャッジ時間 14,143 ms
ジャッジサーバーID
(参考情報)
judge9 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
11,516 KB
testcase_01 AC 6 ms
11,516 KB
testcase_02 AC 263 ms
25,772 KB
testcase_03 AC 315 ms
27,812 KB
testcase_04 AC 226 ms
22,984 KB
testcase_05 AC 329 ms
26,848 KB
testcase_06 AC 401 ms
30,848 KB
testcase_07 AC 115 ms
17,792 KB
testcase_08 AC 235 ms
22,456 KB
testcase_09 AC 334 ms
29,224 KB
testcase_10 AC 464 ms
34,964 KB
testcase_11 AC 149 ms
14,136 KB
testcase_12 AC 466 ms
35,004 KB
testcase_13 AC 170 ms
16,796 KB
testcase_14 AC 374 ms
31,496 KB
testcase_15 AC 440 ms
33,912 KB
testcase_16 AC 274 ms
25,400 KB
testcase_17 AC 403 ms
32,400 KB
testcase_18 AC 456 ms
34,860 KB
testcase_19 AC 471 ms
35,316 KB
testcase_20 AC 256 ms
24,088 KB
testcase_21 AC 119 ms
20,708 KB
testcase_22 AC 67 ms
16,388 KB
testcase_23 AC 67 ms
16,500 KB
testcase_24 AC 202 ms
27,572 KB
testcase_25 AC 146 ms
23,352 KB
testcase_26 AC 156 ms
23,800 KB
testcase_27 AC 124 ms
21,276 KB
testcase_28 AC 68 ms
16,476 KB
testcase_29 AC 21 ms
12,740 KB
testcase_30 AC 282 ms
28,776 KB
testcase_31 AC 292 ms
28,784 KB
testcase_32 AC 297 ms
28,784 KB
testcase_33 AC 295 ms
28,784 KB
testcase_34 AC 297 ms
28,784 KB
testcase_35 AC 297 ms
28,784 KB
testcase_36 AC 293 ms
28,784 KB
testcase_37 AC 294 ms
28,784 KB
testcase_38 AC 283 ms
28,776 KB
testcase_39 AC 293 ms
28,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> veci;
typedef vector<string> vecs;
template<class T,class U> using Hash=unordered_map<T,U>;

#define REP(i, a, n) for(ll i = a; i < n; i++)
#define RREP(i, a, n) for(ll i = n-1; i >= 0; i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, 0, n)
#define MD 1000000007

template<class T> T read(){T a;cin >> a;return a;}
template<class T> T read(T& a){cin >> a;}
template<class T> void rarr(T a, int n){for(int i = 0; i < n; i++) {cin >> a[i];}}
template<class T> void write(T a){cout << a << endl;}
template<class T> void writes(vector<T> a, char* c = " "){cout << a[0];for(int i = 1; i < a.size(); i++)cout << c << a[i];cout << endl;;}
void write(double a){cout << fixed << setprecision(12) << a << endl;}
template<class T> void warr(T a, int n, char* c = " "){cout << a[0];for(int i = 1; i < n; i++)cout << c << a[i];cout << endl;}
void split(string s, string delim, veci& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(atoi(s.substr(pos).data()));break;}else {result.push_back(atoi(s.substr(pos, p - pos).data()));}pos = p + delim.size();}}
void split(string s, string delim, vecs& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(s.substr(pos));break;}else {result.push_back(s.substr(pos, p - pos));}pos = p + delim.size();}}
ll gcd(ll a, ll b){while(true){ll k = a % b;if(k == 0)return b;a = b;b = k;}}
ll comb(ll n, ll m){ll p=1;m=min(m,n-m);for(ll i=1;i<=m;i++){p*=n-i+1;p/=i;}return p;}

Hash<int,bool> h[100000];
bool b[100000]={0};
int ct(int i){
    if(b[i])return 0;
    b[i]=true;
    int res=1;
    for(auto k:h[i]){
        res += ct(k.first);
    }
    return res;
}

int main(void)
{
    int n,m;
    cin>>n>>m;
    rep(i,m){
        int u,v;
        cin>>u>>v;
        if(u==v)continue;
        u--;v--;
        h[u][v]=h[v][u]=true;
    }
    int p[300001]={0};
    int dp[300001]={0};
    rep(i,100001)dp[i]=-1;
    rep(i,n){
        if(b[i])continue;
        int t=ct(i);
        p[t]++;
    }
    dp[0]=0;
    rrep(i,100001){
        if(p[i]==0)continue;
        rrep(j,n+1){
            if(dp[j]==-1)continue;
            int w=i;
            rep(k,p[i]){
                if(j+w>100000)break;
                if(dp[j+w]==-1)
                    dp[j+w]=dp[j+w-i]+1;
                else
                    if(dp[j+w]<=dp[j+w-i]+1)
                        break;
                    else
                        dp[j+w]=dp[j+w-i]+1;
                w+=i;
            }
        }
    }
    REP(i,1,n+1)
        if(dp[i]==-1)write(dp[i]);
        else write(dp[i]-1);
	return 0;
}
0