QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#688797 | #3846. Link-Cut Tree | DepletedPrism# | RE | 0ms | 6800kb | C++14 | 1.3kb | 2024-10-30 13:36:44 | 2024-10-30 13:36:44 |
Judging History
answer
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
namespace Patakou {
const int N = 114514;
int f[N];
vector<pair<int, int> > G[N];
int stk[N], top;
inline int read() {
int x;
scanf("%d", &x);
return x;
}
inline void add(int x, int y, int z) {
G[x].push_back(make_pair(y, z));
G[y].push_back(make_pair(x, z));
}
int get(int x) { return f[x] == x ? x : f[x] = get(f[x]); }
void dfs(int x, int t, int father) {
if (x == t) {
sort(stk + 1, stk + top + 1);
for (int i = 1; i < top; ++i) printf("%d ", stk[i]);
printf("%d\n", stk[top]);
return;
}
for (auto y : G[x]) {
if (y.first == father) continue;
++top;
stk[top] = y.second;
dfs(y.first, t, x);
--top;
}
}
int QAQ() {
int T = read();
while (T--) {
int n = read(), m = read();
for (int i = 1; i <= n; ++i) f[i] = i, G[i].clear();
bool flag = true;
for (int i = 1; i <= m && flag; ++i) {
int x = read(), y = read();
if (get(x) == get(y)) {
flag = false;
top = 1;
stk[top] = i;
dfs(x, y, 0);
break;
}
add(x, y, i);
f[get(x)]=get(y);
}
if (flag) puts("-1");
}
return 0;
}
} // namespace Patakou
int main() { return Patakou::QAQ(); }
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 6800kb
input:
2 6 8 1 2 2 3 5 6 3 4 2 5 5 4 5 1 4 2 4 2 1 2 4 3
output:
2 4 5 6 -1
result:
ok 2 lines
Test #2:
score: -100
Runtime Error
input:
1658 9 20 6 4 5 8 1 7 2 3 3 8 3 1 4 8 5 3 7 6 1 6 4 9 4 1 9 3 2 5 4 5 8 9 1 8 4 2 5 7 3 6 14 78 13 12 10 8 2 10 6 13 2 14 13 1 14 10 9 6 2 13 8 3 9 8 5 6 14 12 8 1 9 14 9 5 12 6 5 10 3 12 10 4 8 5 9 10 6 8 1 6 12 4 3 13 1 5 10 3 13 9 10 13 2 5 4 7 7 1 7 6 9 3 2 12 1 10 9 1 1 14 3 1 3 4 11 1 11 6 7 1...