結果
| 問題 | No.1424 Ultrapalindrome |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-12-09 10:41:05 |
| 言語 | C++17(gcc12) (gcc 12.4.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,611 bytes |
| 記録 | |
| コンパイル時間 | 7,177 ms |
| コンパイル使用メモリ | 266,916 KB |
| 実行使用メモリ | 20,636 KB |
| 最終ジャッジ日時 | 2026-06-15 20:27:43 |
| 合計ジャッジ時間 | 10,422 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 3 |
| other | WA * 29 |
ソースコード
#include "testlib.h"
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <climits>
#include <cassert>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <algorithm>
#define forn(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
int leader(vector<int>& dsu, int idx)
{
return dsu[idx] == idx ? dsu[idx] : (dsu[idx] = leader(dsu, dsu[idx]));
}
bool merge(vector<int>& dsu, int a, int b)
{
a = leader(dsu, a);
b = leader(dsu, b);
if (a == b)
return false;
else
{
if (rnd.next(2) == 0)
dsu[a] = b;
else
dsu[b] = a;
return true;
}
}
int main(int argc, char* argv[])
{
registerValidation(argc, argv);
int n = inf.readInt(2, 100000, "n");
inf.readEoln();
vector<int> dsu(n);
forn(i, n)
dsu[i] = i;
set<pair<int,int> > edges;
forn(i, n - 1)
{
int x = inf.readInt(1, n, "x_i");
inf.readSpace();
int y = inf.readInt(1, n, "y_i");
inf.readEoln();
ensuref(x != y, "Tree can't contain loops");
ensuref(edges.count(make_pair(x, y)) == 0, "Tree can't contain multiple edges between a pair of vertices");
edges.insert(make_pair(x, y));
edges.insert(make_pair(y, x));
ensuref(merge(dsu, x - 1, y - 1), "Tree can't contain cycles");
}
inf.readEof();
return 0;
}