QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#755367#9573. Social MediaWzy#WA 27ms7888kbC++142.1kb2024-11-16 17:08:592024-11-16 17:09:00

Judging History

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

  • [2024-11-16 17:09:00]
  • 评测
  • 测评结果:WA
  • 用时:27ms
  • 内存:7888kb
  • [2024-11-16 17:08:59]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef  long long LL;
typedef pair<int,int> PII;
const int N=200010,M=2000010;
const int mod=1e9+7;
int INF = 1e9;
int h[N],e[M],ne[M],idx;

void add(int a,int b){
    e[idx]=b,ne[idx]=h[a],h[a]=idx++;
}

void solve(){
    int n,m,k;
    cin>>n>>m>>k;

    vector<int> is_friend(k+1);
    for(int i=1;i<=k;i++) h[i]=-1;
    vector<int> d(k+1),f(k+1);

    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        is_friend[x]=true;
    }

    int res=0;
    map<PII,int> mp;
    while(m--){
        int a,b;
        cin>>a>>b;
        if(a==b){
            f[a]++;
            if(is_friend[a]) res++;
            continue;
        }
        add(a,b);
        //cout<<a<<" "<<b<<endl;
        mp[{a,b}]++;
    }

    //cout<<endl;
    for(int u=1;u<=k;u++){
        if(!is_friend[u]) continue;

        for(int i=h[u];~i;i=ne[i]){
            int j=e[i];
            if(!is_friend[j]){
                d[j]++;
                continue;
            }
            //cout<<u<<" "<<j<<endl;
            res++;
        }
    }

    //cout<<res<<endl;

    for(int u=1;u<=k;u++){
        if(is_friend[u]) continue;

        for(int i=h[u];~i;i=ne[i]){
            int j=e[i];
            if(!is_friend[j]) continue;
            else d[u]++;
        }
    }
    int mx=0;

    //cout<<d[2]<<endl;
    for(int u=1;u<=k;u++){
        if(is_friend[u]) continue;

        for(int i=h[u];~i;i=ne[i]){
            int j=e[i];
            if(is_friend[j]) continue;
            
            if(u==j) mx=max(mx,d[u]+f[u]);
            else mx=max(mx,d[u]+d[j]+mp[{u,j}]+mp[{j,u}]+f[u]+f[j]);
        }
    }


    int mx1=0,mx2=0;


    for(int i=1;i<=k;i++){
        if(d[i]+f[i]>mx1) mx2=mx1,mx1=d[i]+f[i];
        else if(d[i]+f[i]>mx2) mx2=f[i]+d[i];
    }
    mx=max(mx,mx1+mx2);
    res+=mx;

    cout<<res<<endl;


}

    
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T=1;
    cin>>T;
    while(T--) solve();
 
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
4 12 7
5 7 3 6
3 6
2 2
1 4
2 4
1 3
7 6
4 1
5 4
1 1
1 1
2 1
3 7
2 7 6
2 4
1 2
3 2
2 5
5 4
2 6
4 6
2 6
1 1 2
1
1 2
2 1 2
1 2
1 2
2 1 100
24 11
11 24

output:

9
5
1
1
1

result:

ok 5 number(s): "9 5 1 1 1"

Test #2:

score: -100
Wrong Answer
time: 27ms
memory: 7888kb

input:

10000
19 12 20
8 12 1 5 11 7 17 13 19 6 3 9 10 15 14 20 4 18 16
4 11
7 1
8 4
16 19
1 13
15 2
16 2
8 7
3 15
11 13
5 20
18 14
17 14 20
2 9 1 12 8 11 10 17 18 16 3 15 5 14 20 13 7
15 10
3 2
5 16
7 8
6 1
6 4
18 16
1 8
4 1
20 6
6 9
4 15
7 5
14 9
1 3 18
9
15 18
17 15
11 14
7 19 7
3 1 2 5 6 4 7
5 1
4 5
3 1...

output:

12
14
1
19
6
5
1
14
19
4
3
10
4
1
4
19
15
2
18
4
17
5
1
2
5
19
3
3
6
15
7
3
6
4
4
7
3
7
4
1
16
16
2
3
6
12
12
7
6
9
8
7
9
11
16
1
4
9
8
16
2
8
22
22
17
8
22
15
8
13
7
9
6
9
2
17
10
5
5
3
6
6
20
8
13
12
10
5
3
6
3
1
8
5
8
12
7
15
10
9
9
11
9
9
6
2
8
15
11
5
3
5
5
10
1
6
9
18
5
3
20
1
4
8
8
10
4
3
1
1...

result:

wrong answer 8th numbers differ - expected: '11', found: '14'