QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#497628 | #3836. So I'll Max Out My Constructive Algorithm Skills | PetroTarnavskyi# | WA | 0ms | 3548kb | C++20 | 1.8kb | 2024-07-29 15:19:29 | 2024-07-29 15:19:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
struct DSU
{
int n;
VI p, sz;
void init(int _n)
{
n = _n;
p.resize(n);
iota(ALL(p), 0);
sz.assign(n, 1);
}
int find(int v)
{
if (v == p[v])
return v;
return p[v] = find(p[v]);
}
bool unite(int u, int v)
{
u = find(u);
v = find(v);
if (u == v)
return false;
if (sz[u] > sz[v])
swap(u, v);
p[u] = v;
sz[v] += sz[u];
return true;
}
};
const int N = 100'447;
VI g[N];
int p[N];
void dfs(int v, int par)
{
p[v] = par;
for (auto to : g[v])
{
if (to != par)
dfs(to, v);
}
}
void solve()
{
int n, m;
cin >> n >> m;
DSU d;
d.init(n);
map<PII, int> mp;
bool res = false;
FOR (i, 0, m)
{
int u, v;
cin >> u >> v;
u--, v--;
if (!d.unite(u, v))
{
VI ans;
dfs(u, -1);
while (v != u)
{
int pv = p[v];
ans.PB(mp[{v, pv}]);
v = pv;
}
ans.PB(i);
sort(ALL(ans));
FOR (j, 0, SZ(ans))
{
if (j)
cout << ' ';
cout << ans[j] + 1;
}
cout << '\n';
res = true;
FOR (k, i, m)
cin >> u >> u;
break;
}
mp[{u, v}] = i;
mp[{v, u}] = i;
g[u].PB(v);
g[v].PB(u);
}
if (!res)
cout << -1 << '\n';
FOR (i, 0, n)
{
g[i].clear();
p[i] = -1;
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--)
solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3548kb
input:
1 2 4 3 2 1
output:
2
result:
wrong output format Unexpected end of file - int32 expected