# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
105818 |
2019-04-15T07:23:19 Z |
TuGSGeReL |
Friend (IOI14_friend) |
C++14 |
|
5 ms |
3840 KB |
#include "friend.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define mp make_pair
#define pub push_back
#define pob pop_back()
#define ss second
#define ff first
#define mt make_tuple
#define pof pop_front()
#define fbo find_by_order
#define ook order_of_key
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
using pll = pair <ll, ll>;
using pii = pair <int, int>;
int used[2001], pre[3], dp[2001][2], idx, par[2001], fl[2001][2001];
vector <int> edg[2001];
pair<int, int> p[1001];
int solve1(int n, int confidence[], int host[], int protocol[])
{
int ans = 0;
for (int i = 1; i < n; i++)
{
if ( !protocol[i] )
{
edg[i].pub(host[i]);
edg[host[i]].pub(i);
} else if ( protocol[i] == 1 )
{
for (int j = 0; j < edg[host[i]].size(); j++)
{
edg[edg[host[i]][j]].pub(i);
edg[i].pub(edg[host[i]][j]);
}
} else {
for (int j = 0; j < edg[host[i]].size(); j++)
{
edg[i].pub(edg[host[i]][j]);
edg[edg[host[i]][j]].pub(i);
}
edg[i].pub(host[i]);
edg[host[i]].pub(i);
}
}
for (int i = 0; i < (1 << n); i++)
{
memset(used, 0, sizeof used);
bool boo = 0;
int res = 0;
for (int j = 0; j < n; j++)
{
if ( i & (1 << j) )
{
for ( auto x : edg[j] )
if ( used[x] )
boo = 1;
res += confidence[j];
used[j] = 1;
}
}
if ( !boo )
ans = max(ans, res);
}
return ans;
}
void dfs(int u, int pra)
{
bool boo = 1;
for (auto x : edg[u])
if ( x != pra )
dfs(x, u), boo = 0;
if ( pra != -1 )
{
dp[pra][0] += max(dp[u][1], dp[u][0]);
dp[pra][1] += dp[u][0];
}
}
bool bfs(int u)
{
memset(used, 0, sizeof used);
used[u] = 1;
par[u] = -1;
queue<int>q;
q.push(u);
while (!q.empty())
{
u = q.front();
q.pop();
for (int i = 0; i <= idx + 1; i++)
{
if ( fl[u][i] && !used[i] )
{
used[i] = 1;
par[i] = u;
q.push(i);
}
}
}
if ( used[idx + 1] )
return 1;
return 0;
}
int findSample(int n,int confidence[],int host[],int protocol[])
{
// if ( n <= 10 )
// return solve1(n, confidence, host, protocol);
//
// for (int i = 1; i < n; i++)
// pre[protocol[i]]++;
//
// if ( pre[1] == n - 1 )
// {
// int ans = 0;
//
// for (int i = 0; i < n; i++)
// ans += confidence[i];
//
// return ans;
// }
//
// if ( pre[2] == n - 1 )
// {
// int ans = 0;
//
// for (int i = 0; i < n; i++)
// ans = max(ans, confidence[i]);
//
// return ans;
// }
//
// if ( pre[0] == n - 1 )
// {
// for (int i = 1; i < n; i++)
// {
// edg[host[i]].pub(i);
// edg[i].pub(host[i]);
// }
//
// for (int i = 0; i < n; i++)
// dp[i][1] = confidence[i];
//
// dfs(0, -1);
//
// return max(dp[0][0], dp[0][1]);
// }
p[0].ss = 0;
for (int i = 1; i < n - 1; i++)
{
p[i].ff = ++idx;
p[i].ss = ++idx;
fl[p[i].ff][p[i].ss] = 1;
}
p[n - 1].ff = ++idx;
for (int i = 1; i < n; i++)
{
if ( !protocol[i] )
{
edg[i].pub(host[i]);
edg[host[i]].pub(i);
fl[p[host[i]].ss][p[i].ff] = 1;
} else {
for (auto x : edg[host[i]])
{
fl[p[x].ss][p[i].ff] = 1;
edg[x].pub(i);
edg[i].pub(x);
}
}
}
for (int i = 1; i < n; i++)
{
fl[p[i].ss][idx + 1] = 1;
}
int ans = 0;
while (bfs(0))
{
int mn = 1e9;
for (int i = idx + 1; par[i] != -1; i = par[i])
mn = min(mn, fl[par[i]][i]);
for (int i = idx + 1; par[i] != -1; i = par[i])
fl[par[i]][i] -= mn, fl[i][par[i]] += mn;
ans += mn;
}
return ans;
}
Compilation message
friend.cpp: In function 'int solve1(int, int*, int*, int*)':
friend.cpp:40:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < edg[host[i]].size(); j++)
~~^~~~~~~~~~~~~~~~~~~~~
friend.cpp:47:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < edg[host[i]].size(); j++)
~~^~~~~~~~~~~~~~~~~~~~~
friend.cpp: In function 'void dfs(int, int)':
friend.cpp:86:7: warning: variable 'boo' set but not used [-Wunused-but-set-variable]
bool boo = 1;
^~~
friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:214:6: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for (int i = idx + 1; par[i] != -1; i = par[i])
^~~
friend.cpp:217:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
ans += mn;
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
1920 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
3840 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |