QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#814105 | #9875. Don't Detect Cycle | ucup-team3161# | WA | 67ms | 9380kb | C++17 | 1.8kb | 2024-12-14 15:17:21 | 2024-12-14 15:17:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define pii pair<int,int>
#define eb emplace_back
const int N=1e5+5;
mt19937_64 rand1;
int T,n,m,_u[N],_v[N],dg[N],ans[N];
bool vse[N];
int fa[N],d[N];
int w1[N];ull w[N];
bool vs[N],tr[N];
vector<pii> e[N];
void dfs(int u,int f)
{
fa[u]=f;
d[u]=d[f]+1;
vs[u]=1;
for(auto [v,id]:e[u]) if(!vse[id] && !vs[v])
tr[id]=1,dfs(v,u);
}
void dfs1(int u,int f)
{
vs[u]=1;
for(auto [v,id]:e[u]) if(!vse[id] && !vs[v])
dfs1(v,u),w[u]^=w[v],w1[u]+=w1[v];
}
int get()
{
int r=0;
for(int i=1;i<=n;++i) if(dg[i]) {r=i;break;}
fill(tr+1,tr+m+1,0);
fill(vs+1,vs+n+1,0);
dfs(r,0);
fill(w+1,w+n+1,0);
fill(w1+1,w1+n+1,0);
for(int i=1;i<=m;++i)
if(!vse[i] && !tr[i])
{
int u=_u[i],v=_v[i];
if(d[u]<d[v]) swap(u,v);
v=fa[v];
ull t=rand1();
w[u]^=t;
w[v]^=t;
++w1[u];
--w1[v];
}
fill(vs+1,vs+n+1,0);
dfs1(r,0);
for(int i=1;i<=m;++i) if(!vse[i])
{
int u=_u[i],v=_v[i];
if(w[u]==w[v] && w1[u]<2 && w1[v]<2)
return i;
}
return 0;
}
void slv()
{
scanf("%d %d",&n,&m);
fill(dg+1,dg+m+1,0);
for(int i=1;i<=n;++i) e[i].clear();
for(int i=1,u,v;i<=m;++i)
{
scanf("%d %d",&u,&v);
_u[i]=u;_v[i]=v;
++dg[u];++dg[v];
e[u].eb(v,i);
e[v].eb(u,i);
}
fill(vse+1,vse+m+1,0);
for(int i=m,t;i;--i)
{
t=ans[i]=get();
if(!t) {puts("-1");return;}
vse[t]=1;
--dg[_u[t]];--dg[_v[t]];
}
for(int i=1;i<=m;++i) printf("%d ",ans[i]);
puts("");
}
int main()
{
scanf("%d",&T);
while(T--) slv();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 9380kb
input:
1 4 4 1 2 2 3 3 4 4 2
output:
4 3 1 2
result:
ok Correct
Test #2:
score: 0
Accepted
time: 2ms
memory: 9232kb
input:
4 4 5 1 2 2 3 3 4 3 1 1 4 5 3 1 2 2 3 3 4 9 10 3 5 1 8 5 8 4 9 6 7 7 9 1 2 1 4 2 4 4 6 8 10 1 4 3 8 2 5 3 4 1 5 5 8 2 8 5 7 4 5 3 7
output:
-1 3 2 1 10 9 8 4 2 7 6 5 3 1 -1
result:
ok Correct
Test #3:
score: -100
Wrong Answer
time: 67ms
memory: 8888kb
input:
50 3214 2907 970 1929 2860 3033 1322 2296 931 1192 861 2505 831 2469 231 2549 1 2306 1765 1842 999 3171 177 2007 1798 1894 827 3180 673 1738 1163 1573 2213 2781 2766 3200 1663 2197 1797 2281 315 2637 442 2689 558 2874 1520 2591 651 1923 1133 2920 1747 2412 1104 1528 313 2487 632 3124 660 2182 1581 2...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 12 11 10 8 17 15 5 3 16 13 14 7 6 1 2 9 4 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 4 16 11 7 3 18 10 17 14 15 8 6 13 2 5 12 9 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 19 11 9 20 18 16 2 17 15 12 1 13 5 14 10 7 8 6 3 4 10 8 6 14 13 12 7 4 1 11 2 5 3 9 -1 -1 11 12 9 8 14 10 13 4...
result:
wrong answer Wrong - you can add all edges, but found: -1