QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#671110 | #9449. New School Term | maojun | WA | 2ms | 12068kb | C++23 | 1.1kb | 2024-10-24 10:58:22 | 2024-10-24 10:58:23 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e4+5,M=1e6+5;
int n,m,a[M],b[M];
const int E=M<<1;
int tot=0,hd[N],to[E],nxt[E];
inline void Add(int u,int v){to[++tot]=v;nxt[tot]=hd[u];hd[u]=tot;}
int f[N*2];
int fd(int x){return x==f[x]?x:f[x]=fd(f[x]);}
int k,vs[N];vector<int>p[N][2];
void dfs(int u,int c){
if(vs[u])return;vs[u]=c;
p[k][c-1].emplace_back(u);
for(int i=hd[u];i;i=nxt[i])dfs(to[i],c^3);
}
bitset<N/2>dp[N];int g[N];
int main(){
scanf("%d%d",&n,&m);n<<=1;
for(int i=1;i<=m;i++)scanf("%d%d",&a[i],&b[i]);
iota(f+1,f+n*2+1,1);
for(int i=m;i;i--)
if(fd(a[i])!=fd(b[i])&&fd(a[i]+n)!=fd(b[i]+n)){
f[fd(a[i])]=fd(b[i]+n);f[fd(b[i])]=fd(a[i]+n);
Add(a[i],b[i]);Add(b[i],a[i]);
}
for(int i=1;i<=n;i++)if(!vs[i]){k++;dfs(i,1);}
dp[0].set(0);
for(int i=1;i<=k;i++)dp[i]=dp[i-1]<<p[i][0].size()|dp[i-1]<<p[i][1].size();
for(int i=k,j=n/2;i;i--)
if(j>=p[i][0].size()&&dp[i-1][j-p[i][0].size()]){
j-=p[i][0].size();
for(int x:p[i][0])g[x]=1;
}else{
j-=p[i][1].size();
for(int x:p[i][1])g[x]=1;
}
for(int i=1;i<=n;i++)printf("%d",g[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 12068kb
input:
2 4 1 3 2 4 1 4 1 2
output:
0111
result:
wrong answer The number of 0s must be equal to that of 1s.