結果

問題 No.317 辺の追加
ユーザー 小指が強い人小指が強い人
提出日時 2016-02-14 03:16:34
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,755 bytes
コンパイル時間 1,730 ms
コンパイル使用メモリ 173,972 KB
実行使用メモリ 35,232 KB
最終ジャッジ日時 2023-10-22 05:05:09
合計ジャッジ時間 15,172 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
11,432 KB
testcase_01 AC 6 ms
11,432 KB
testcase_02 AC 282 ms
25,688 KB
testcase_03 AC 314 ms
27,728 KB
testcase_04 AC 696 ms
22,900 KB
testcase_05 AC 339 ms
26,764 KB
testcase_06 AC 410 ms
30,764 KB
testcase_07 AC 114 ms
17,708 KB
testcase_08 AC 1,628 ms
22,372 KB
testcase_09 AC 378 ms
29,140 KB
testcase_10 AC 469 ms
34,880 KB
testcase_11 TLE -
testcase_12 AC 479 ms
34,920 KB
testcase_13 TLE -
testcase_14 AC 396 ms
31,412 KB
testcase_15 AC 467 ms
33,828 KB
testcase_16 AC 670 ms
25,316 KB
testcase_17 AC 407 ms
32,316 KB
testcase_18 AC 465 ms
34,776 KB
testcase_19 AC 475 ms
35,232 KB
testcase_20 AC 957 ms
24,004 KB
testcase_21 AC 117 ms
20,624 KB
testcase_22 AC 65 ms
16,304 KB
testcase_23 AC 67 ms
16,416 KB
testcase_24 AC 201 ms
27,488 KB
testcase_25 AC 144 ms
23,268 KB
testcase_26 AC 152 ms
23,716 KB
testcase_27 AC 122 ms
21,192 KB
testcase_28 AC 67 ms
16,392 KB
testcase_29 AC 21 ms
12,656 KB
testcase_30 AC 270 ms
28,692 KB
testcase_31 AC 274 ms
28,700 KB
testcase_32 AC 277 ms
28,700 KB
testcase_33 AC 281 ms
28,700 KB
testcase_34 AC 284 ms
28,700 KB
testcase_35 AC 276 ms
28,700 KB
testcase_36 AC 276 ms
28,700 KB
testcase_37 AC 277 ms
28,700 KB
testcase_38 AC 272 ms
28,692 KB
testcase_39 AC 276 ms
28,700 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;
    rep(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>130000)break;
                if(dp[j+w]==-1)
                    dp[j+w]=dp[j+w-i]+1;
                else
                    dp[j+w]=min(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