#include "friend.h"
#include<bits/stdc++.h>
using namespace std;
struct edge{
int bg;
int en;
int flow;
edge (int bg, int en, int flow){
this -> bg = bg;
this -> en = en;
this -> flow = flow;
}
};
int answer = 0;
vector<int> adj[1005];
int dp_get[1005], dp_didnt_get[1005];
int side[1005];
vector<edge> edges;
vector<pair<int, int> > adj1[1005];
pair<int, int> parent[1005];
bool used[1005];
void dp (int current, int parent, int confidence[]) {
dp_get[current] = confidence[current];
bool leaf = 1;
for (int x : adj[current]) {
if (x == parent) continue;
leaf = 0;
dp(x, current, confidence);
}
if (leaf) return;
for (int x : adj[current]) {
if (x == parent) continue;
dp_get[current] += dp_didnt_get[x];
dp_didnt_get[current] += max(dp_didnt_get[x], dp_get[x]);
}
}
void make_edge(int bg, int en) {
edges.push_back(edge(bg, en, 1));
adj1[bg].push_back(make_pair(en, edges.size() - 1));
adj1[en].push_back(make_pair(bg, edges.size() - 1));
}
int found_path(int nn) {
queue <int> q;
memset(used, 0, sizeof used);
q.push(nn);
parent[nn] = make_pair(-1, -1);
used[nn] = 1;
while (!q.empty()) {
int current = q.front();
q.pop();
for (pair<int, int> x : adj1[current]) {
if (used[x.first]) continue;
if (edges[x.second].bg == current && edges[x.second].flow == 1) {
used[x.first] = 1;
parent[x.first] = make_pair(current, x.second);
q.push(x.first);
}
if (edges[x.second].en == current && edges[x.second].flow == 0) {
used[x.first] = 1;
parent[x.first] = make_pair(current, x.second);
q.push(x.first);
}
}
}
return used[nn + 1];
}
int findSample(int n, int confidence[],int host[],int protocol[]){
for (int i = 1; i < n; i++) {
if (protocol[i] == 1 || protocol[i] == 2) {
for (int x : adj[host[i]]) {
adj[x].push_back(i);
adj[i].push_back(x);
}
}
if (protocol[i] == 0 || protocol[i] == 2) {
adj[i].push_back(host[i]);
adj[host[i]].push_back(i);
}
}
if (n <= 10) {
for (int i = 0; i < (1<<n); i++) {
vector<int> group;
bool found_connectedness = 0;
for (int j = 0; j < n; j++) {
if (i & (1<<j)) group.push_back(j);
}
for (int i : group) {
for (int j : group) {
for (int x : adj[i]) if ( x == j) found_connectedness = 1;
}
}
if (found_connectedness == 1) continue;
int sum = 0;
for (int x : group) sum += confidence[x];
answer = max(answer, sum);
}
return answer;
}
bool all0 = 1, all1 = 1, all2 = 1;
for (int i = 1; i < n; i++) {
if (protocol[i] == 0) {
all1 = 0;
all2 = 0;
}
if (protocol[i] == 1) {
all0 = 0;
all2 = 0;
}
if (protocol[i] == 2) {
all0 = 0;
all1 = 0;
}
}
if (all1 == 1) {
int sum = 0;
for (int i = 0; i < n; i++) sum += confidence[i];
return sum;
}
if (all2 == 1) {
int ma = 0;
for (int i = 0; i < n; i++) ma = max(ma, confidence[i]);
return ma;
}
if (all0 == 1) {
dp(0, -1, confidence);
return max(dp_get[0], dp_didnt_get[0]);
}
side[0] = 0;
for (int i = 1; i < n; i++) {
if (protocol[i] == 0) side[i] = 1 - side[host[i]];
if (protocol[i] == 1) side[i] = side[host[i]];
}
for (int i = 0; i < n; i++) {
if (side[i] == 1) continue;
for (int x : adj[i]) make_edge(i, x);
}
for (int i = 0; i < n; i++) {
if (side[i] == 0) make_edge(n, i);
if (side[i] == 1) make_edge(i, n + 1);
}
int maximum_matching = 0;
while (found_path(n)) {
maximum_matching++;
for (int i = n; parent[i].first != -1; i = parent[i].first) {
edges[parent[i].second].flow ^= 1;
}
}
return (n - maximum_matching);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1280 KB |
Output is correct |
2 |
Correct |
11 ms |
4224 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
7 ms |
3072 KB |
Output is correct |
5 |
Correct |
13 ms |
4224 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
1024 KB |
Output is correct |
8 |
Correct |
5 ms |
1152 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
12 ms |
4480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
512 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Execution timed out |
1072 ms |
512 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Runtime error |
34 ms |
3932 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
13 |
Halted |
0 ms |
0 KB |
- |