結果
問題 | No.317 辺の追加 |
ユーザー |
![]() |
提出日時 | 2025-01-19 11:44:39 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 924 bytes |
コンパイル時間 | 629 ms |
コンパイル使用メモリ | 61,284 KB |
実行使用メモリ | 20,412 KB |
最終ジャッジ日時 | 2025-01-19 11:46:58 |
合計ジャッジ時間 | 126,234 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | TLE * 2 |
other | TLE * 38 |
コンパイルメッセージ
main.cpp: In function ‘int dfs(int&, int)’: main.cpp:23:1: warning: no return statement in function returning non-void [-Wreturn-type] 23 | } | ^
ソースコード
#include<iostream>using namespace std;int n,m;struct pos{int to,net;}r[400005];int top=1,head[100005],vis[100005],w[100005],f[100005];void add(int a,int b){r[top]=(pos){b,head[a]};head[a]=top;top++;}int dfs(int &cnt,int x){cnt++;for (int i=head[x];i!=0;i=r[i].net){if(vis[r[i].to]==0){vis[r[i].to]=1;dfs(cnt,r[i].to);}}}int main(){cin >> n >> m;for (int i=1;i<=m;i++){int a,b;cin >> a >> b;add(a,b);add(b,a);}int ttop=1;for (int i=1;i<=n;i++){int cnt=0;if(vis[i]==0){vis[i]=1;dfs(cnt,i);w[ttop++]=cnt;// cout << cnt << " ";}}// cout << endl;f[0]=1;for (int i=1;i<=ttop;i++){for (int j=n;j>=w[i];j--){if(f[j-w[i]]!=0){if(f[j]!=0)f[j]=min(f[j],f[j-w[i]]+1);else f[j]=f[j-w[i]]+1;}}}for (int i=1;i<=n;i++){if(f[i]==0)cout << -1 << "\n";else cout << f[i]-2 << "\n";}}/*6 32 34 55 6*/