QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#814160#9875. Don't Detect Cycleucup-team3161#WA 129ms11720kbC++172.5kb2024-12-14 15:37:452024-12-14 15:37:47

Judging History

你现在查看的是最新测评结果

  • [2024-12-14 15:37:47]
  • 评测
  • 测评结果:WA
  • 用时:129ms
  • 内存:11720kb
  • [2024-12-14 15:37:45]
  • 提交

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],we[N];
vector<ull> z[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],we[u]^=we[v],w1[u]+=w1[v];
}
bool chk(int u,ull w)
{
    auto it=lower_bound(z[u].begin(),z[u].end(),w);
    if(it==z[u].end() || it+1==z[u].end()) return 0;
    return *(it+1)==w;
}
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;
            we[u]^=t;
            we[v]^=t;
            ++w1[u];
            --w1[v];
        }
    fill(vs+1,vs+n+1,0);
    dfs1(r,0);
    for(int i=1;i<=n;++i) z[i].clear();
    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);
            z[u].eb(we[u]);
            z[v].eb(we[u]);
        }
    for(int i=1;i<=n;++i)
        sort(z[i].begin(),z[i].end());
    for(int i=1;i<=m;++i) if(!vse[i])
    {
        int u=_u[i],v=_v[i];
        if(d[u]<d[v]) swap(u,v);
        if(w[u]!=w[v]) continue;
        if(w1[u]<2 && w1[v]<2) return i;
        if(tr[i] && chk(u,we[u]) && chk(v,we[u])) 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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 10944kb

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: 0ms
memory: 11720kb

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: 129ms
memory: 11644kb

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