我不知道为什么,但把我自己hack掉了
我刚AC的喜悦啊,随便造组数据就把自己hack掉了QAQ
应该是数据导致重边造成的,但题目没说
输入:
3 3
1 0 2 1
3 0 1 0
2 1 1 0
我的输出:
POSSIBLE
0 0 0
显然不满足第二条情况
我手搓的正确解,可能有遗漏:
POSSIBLE
case 1:0 0 1
case 2:1 1 0
麻烦聚铑们验算下这组数据的正确解,球球了QAQ
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e6+5;
const int maxm=3e6+7;
struct edge
{
int to;
int last;
};
edge edges[maxm*2];
int head[maxn];
int tot=0;
int dfn[maxn];
int low[maxn];
int vis[maxn];
stack<int> s;
int idx=0;
int scccnt=0;
int scc[maxn];
int ans[maxn];
inline void adde(int u,int v)
{
edges[++tot].last=head[u];
edges[tot].to=v;
head[u]=tot;
}
void strongtarjan(int x)
{
s.push(x);
dfn[x]=low[x]=++idx;
vis[x]=1;
for(int i=head[x];i!=0;i=edges[i].last)
{
int v=edges[i].to;
if(!dfn[v])
{
strongtarjan(v);
low[x]=min(low[x],low[v]);
}
else if(vis[v])
{
low[x]=min(low[x],dfn[v]);
}
}
if(dfn[x]==low[x])
{
scccnt++;
int u=0;
do
{
u=s.top();
vis[u]=0;
s.pop();
scc[u]=scccnt;
}
while(x!=u);
}
}
int main()
{
int n=0,m=0,u=0,v=0,uval=0,vval=0;
cin>>n>>m;
for(int i=1;i<=m;i++)
{
cin>>u>>uval>>v>>vval;
adde(u+(!uval)*n,v+vval*n);
adde(v+(!vval)*n,u+uval*n);
}
for(int i=1;i<=2*n;i++)
{
if(!dfn[i])strongtarjan(i);
}
for(int i=1;i<=n;i++)
{
if(scc[i]==scc[i+n])
{
cout<<"IMPOSSIBLE";
return 0;
}
ans[i]=(scc[i]>scc[i+n]?1:0);
}
cout<<"POSSIBLE"<<endl;
for(int i=1;i<=n;i++)
{
cout<<ans[i];
if(i<n)cout<<' ';
}
return 0;
}
判断标准:起码跟我的错误输出一致(
5这位更是重量级,输出0 1 0,三条全崩了,默哀QAQ
这位的输出也是0 1 0