結果
問題 | No.317 辺の追加 |
ユーザー |
![]() |
提出日時 | 2015-12-12 15:40:01 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,623 bytes |
コンパイル時間 | 812 ms |
コンパイル使用メモリ | 87,000 KB |
実行使用メモリ | 16,028 KB |
最終ジャッジ日時 | 2024-09-15 08:44:15 |
合計ジャッジ時間 | 4,772 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 4 WA * 1 TLE * 3 -- * 30 |
ソースコード
#include <iostream>#include <stdio.h>#include <vector>#include <map>#include <set>#include <queue>#include <deque>#include <stack>#include <algorithm>#include <functional>#include <cmath>#include <string>using namespace std;typedef vector <int> VI;typedef vector <VI> VVI;typedef vector <string> VS;typedef pair<int,int> PII;typedef long long LL;typedef vector <LL> VLL;typedef unsigned long long ULL;typedef pair <int, LL> PIL;typedef vector <PIL> VPIL;//#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)//#define sort(c) sort((c).begin(),(c).end())#define range(i,a,b) for(int i=(a); i < (b); i++)#define rep(i,n) range(i,0,n)int parent[100001];int Pre[100002];int ans[100001];int root(int x){if (x != parent[x]) parent[x] = root(parent[x]);return parent[x];}int solve(int n, int x){if (x <= n) return x;if (ans[x] == -1 && ans[x-n] != -1) ans[x] = ans[x-n] + 1;Pre[x] = solve(n,Pre[x]);return ans[x] == -1 ? x : Pre[x];}int main(){int N,M,C,u,v,n,tmp_max;map <int,int> conn_comp;map <int,int> :: iterator it;VI comp_num;cin >> N >> M;rep(i,N+2) Pre[i]=i-1;rep(i,N){ans[i+1] = -1; parent[i] = i;}rep(i,M){cin >> u >> v;u = root(u-1); v = root(v-1);if (u!=v) parent[u] = v;}rep(i,N)conn_comp[root(i)] += 1;for (it=conn_comp.begin();it!=conn_comp.end();it++) comp_num.push_back(it->second);sort(comp_num.begin(),comp_num.end(),greater<int>());C = comp_num.size();tmp_max = 0;rep(i,C){n = comp_num[i];tmp_max += n;solve(n,tmp_max+1);ans[n] = 0;}rep(i,N) cout << ans[i+1] << endl;return 0;}