QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#884129 | #9911. 路南柯 | ningago | 61.748738 | 7ms | 8024kb | C++14 | 3.8kb | 2025-02-05 21:27:17 | 2025-02-05 21:27:29 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <cctype>
#include <set>
namespace uvu
{
#define LOCAL ____________DONT_DEFINE_ME____________
// #define ll long long
// #define inf 0x3f3f3f3f
#define int long long
#define inf 0x3f3f3f3f3f3f3f3fll
#define infll 0x3f3f3f3f3f3f3f3fll
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define gline debug("now is #%d\n", __LINE__)
#define pii std::pair <int, int>
#define mkp std::make_pair
#define fi first
#define se second
char _ST_;
const int BUFSIZE = (1 << 20);
char ibuf[BUFSIZE], *iS = ibuf, *iT = ibuf;
char obuf[BUFSIZE], *oS = obuf, *oT = obuf + BUFSIZE;
char getc()
{
#ifdef LOCAL
return getchar();
#else
if(iS == iT) iT = (iS = ibuf) + fread(ibuf, 1, BUFSIZE, stdin);
return iS == iT ? EOF : *iS++;
#endif
#define getchar ERR
}
void Flush() { fwrite(obuf, 1, oS - obuf, stdout); oS = obuf; }
struct Flusher { ~Flusher(){ Flush(); } }iamflusher;
void putc(char c)
{
#ifdef LOCAL
putchar(c);
#else
*oS++ = c;
if(oS == oT) Flush();
#endif
#define putchar ERR
}
template <typename T = int> T read()
{
T x = 0, f = 1; char c = getc();
for(; !isdigit(c); c = getc()) if(c == '-') f = -1;
for(; isdigit(c); c = getc()) x = (x << 3) + (x << 1) + (c ^ 48);
return x * f;
}
template <typename T> void print(T x, char c)
{
static int sta[BUFSIZE], top;
top = 0;
if(x < 0) putc('-'), x = -x;
if(!x) sta[top = 1] = 0;
for(; x; x /= 10) sta[++top] = x % 10;
for(; top; ) putc(sta[top--] ^ 48);
if(c) putc(c);
}
int readstr(char *s, int base)
{
int idx = base - 1; char c = getc();
for(; !(isdigit(c) || isalpha(c) || c == '(' || c == '?'); c = getc());
for(; isdigit(c) || isalpha(c) || c == '(' || c == '?' ; c = getc()) s[++idx] = c;
return idx - base + 1;
}
void printf(const char *s) { for(; *s; s++) putc(*s); }
template <typename T, typename ... Args>
void printf(const char *s, T x, Args ... rest)
{
for(; *s; s++)
{
if(*s != '%') { putc(*s); continue; }
s++; if(*s == 'd') print(x, 0);
else if(*s == 'c') putc(x);
printf(s + 1, rest ...);
return;
}
}
template <typename T> void ckmax(T &x, T y) { x = x > y ? x : y; }
template <typename T> void ckmin(T &x, T y) { x = x < y ? x : y; }
#define mod 998244353
// #define mod 1000000007
int sm(int x) { return x >= mod ? x - mod : x; }
void plus_(int &x, int y) { x = (x + y >= mod ? x + y - mod : x + y); }
void mul_(int &x, int y) { x = 1ll * x * y % mod; }
int ksm(int a, int b) { int res = 1; for(; b; b >>= 1, mul_(a, a)) if(b & 1) mul_(res, a); return res; }
// 最简单的构造:对于每个点输出以它为根任意一个拓扑序
// 简单的优化:只需要对于每个叶子输出即可
#define N 110
int n, h[N], e[N << 1], ne[N << 1], idx = -1, du[N];
void add_edge(int x, int y) { ne[++idx] = h[x], h[x] = idx, du[e[idx] = y]++; }
void add(int x, int y) { add_edge(x, y), add_edge(y, x); }
std::vector <std::vector <int> > ans;
std::vector <int> now;
void dfs0(int k, int fa)
{
for(int i = h[k]; ~i; i = ne[i]) if(e[i] != fa) dfs0(e[i], k);
now.push_back(k);
}
void solve()
{
// memset(h, idx = -1, sizeof(h));
n = read(); for(int i = 1; i <= n; i++) h[i] = idx = -1, du[i] = 0;
ans.clear();
for(int i = 1; i < n; i++) add(read(), read());
for(int i = 1; i <= n; i++) if(du[i] == 1) now.clear(), dfs0(i, 0), ans.push_back(now);
print(ans.size(), '\n');
for(auto vec : ans) { for(auto t : vec) print(t, ' '); putc('\n'); }
}
void init()
{
}
char _ED_;
void mian()
{
debug("%.3f MB\n", abs(&_ST_ - &_ED_) / 1024.0 / 1024);
init(); int T = read();
for(; T; solve(), T--);
}
#ifdef int
#undef int
#endif
}
int main()
{
uvu::mian(); return 0;
}
詳細信息
Subtask #1:
score: 18.7173
Acceptable Answer
Test #1:
score: 18.7173
Acceptable Answer
time: 0ms
memory: 8024kb
input:
10 10 4 2 5 1 8 6 1 9 3 7 1 8 10 2 6 4 3 4 10 4 3 3 1 5 3 6 3 2 3 8 7 8 2 7 10 8 9 10 5 4 10 8 10 3 6 3 9 8 1 10 4 2 2 7 8 4 10 10 6 6 8 1 7 2 6 3 5 3 9 4 2 6 9 3 1 10 2 8 10 4 9 1 9 3 5 7 6 3 1 8 8 7 4 2 10 9 2 9 1 7 1 5 6 8 2 3 9 5 10 5 4 1 10 10 2 9 8 1 8 5 6 3 7 1 6 2 9 8 2 10 4 2 10 5 7 6 2 8 7...
output:
4 7 3 10 2 4 6 8 9 1 5 9 5 1 8 6 10 2 4 3 7 7 3 10 2 4 6 8 5 1 9 7 3 9 5 1 8 6 4 2 10 6 9 10 7 8 2 6 5 4 3 1 9 10 7 8 2 6 5 1 3 4 9 10 7 8 2 6 1 4 3 5 9 10 7 8 2 5 1 4 3 6 6 5 1 4 3 2 10 7 8 9 9 6 5 1 4 3 2 8 7 10 5 6 3 7 2 5 4 9 8 10 1 9 1 6 3 10 8 7 2 4 5 1 7 2 5 4 9 8 10 3 6 9 1 6 3 ...
result:
points 0.935865781 Partial correct.
Subtask #2:
score: 43.0314
Acceptable Answer
Test #2:
score: 43.0314
Acceptable Answer
time: 7ms
memory: 7928kb
input:
100 100 90 19 79 98 23 34 50 41 31 52 61 19 50 30 49 5 95 65 22 44 72 89 49 77 27 7 48 2 28 25 56 12 97 63 98 43 10 4 50 33 12 13 54 16 100 43 23 69 53 5 56 85 39 6 64 92 100 59 2 71 44 29 59 97 64 39 75 53 59 89 16 35 67 16 6 43 38 51 36 22 58 70 3 29 9 61 99 11 49 95 27 72 73 89 23 3 14 3 61 57 26...
output:
38 18 86 8 58 70 83 81 21 14 60 80 87 15 42 82 57 9 61 19 90 62 63 97 78 67 31 52 71 2 48 54 16 35 93 24 66 20 26 91 76 88 40 37 84 92 64 39 6 47 45 79 98 43 100 59 7 27 72 89 73 69 34 23 3 68 10 4 75 53 51 38 65 95 94 28 25 77 49 5 17 36 22 44 29 33 41 50 30 46 55 99 11 32 74 96 85 56 12 13 1 60 8...
result:
points 0.5378927802 Partial correct.