QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#44037 | #4539. Independent Feedback Vertex Set | Cfer# | AC ✓ | 269ms | 8928kb | C++17 | 1.1kb | 2022-08-12 13:27:19 | 2022-08-12 13:27:19 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<cmath>
#include<bitset>
#include<cmath>
#define int long long
#define x first
#define y second
#define ps push_back
#define endl '\n'
#define kd ios::sync_with_stdio(false);cin.tie();cout.tie(0);
using namespace std;
typedef pair<int,int>pi;
const int N=2e5+100,mod=1e9+7,INF=1e10;
int lowbit(int x){return x&-x;}
int gcd(int a,int b){return a%b==0?b:gcd(b,a%b);}
int w[N];
pi e[N];
int n,col[N];
int wk(int x)
{
for(int i=1;i<=n;i++)col[i]=-1;
col[x]=1;
int ans=w[x];
for(int i=4;i<=n;i++)
{
int u=e[i].x,v=e[i].y;
if(col[u]==-1&&col[v]==-1)
{
ans+=w[i];
col[i]=1;
}
}
return ans;
}
void solve()
{
cin>>n;
for(int i=1;i<=n;i++)cin>>w[i];
for(int i=1;i<=n-3;i++)
{
int u,v;cin>>u>>v;
e[i+3]={u,v};
}
int res=0;
for(int i=1;i<=3;i++)
{
res=max(wk(i),res);
}
cout<<res<<endl;
}
signed main()
{
kd;
int _;_=1;
cin>>_;
while(_--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 269ms
memory: 8928kb
input:
1000 1561 14 78 18 74 80 97 70 49 39 81 79 65 55 1 29 32 91 73 94 41 69 41 79 34 62 81 25 33 76 26 57 69 66 48 37 78 67 50 21 8 27 58 58 32 8 42 31 52 35 36 99 56 61 27 4 64 50 59 43 55 73 53 41 80 94 32 56 59 19 57 28 56 35 73 70 13 18 6 96 47 71 29 16 73 65 27 61 68 50 11 21 96 19 18 33 97 6 43 19...
output:
26477 730 133872218725 206 139 26838 225784601561 409 163907525588 65 27568981002 26830437 612 206 647 3808763 392 39765006630 9823066 71309193 126 10667 93591615 12028 113 12356789 2420359 213 418 223 166 40 5324 219 1419 562 663 22941 14 39 102638547 14199134 58 201 12653791 101 10447 16511 171245...
result:
ok 1000 lines