QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#415097#6705. MedianxiaoleML 1ms3620kbC++231.9kb2024-05-20 09:56:432024-05-20 09:56:44

Judging History

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

  • [2024-05-20 09:56:44]
  • 评测
  • 测评结果:ML
  • 用时:1ms
  • 内存:3620kb
  • [2024-05-20 09:56:43]
  • 提交

answer

#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;using ll = long long;using PLL = pair<ll,ll>;
const ll MAX = 1e18;const ll MIN = -1e18;const ll INF=0x3f3f3f3f;
const ll Q = 2000+9;const ll MOD = 1e9 + 7;
vector<ll> s[Q];
vector<ll> x[Q];
bool vis[Q];
int inde;

ll dfs(ll now){
    ll cnt=1;
    if(vis[now]==false)
    cnt=1;
    else cnt=0;
    vis[now]=true;
    if(inde == -1) return 0;
    for(auto i:s[now]){
        if(i == inde) {inde = -1;return 0;}
        cnt+=dfs(i);
    }
    return cnt;
}
ll dfs2(ll now){
     ll cnt;
    if(vis[now]==false)
    cnt=1;
    else cnt=0;
    vis[now]=true;
    if(inde == -1) return 0;
    for(auto i:x[now]){
        if(i == inde) {inde = -1;return 0;}
        cnt+=dfs2(i);
    }
    return cnt;
}
ll ans[Q];
void solve(){
   ll n,m;cin>>n>>m;
   memset(ans,0,sizeof ans);
   for (ll i = 1; i <= n; i++)
   {
        s[i].clear();
        x[i].clear();
   }
   
   for (ll i = 1; i <= m; i++)
   {
    ll o,p;cin>>o>>p;
    x[o].push_back(p);
    s[p].push_back(o);
   }
    for (ll i = 1; i <= n; i++)
    {   
        inde = i;
        memset(vis,0,sizeof vis);
        ll l=dfs(i)-1;
        if(inde == -1) {
            for (ll i = 0; i < n; i++)
            {
                cout<<0;
            }cout<<"\n";
            return;
            
        }
        inde = i; 
        memset(vis,0,sizeof vis);
        ll r=dfs2(i)-1;
        if(inde == -1) {
            for (ll i = 0; i < n; i++)
            {
                cout<<0;
            }cout<<"\n";
            return;
        }

    //cout<<l<<" "<<r<<"\n";
        if(l<=(n)/2 and r<=(n)/2) ans[i]=1;
        else ans[i]=0;
    }

    for (ll i = 1; i <= n; i++)
    {
        cout<<ans[i];
    }cout<<"\n";
    
}
int main(){
    ios;ll _=1;cin>>_;
    while (_--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3620kb

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: -100
Memory Limit Exceeded

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:


result: