QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#410905#6329. Colorful Graphgrass8cow#WA 410ms6196kbC++172.2kb2024-05-14 16:49:082024-05-14 16:49:09

Judging History

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

  • [2024-05-14 16:49:09]
  • 评测
  • 测评结果:WA
  • 用时:410ms
  • 内存:6196kb
  • [2024-05-14 16:49:08]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int I=1e9,N=7e3+10;
int dfn[N],low[N],sta[N],top;
bool in[N];
vector<int>g[N],G[N];
int sc,col[N],ry[N];
void dfs(int x){
	dfn[x]=low[x]=++dfn[0],sta[++top]=x,in[x]=1;
	for(int v:g[x]){
		if(!dfn[v])dfs(v),low[x]=min(low[x],low[v]);
		else if(in[v])low[x]=min(low[x],dfn[v]);
	}
	if(dfn[x]==low[x]){
		sc++,ry[sc]=x;
		while(sta[top]!=x)col[sta[top]]=sc,in[sta[top]]=0,top--;
		in[x]=0,col[x]=sc,top--;
	}
}
int S,T,hd[50100],flow[201000],nxt[201000],to[201000],cn=1;
void ad(int u,int v,int w){
	to[++cn]=v,flow[cn]=w,nxt[cn]=hd[u],hd[u]=cn;
	to[++cn]=u,flow[cn]=0,nxt[cn]=hd[v],hd[v]=cn;
}
int d[50100];
bool bfs(){
	for(int i=1;i<=T;i++)d[i]=0;
	d[S]=1;queue<int>q;q.push(S);
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int i=hd[u];i;i=nxt[i])if(flow[i]&&!d[to[i]])
			d[to[i]]=d[u]+1,q.push(to[i]);
	}
	return d[T]>0;
}
int dfs(int u,int in){
	if(u==T)return in;
	int out=0;
	for(int i=hd[u];i&&in;i=nxt[i])if(flow[i]&&d[to[i]]==d[u]+1){
		int p=dfs(to[i],min(in,flow[i]));
		in-=p,out+=p,flow[i]-=p,flow[i^1]+=p;
	}
	if(!out)d[u]=0;return out;
}
int dinic(){
	int s=0;
	while(bfs())s+=dfs(S,I);
	return s;
}
int n,m,wh[7010],ans[7010],de[7010];
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1,u,v;i<=m;i++)scanf("%d%d",&u,&v),g[u].push_back(v);
    for(int i=1;i<=n;i++)if(!dfn[i])dfs(i);
    S=sc*2+1,T=S+1;
    for(int i=1;i<=sc;i++)ad(S,i,1),wh[i]=cn+1,ad(i+sc,T,1),ad(i+sc,i,I);
    for(int i=1;i<=n;i++)for(int v:g[i])if(col[i]!=col[v])ad(col[i],col[v]+sc,I);
    int tc=sc-dinic();
    for(int i=1;i<=sc;i++)for(int j=hd[i];j;j=nxt[j])if(flow[j]!=I&&sc<to[j]&&to[j]<=sc*2)
    G[i].push_back(to[j]-sc),de[to[j]-sc]++;
    tc=0;
    while(1){
        int ntc=tc;
        for(int j=1;j<=sc;j++)if(G[j].size()>de[j]){
            tc++;int o=j;ans[o]=tc;
            while(!G[o].empty()){
                int v=G[o].back();G[o].pop_back();
                de[v]--;
                o=v,ans[v]=tc;
            }
        }
        if(ntc==tc)break;
    }
    for(int i=1;i<=sc;i++)if(!ans[i])ans[i]=++tc;
    for(int i=1;i<=n;i++)printf("%d ",ans[col[i]]);
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 6196kb

input:

5 5
1 4
2 3
1 3
2 5
5 1

output:

1 1 1 2 1 

result:

ok AC

Test #2:

score: 0
Accepted
time: 1ms
memory: 4152kb

input:

5 7
1 2
2 1
4 3
5 1
5 4
4 1
4 5

output:

1 1 2 1 1 

result:

ok AC

Test #3:

score: 0
Accepted
time: 0ms
memory: 6192kb

input:

8 6
6 1
3 4
3 6
2 3
4 1
6 4

output:

1 1 1 1 2 1 3 4 

result:

ok AC

Test #4:

score: -100
Wrong Answer
time: 410ms
memory: 5912kb

input:

7000 6999
4365 4296
2980 3141
6820 4995
4781 24
2416 5844
2940 2675
3293 2163
3853 5356
262 6706
1985 1497
5241 3803
353 1624
5838 4708
5452 3019
2029 6161
3849 4219
1095 1453
4268 4567
1184 1857
2911 3977
1662 2751
6353 6496
2002 6628
1407 4623
425 1331
4445 4277
1259 3165
4994 1044
2756 5788
5496 ...

output:

1750 1552 914 1362 2117 1751 1752 989 456 1260 2158 3127 1753 3343 1288 1754 724 1755 360 1710 761 590 3365 1246 1562 1756 1757 2504 1071 1758 580 637 1759 1760 973 974 1170 1761 3389 1762 1298 545 1763 694 1764 388 1765 2440 1766 1767 12 1768 838 3145 1526 1388 2650 1769 295 1770 618 2936 2016 2295...

result:

wrong answer Integer 2117 violates the range [1, 1750]