結果
| 問題 |
No.363 門松サイクル
|
| コンテスト | |
| ユーザー |
koyumeishi
|
| 提出日時 | 2016-03-16 01:59:55 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,402 bytes |
| コンパイル時間 | 819 ms |
| コンパイル使用メモリ | 97,240 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-01 20:10:03 |
| 合計ジャッジ時間 | 5,820 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 2 |
| other | WA * 27 |
ソースコード
//入力確認用
#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;
}
koyumeishi