QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#733571 | #9573. Social Media | 20225954# | RE | 0ms | 0kb | C++20 | 1.5kb | 2024-11-10 19:53:36 | 2024-11-10 19:53:36 |
answer
#include<bits/stdc++.h>
using namespace std;
#define db(x) cerr<<#x<<" " <<(x)<<" \n"
#define ll long long
const int N = 2e5+10;
vector<pair<int,int> > v[N];
int vis[N];
int val[N];
void solve(){
int n,m,k,ans1 =0,ans2 =0;
cin>>n>>m>>k;
for(int i=1;i<=n;i++){
int x;cin>>x;vis[x] =1;
}
using pii =pair<int ,int >;
map<pii,int > mp;
for(int i=1;i<=m;i++){
int x,y;
cin>>x>>y;
if(x>y)swap(x,y);
if(vis[x]&&vis[y]){
// db(x),db(y);ans1++;
ans1++;
} else if(x==y&&!vis[x]){
val[x]++;
}else if(vis[x]^vis[y]){
if(vis[x])swap(x,y);
val[x]++;
}else if(!vis[x]&&!vis[y]){
mp[{x,y}]++;
v[x].push_back({0,y});
v[y].push_back({0,x});
}
}
for(int i=1;i<=k;i++){
if(vis[i])continue;
for(auto& [x,y]:v[i]){
int a= i,b = y;
if(a>b)swap(a,b);
x+=val[y];
if(mp.count({a,b}))x+=mp[{a,b}];
}
sort(v[i].begin(),v[i].end());
int tmp = v[i][v[i].size()-1].first;
ans2 = max(ans2,tmp+val[i]);
// ans2 = max(ans2,val[i]+ prev(v[i].end())->first);
}
// db(ans1);
cout<<ans1+ans2<<"\n";
for(int i=1;i<=k;i++)vis[i] =0,val[i] =0;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int _=1;
cin>>_;
while(_--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
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