QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#876359 | #6388. Network | Zhamshid | 0 | 10ms | 28104kb | C++14 | 2.1kb | 2025-01-30 20:10:43 | 2025-01-30 20:10:50 |
Judging History
answer
#include <bits/stdc++.h>
#define noSuccess t--
#define int long long
#define pb push_back
#define F first
#define S second
#define YouCanDoGreatThings ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(s) s.begin(),s.end()
#define yes "YES\n"
#define no "NO\n"
#define sz size
using namespace std;
const int maxn = 1e6;
vector<int>g[maxn];
int used[maxn];
int timer;
void dfs(int v){
used[v]=timer;
for(auto& to: g[v]){
if(used[to]==1e10) dfs(to);
}
}
void tryAgain(){
int n,m;
cin>>n>>m;
for(int i=1;i<=n-1;i++){
int u,v;
cin>>u>>v;
g[u].pb(v);
g[v].pb(u);
}
int a[m+5],b[m+5];
for(int i=1;i<=m;i++){
cin>>a[i]>>b[i];
}
set<int>st;
int ans=INT_MAX,pos=0;
for(int ms=1;ms<(1<<n);ms++){
int cal=0;
for(int i=1;i<=n;i++){
used[i]=1e10;
int k=i-1;
if((1<<k) & ms){
used[i]=-1;
cal++;
}
}
timer=0;
for(int i=1;i<=n;i++){
if(used[i]==1e10){
++timer;
dfs(i);
}
}
bool ok=1;
for(int i=1;i<=m;i++){
if(used[b[i]]==-1 || used[a[i]]==-1) continue;
if(used[a[i]]==used[b[i]]){
ok=0;
break;
}
}
if(ans>=cal && ok==1){
ans=cal;
pos=ms;
}
}
for(int i=1;i<=n;i++){
int k=i-1;
used[i]=1e10;
if((1<<k) & pos){
used[i]=-1;
st.insert(i);
}
}
timer=0;
for(int i=1;i<=n;i++){
if(used[i]==1e10 && used[i]!=-1){
++timer;
dfs(i);
}
}
for(int i=1;i<=n;i++){
int ok=0;
for(int j=1;j<=m;j++){
if(a[i]==i && a[j]==i) {
ok=1;
break;
}
}
if(ok==1) continue;
for(auto to : g[i]){
if(used[to]!=-1) ok=1;
}
if(ok==0) st.erase(i);
}
// for(int i=1;i<=n;i++) cout<<used[i]<<' ';
cout<<st.sz()<<'\n';
for(auto to : st){
cout<<to<<' ';
}
}
signed main(){
YouCanDoGreatThings
// freopen("length.in", "r", stdin);
// freopen("length.out", "w", stdout);
int t = 1;
// cin >> t;
while(noSuccess){
tryAgain();
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
input:
200000 200000 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 ...
output:
result:
Subtask #2:
score: 0
Time Limit Exceeded
Test #8:
score: 0
Time Limit Exceeded
input:
200000 200000 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 ...
output:
result:
Subtask #3:
score: 0
Wrong Answer
Test #15:
score: 14
Accepted
time: 3ms
memory: 28104kb
input:
5 15 5 4 3 4 5 1 5 2 4 4 1 4 2 2 4 2 5 2 1 3 1 2 3 1 3 5 2 4 2 2 1 4 3 4 5 4 3 4
output:
2 2 4
result:
ok correct plan
Test #16:
score: 0
Wrong Answer
time: 10ms
memory: 27720kb
input:
15 15 3 7 12 15 4 11 12 14 8 3 9 13 10 12 3 2 5 6 8 13 5 10 1 8 11 2 15 1 5 5 13 13 9 13 14 12 9 9 6 5 6 6 13 13 5 6 15 1 9 13 10 10 15 1 10 10 13 9
output:
5 6 10 13 14 15
result:
wrong answer you deactivated 5 servers but jury deactivated 7 servers
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%