QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#408710#6705. MedianyldAC ✓1ms3712kbC++202.8kb2024-05-10 21:46:152024-05-10 21:46:16

Judging History

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

  • [2024-05-10 21:46:16]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3712kb
  • [2024-05-10 21:46:15]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int MAXN=2e2+5;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(!isdigit(ch))
    {
        if(ch=='-'){f=-1;}
        ch=getchar();
    }
    while(isdigit(ch))
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}

vector<int> edge1[MAXN],edge2[MAXN];
int vis[MAXN];
int dfs1(int u)
{
    vis[u]=1;
    int res=1;
    for(auto v:edge1[u])
    {
        if(vis[v]) continue; 
        res+=dfs1(v);
    }
    return res;
}
int dfs2(int u)
{
    vis[u]=1;
    int res=1;
    for(auto v:edge2[u])
    {
        if(vis[v]) continue;
        res+=dfs2(v);
    }
    return res;
}
void solve()
{
    int n=read(),m=read();
    for(int i=1;i<=n;i++) edge1[i].clear(),edge2[i].clear();
    vector<int> deg1(n+1),deg2(n+1),num1(n+1),num2(n+1),deg3(n+1),deg4(n+1);
    for(int i=1;i<=m;i++)
    {
        int u=read(),v=read();
        edge1[u].push_back(v);
        deg1[v]++;
        edge2[v].push_back(u);
        deg2[u]++;
    }
    queue<int> q;
    auto topo1=[&]()->void
    {
        for(int i=1;i<=n;i++) vis[i]=0;
        for(int i=1;i<=n;i++) if(deg1[i]==0) q.push(i);
        while(q.size())
        {
            int u=q.front();
            vis[u]=1;
            q.pop();
            for(auto v:edge1[u])
            {
                deg1[v]--;
                if(deg1[v]==0) q.push(v);
            }
        }    
    };
    auto topo2=[&]()->void
    {
        for(int i=1;i<=n;i++) vis[i]=0;
        for(int i=1;i<=n;i++) if(deg2[i]==0) q.push(i);
        while(q.size())
        {
            int u=q.front();
            vis[u]=1;
            q.pop();
            for(auto v:edge2[u])
            {
                deg2[v]--;
                if(deg2[v]==0) q.push(v);
            }
        }    
    };
    topo1();
    int flag=0;
    for(int i=1;i<=n;i++)
    {
        if(!vis[i])
        {
            flag=1;
            break;
        }
    }
    if(flag)
    {
        for(int i=1;i<=n;i++) cout<<0;
        cout<<endl;
        return;
    }
    topo2();
    flag=0;
    for(int i=1;i<=n;i++)
    {
        if(!vis[i])
        {
            flag=1;
            break;
        }
    }
    if(flag)
    {
        for(int i=1;i<=n;i++) cout<<0;
        cout<<endl;
        return;
    }
    dfs2(1);
    for(int i=1;i<=n;i++)
    {
        memset(vis,0,sizeof vis);
        int num1=dfs1(i);
        memset(vis,0,sizeof vis);
        int num2=dfs2(i);
        // cout<<num1<<' '<<num2<<endl;
        if(n-num1-num2+1>=abs(num1-num2)) cout<<1;
        else cout<<0;
    }
    cout<<endl;
}
signed main()
{
    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: 1ms
memory: 3492kb

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: 0ms
memory: 3712kb

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