結果

問題 No.826 連絡網
ユーザー kotatsugamekotatsugame
提出日時 2019-05-04 01:06:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 683 bytes
コンパイル時間 608 ms
コンパイル使用メモリ 69,616 KB
実行使用メモリ 10,804 KB
最終ジャッジ日時 2023-08-15 18:26:36
合計ジャッジ時間 2,393 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 46 ms
8,492 KB
testcase_13 AC 15 ms
5,512 KB
testcase_14 AC 33 ms
7,380 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 20 ms
6,024 KB
testcase_17 AC 15 ms
5,460 KB
testcase_18 AC 12 ms
4,968 KB
testcase_19 AC 54 ms
9,480 KB
testcase_20 AC 54 ms
9,648 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 16 ms
5,340 KB
testcase_23 AC 21 ms
6,000 KB
testcase_24 AC 8 ms
4,464 KB
testcase_25 AC 67 ms
10,732 KB
testcase_26 AC 10 ms
4,596 KB
testcase_27 AC 48 ms
8,688 KB
testcase_28 AC 37 ms
7,492 KB
testcase_29 AC 15 ms
5,192 KB
testcase_30 AC 69 ms
10,804 KB
testcase_31 AC 19 ms
5,660 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:36:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   36 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
#include<vector>
struct UF{
	int n;
	vector<int>parent,rank;
	UF(int n_=0):n(n_),parent(n_),rank(n_,1)
	{
		for(int i=0;i<n_;i++)parent[i]=i;
	}
	int find(int a)
	{
		return parent[a]!=a?parent[a]=find(parent[a]):a;
	}
	bool same(int a,int b)
	{
		return find(a)==find(b);
	}
	bool unite(int a,int b)
	{
		a=find(a),b=find(b);
		if(a==b)return false;
		if(rank[a]<rank[b])
		{
			parent[a]=b;
			rank[b]+=rank[a];
		}
		else
		{
			parent[b]=a;
			rank[a]+=rank[b];
		}
		return true;
	}
};
main()
{
	int N,P;
	cin>>N>>P;
	UF uf(N+1);
	for(int i=2;i<=N;i++)
	{
		for(int j=i;j+i<=N;j+=i)uf.unite(j,j+i);
	}
	cout<<uf.rank[uf.find(P)]<<endl;
}
0