QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#470224 | #6705. Median | zzisjtu | AC ✓ | 3ms | 3820kb | C++23 | 1.9kb | 2024-07-10 11:24:00 | 2024-07-10 11:24:01 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define all(x) x.begin(), x.end()
#define lowbit(i) ((i)&(-i))
#define pii pair<int,int>
#define endl '\n'
#define mk(x,y) make_pair(x,y)
#define popcount(x) __builtin_popcount(x)
const double pi=3.14159265358979323846;
const double eps=1e-9;
const int inf=1e9;
const long long INF=4e18;
const int mod=1e9+7;
using namespace std;
const int N=1e5+10;
void solve()
{
int n,m;
cin>>n>>m;
vector<vector<int>>e(n+1),g(n+1);
bool flag=false;
for(int i=1;i<=m;i++){
int a,b;
cin>>a>>b;
e[a].push_back(b);
g[b].push_back(a);
if(a==b)flag=1;
}
if(flag){
for(int i=1;i<=n;i++){
cout<<"0";
}
cout<<endl;
return;
}
int cnt=n/2;
vector<int>ans(n+1,1);
vector<int>pre(n+1),suf(n+1);//前驱结点与后继结点的个数
vector<int>vis(n+1);
auto bfs=[&](int u){
queue<int>q;
q.push(u);
vis[u]=1;
while(q.size()){
int x=q.front();q.pop();
for(int v:e[x]){
if(v==u)return false;
if(vis[v]==u)continue;
vis[v]=u;
q.push(v);
pre[v]++;suf[u]++;
}
}
return true;
};
for(int i=1;i<=n;i++){
if(!bfs(i)){
for(int i=1;i<=n;i++){
cout<<"0";
}
cout<<endl;
return;
}
}
// for(int i=1;i<=n;i++){
// cout<<pre[i]<<" "<<suf[i]<<endl;
// }
for(int i=1;i<=n;i++){
if(suf[i]>n/2||pre[i]>n/2)ans[i]=0;
}
for(int i=1;i<=n;i++){
cout<<ans[i];
}
cout<<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T=1;
cin>>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: 3820kb
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: 3ms
memory: 3584kb
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