結果

問題 No.363 門松サイクル
ユーザー koyumeishikoyumeishi
提出日時 2016-03-16 01:59:55
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,402 bytes
コンパイル時間 680 ms
コンパイル使用メモリ 97,284 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 19:56:04
合計ジャッジ時間 5,756 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

//入力確認用
#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <functional>
#include <set>
#include <ctime>
#include <random>
#include <chrono>
#include <cassert>
using namespace std;

template<class T> istream& operator >> (istream& is, vector<T>& vec){for(T& val: vec) is >> val; return is;}
template<class T> istream& operator ,  (istream& is, T& val){ return is >> val;}
template<class T> ostream& operator << (ostream& os, const vector<T>& vec){for(int i=0; i<vec.size(); i++) os << vec[i] << (i==vec.size()-1?"":" "); return os;}
template<class T> ostream& operator ,  (ostream& os, const T& val){ return os << " " << val;}
template<class T> ostream& operator >> (ostream& os, const T& val){ return os << " " << val;}


class UnionFindTree{
	struct base_node{
		int parent;
		int rank;
		int size;
	};
	
	vector<base_node> node;
public:
	UnionFindTree(int n){
		node.resize(n);
		for(int i=0; i<n; i++){
			node[i].parent=i;
			node[i].rank=0;
			node[i].size=1;
		}
	}

	int find(int x){  //return root node of x
		if(node[x].parent == x) return x;
		else{
			return node[x].parent = find(node[x].parent);
		}
	}
	
	bool same(int x, int y){
		return find(x) == find(y);
	}

	int size(int at){
		return node[find(at)].size;
	}

	void unite(int x, int y){
		x = find(node[x].parent);
		y = find(node[y].parent);

		if(x==y) return;

		if(node[x].rank < node[y].rank){
			node[x].parent = y;
			node[y].size += node[x].size;
		}else if(node[x].rank > node[y].rank){
			node[y].parent = x;
			node[x].size += node[y].size;
		}else{
			node[x].rank++;
			unite(x,y);
		}
	}
};


int main_(){
	int n;
	cin >> n;
	assert(2<=n && n<=100000);
	vector<int> a(n);
	for(int i=0; i<n; i++){
		//scanf("%d", &a[i]);
		cin >> a[i];
		assert(1<=a[i] && a[i]<=100000);
	}
	UnionFindTree uft(n);
	for(int i=0; i<n-1; i++){
		int u,v;
		cin >> u,v;
		//scanf("%d%d", &u,&v);
		assert(1<=u && u<=n);
		assert(1<=v && v<=n);
		assert(u!=v);
		u--,v--;
		uft.unite(u,v);
	}

	int q;
	cin >> q;
	assert(1<=q && q<=100000);
	while(q--){
		int u,v;
		cin >> u,v;
		//scanf("%d%d", &u,&v);
		assert(1<=u && u<=n);
		assert(1<=v && v<=n);
		assert(u!=v);
		cout << "UNKO" << endl;
	}
	return 0;
}

int main(){
	//auto s = clock();
	main_();
	//cerr << clock()-s << " [ms] " << endl;
	return 0;
}
0