QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#341208#4513. Slide ParadeGraphcity0 2564ms46812kbC++203.4kb2024-02-29 16:32:042024-02-29 16:32:04

Judging History

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

  • [2024-02-29 16:32:04]
  • 评测
  • 测评结果:0
  • 用时:2564ms
  • 内存:46812kb
  • [2024-02-29 16:32:04]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rof(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
const int Maxn=1e5,Maxk=1e6,inf=1e9;

int n,m,cnt[405][405];
struct Link{int to,nxt;} Edge[Maxk+5];
int tot,Head[Maxn+5];
inline void Add(int x,int y) {Edge[++tot]=(Link){y,Head[x]},Head[x]=tot;}
vector<int> st;
inline void dfs(int x)
{
    for(int &i=Head[x];i;) {int y=Edge[i].to; i=Edge[i].nxt,dfs(y);}
    st.push_back(x);
}

struct Graph
{
    int s,t,vis[Maxn+5],dis[Maxn+5],maxf;
    struct Node{int frm,to,nxt,w;} Edge[Maxn*2+5];
    int tot=1,Head[Maxn+5],cur[Maxn+5],pr[Maxn+5];
    inline void Addedge(int x,int y,int k)
    {
        Edge[++tot]=Node{x,y,Head[x],k},Head[x]=tot;
        Edge[++tot]=Node{y,x,Head[y],0ll},Head[y]=tot;
    }
    inline int bfs()
    {
        queue<int> q; For(i,1,t) dis[i]=vis[i]=0,cur[i]=Head[i];
        dis[s]=0,vis[s]=1,q.push(s);
        while(!q.empty())
        {
            int x=q.front(); q.pop();
            for(int i=Head[x];i;i=Edge[i].nxt)
            {
                int y=Edge[i].to;
                if(Edge[i].w && !vis[y])
                    dis[y]=dis[x]+1,vis[y]=1,q.push(y);
            }
        } return vis[t];
    }
    inline int dfs(int x,int flow)
    {
        if(!flow || x==t) {maxf+=flow; return flow;}
        int used=0,res=0;
        for(int i=cur[x];i && used<flow;i=Edge[i].nxt)
        {
            int y=Edge[i].to; cur[x]=i;
            if(dis[y]==dis[x]+1 && Edge[i].w)
                if(res=dfs(y,min(flow-used,Edge[i].w)))
                    used+=res,Edge[i].w-=res,Edge[i^1].w+=res;
        } return used;
    }
    inline void dfs(int x)
    {
        for(int i=Head[x];i;i=Edge[i].nxt) if(!Edge[i].w)
        {
            int y=Edge[i].to; if(y==s || y==t || vis[y]) continue;
            vis[y]=1,pr[y]=x,dfs(y);
        }
    }
    inline int Work(int x)
    {
        For(i,1,t) vis[i]=0; vis[x]=1,dfs(x);
        for(int i=Head[x];i;i=Edge[i].nxt) if(Edge[i].w)
        {
            int y=Edge[i].to; if(y==s || y==t) continue;
            if(!vis[y]) return 0; cnt[x][y]++;
            for(int k=y;k!=x;k=pr[k])
                {int a=pr[k],b=k; if(a>b) swap(a,b); cnt[a][b]++;}
        } return 1;
    }
    inline void Solve()
    {
        For(x,1,n) for(int i=Head[x];i;i=Edge[i].nxt)
        {
            int y=Edge[i].to; if(y==s || y==t) continue;
            if(!Edge[i].w) cnt[x][y]=m-cnt[x][y];
            while(cnt[x][y]--) Add(y-n,x);
        }
    }
    inline void Clear() {For(i,1,t) Head[i]=0; tot=1;}
} G;

inline void Clear()
{
    G.Clear(); For(i,1,n) Head[i]=0;
    For(i,1,n*2) For(j,1,n*2) cnt[i][j]=0;
    tot=0,vector<int>().swap(st);
}
inline void Solve(int cid)
{
    cin>>n>>m; G.s=n*2+1,G.t=n*2+2,G.maxf=0;
    For(i,1,n) G.Addedge(G.s,i,1),G.Addedge(i+n,G.t,1);
    For(i,1,m) {int a,b; cin>>a>>b; G.Addedge(b,a+n,1);}
    while(G.bfs()) G.dfs(G.s,inf);
    if(G.maxf!=n) {printf("Case #%d: IMPOSSIBLE\n",cid); Clear(); return;}
    For(i,1,n) if(!G.Work(i)) {printf("Case #%d: IMPOSSIBLE\n",cid); Clear(); return;}
    G.Solve(),dfs(1),reverse(st.begin(),st.end());
    printf("Case #%d: %d\n",cid,int(st.size()));
    for(auto i:st) printf("%d ",i); printf("\n"),Clear();
}

int main()
{
    // freopen("1.in","r",stdin);

    int T,cid=0; cin>>T;
    while(T--) Solve(++cid);
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 8112kb

input:

100
5 8
1 2
1 3
1 4
1 5
2 1
3 1
4 1
5 1
5 10
1 3
1 4
2 3
2 5
3 1
3 4
3 5
4 2
5 1
5 3
5 10
1 4
2 3
2 5
3 1
3 5
4 2
4 3
4 5
5 1
5 2
3 6
1 2
1 3
2 1
2 3
3 1
3 2
5 10
1 2
1 5
2 3
2 4
3 1
4 3
4 5
5 2
5 3
5 4
4 10
1 2
1 3
1 4
2 1
2 3
2 4
3 1
3 4
4 2
4 3
5 10
1 2
1 3
2 1
2 4
3 1
3 5
4 2
4 5
5 3
5 4
5 10
1 ...

output:

Case #1: IMPOSSIBLE
Case #2: 51
1 4 2 5 3 5 3 5 1 4 2 5 1 4 2 5 1 4 2 5 1 4 2 5 1 4 2 3 5 1 4 2 3 5 1 3 5 1 3 4 2 3 4 2 3 4 2 3 1 3 1 
Case #3: 51
1 4 5 2 5 2 5 2 3 5 2 3 5 2 3 5 2 3 1 4 5 2 3 1 4 5 1 4 5 1 4 5 1 4 3 1 4 3 1 4 2 3 1 4 2 3 1 4 2 3 1 
Case #4: 19
1 3 2 3 2 3 2 3 1 3 1 3 1 2 1 2 1 2 1 ...

result:

wrong answer the slide from 3 to 4 hasn't be used (test case 25)

Test #2:

score: 0
Wrong Answer
time: 2564ms
memory: 46812kb

input:

100
199 4980
1 95
1 96
1 105
1 124
1 130
1 131
1 135
1 137
1 139
1 140
1 141
1 147
1 155
1 172
1 174
1 179
1 183
1 188
1 193
1 196
1 197
2 3
2 5
2 13
2 14
2 17
2 20
2 24
2 26
2 30
2 41
2 44
2 45
2 52
2 56
2 67
2 70
2 71
2 74
2 78
2 84
2 85
2 90
2 92
2 93
2 97
2 107
2 111
2 113
2 122
2 124
2 128
2 13...

output:

Case #1: IMPOSSIBLE
Case #2: IMPOSSIBLE
Case #3: 1000001
1 193 195 197 200 169 196 195 197 200 169 196 195 197 200 169 196 195 197 200 169 196 195 197 200 169 196 195 197 200 169 196 195 197 200 169 196 195 197 200 169 196 195 197 200 169 196 195 197 200 169 196 195 197 200 169 196 195 197 200 169 1...

result:

wrong answer the slide from 3 to 4 hasn't be used (test case 27)