提出 #776329


ソースコード 拡げる

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

int N,M,Q;
pair<int, pair<int,int> > edge [200000];
pair<int, pair<int,int> > query [100000];
int ans [100000];

class union_find
{
	public:
	union_find(int n)
		:node(n + 1),compo(n + 1,1)
	{
		for(int i = 1;i <= n;i++){
			node [i] = i;
		}
	}
	int go(int x)
	{
		return compo [find(x)];
	}
	int find(int x)
	{
		if(node [x] == x){
			return x;
		}
		return node [x] = find(node [x]);
	}
	void connect(int x,int y)
	{
		x = find(x);
		y = find(y);

		if(x != y){
			node [y] = x;
			compo [x] += compo [y];
		}
	}
	private:
		vector<int> node;
		vector<int> compo;
};
int main()
{
	scanf("%d%d",&N,&M);
	for(int i = 0;i < M;i++){
		scanf("%d%d%d",&edge [i].second.first,&edge [i].second.second,&edge [i].first);
	}

	scanf("%d",&Q);
	for(int i = 0;i < Q;i++){
		scanf("%d%d",&query [i].second.first,&query [i].first);
		query [i].second.second = i;
	}

	sort(edge,edge + M,greater< pair<int, pair<int,int> > >());
	sort(query,query + Q,greater< pair<int, pair<int,int> > >());

	union_find uf(N);

	int idx = 0;
	for(int i = 0;i < Q;i++){
		while(idx < M && edge [idx].first > query [i].first){
			uf.connect(edge [idx].second.first,edge [idx].second.second);
			idx++;
		}
		ans [query [i].second.second] = uf.go(query [i].second.first);
	}
	for(int i = 0;i < Q;i++){
		printf("%d\n",ans [i]);
	}

	return 0;
}

提出情報

提出日時
問題 D - 道路の老朽化対策について
ユーザ cmmnd17
言語 C++14 (GCC 5.4.1)
得点 100
コード長 1436 Byte
結果 AC
実行時間 198 ms
メモリ 5504 KiB

コンパイルエラー

./Main.cpp: In function ‘int main()’:
./Main.cpp:46:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&N,&M);
                     ^
./Main.cpp:48:81: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d",&edge [i].second.first,&edge [i].second.second,&edge [i].first);
                                                                                 ^
./Main.cpp:51:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&Q);
                ^
./Main.cpp:53:57: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&query [i].second.first,&query [i].first);
                                                         ^

ジャッジ結果

セット名 Sample Subtask1 All
得点 / 配点 0 / 0 50 / 50 50 / 50
結果
AC × 3
AC × 10
AC × 22
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
Subtask1 sample_01.txt, sample_02.txt, sample_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt
All sample_01.txt, sample_02.txt, sample_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt
ケース名 結果 実行時間 メモリ
sample_01.txt AC 4 ms 256 KiB
sample_02.txt AC 4 ms 256 KiB
sample_03.txt AC 4 ms 256 KiB
subtask1_01.txt AC 6 ms 256 KiB
subtask1_02.txt AC 6 ms 256 KiB
subtask1_03.txt AC 6 ms 256 KiB
subtask1_04.txt AC 5 ms 256 KiB
subtask1_05.txt AC 6 ms 256 KiB
subtask1_06.txt AC 6 ms 256 KiB
subtask1_07.txt AC 6 ms 256 KiB
subtask2_01.txt AC 197 ms 5504 KiB
subtask2_02.txt AC 196 ms 5376 KiB
subtask2_03.txt AC 197 ms 5376 KiB
subtask2_04.txt AC 198 ms 5376 KiB
subtask2_05.txt AC 109 ms 3840 KiB
subtask2_06.txt AC 196 ms 5504 KiB
subtask2_07.txt AC 193 ms 5504 KiB
subtask2_08.txt AC 189 ms 5504 KiB
subtask2_09.txt AC 198 ms 5376 KiB
subtask2_10.txt AC 196 ms 5376 KiB
subtask2_11.txt AC 195 ms 5248 KiB
subtask2_12.txt AC 184 ms 5120 KiB