QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#471537 | #6705. Median | chenxinyang2006 | AC ✓ | 2ms | 3796kb | C++20 | 2.1kb | 2024-07-10 21:53:07 | 2024-07-10 21:53:09 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;
template <class T>
void chkmax(T &x,T y){
if(x < y) x = y;
}
template <class T>
void chkmin(T &x,T y){
if(x > y) x = y;
}
inline int popcnt(int x){
return __builtin_popcount(x);
}
inline int ctz(int x){
return __builtin_ctz(x);
}
/*ll power(ll p,int k = mod - 2){
ll ans = 1;
while(k){
if(k % 2 == 1) ans = ans * p % mod;
p = p * p % mod;
k /= 2;
}
return ans;
}*/
int T,n,m;
int G[105][105],deg[105];
queue <int> Q;
bitset <105> dp[105];
int ans[105];
void solve(){
scanf("%d%d",&n,&m);
rep(u,1,n){
fill(G[u],G[u] + n + 1,0);
deg[u] = 0;
dp[u].reset();
dp[u].set(u);
}
rep(i,1,m){
int u,v;
scanf("%d%d",&u,&v);
G[u][v] = 1;deg[u]++;
}
rep(u,1,n) if(!deg[u]) Q.push(u);
int sz = 0;
while(!Q.empty()){
int u = Q.front();
Q.pop();
sz++;
rep(v,1,n){
if(!G[v][u]) continue;
dp[v] |= dp[u];
deg[v]--;
if(!deg[v]) Q.push(v);
}
}
if(sz < n){
rep(u,1,n) printf("0");
printf("\n");
return;
}
rep(u,1,n) ans[u] = dp[u].count() <= (n / 2 + 1);
rep(u,1,n){
deg[u] = 0;
dp[u].reset();
dp[u].set(u);
}
rep(u,1,n){
rep(v,1,n) if(G[u][v]) deg[v]++;
}
rep(u,1,n) if(!deg[u]) Q.push(u);
while(!Q.empty()){
int u = Q.front();
Q.pop();
rep(v,1,n){
if(!G[u][v]) continue;
dp[v] |= dp[u];
deg[v]--;
if(!deg[v]) Q.push(v);
}
}
rep(u,1,n){
ans[u] &= dp[u].count() <= (n / 2 + 1);
printf("%d",ans[u]);
}
printf("\n");
}
int main(){
// freopen("test.in","r",stdin);
scanf("%d",&T);
while(T--) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3796kb
input:
2 5 4 1 2 3 2 2 4 2 5 3 2 1 1 2 3
output:
01000 000
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 2ms
memory: 3796kb
input:
66 13 2 9 13 7 11 11 19 9 1 8 1 5 1 2 8 4 2 2 1 5 2 6 3 3 11 3 2 4 6 6 10 9 8 3 5 1 7 5 8 3 9 4 9 6 7 3 1 2 3 11 6 9 4 1 6 5 2 1 5 4 6 8 4 15 15 10 6 15 8 7 6 11 1 5 2 3 4 11 13 4 6 10 12 10 13 1 6 15 2 5 12 13 14 5 3 15 86 14 12 8 1 14 9 8 15 5 10 1 9 11 2 6 2 7 10 10 13 14 5 4 13 5 8 4 10 13 9 6 9...
output:
1111111111111 01001000111 111 11111111111 111111111111111 001001000000000 00100 01100 1111111 1000000000000 111101101 111111111 000011111011101 010111111 001100000 0100001001101 1111111111111 001000010000000 10010111011 001000000000100 11111111111 00100000011 11111 01000000110 11101110111 00000 1111...
result:
ok 66 lines