QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#282124 | #1359. Setting Maps | JerryJohn | WA | 1ms | 3656kb | C++14 | 1.8kb | 2023-12-11 13:51:48 | 2023-12-11 13:51:49 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int inf = 0x3f3f3f3f3f3f3f3f,N = 1000,M = 10000;
int usv;
int bgn[N + 11],to[2 * M + 11],nxt[2 * M + 11],c[2 * M + 11],u[2 * M + 11],idx = 1;
inline void add(int x,int y,int w)
{
to[++idx] = y,u[idx] = 0,c[idx] = w,nxt[idx] = bgn[x],bgn[x] = idx;
to[++idx] = x,u[idx] = 0,c[idx] = 0,nxt[idx] = bgn[y],bgn[y] = idx;
}
int deep[N + 11],nbgn[N + 11];
int flow,S,T;
int q[N + 11],l,r;
inline bool BFS()
{
for(int i = 1;i <= usv;i++) deep[i] = 0,nbgn[i] = bgn[i];
deep[S] = 1;
q[l = 0] = S,r = 1;
while(l ^ r)
{
int p = q[l++];
for(int i = bgn[p];i;i = nxt[i]) if(c[i] ^ u[i])
{
int v = to[i];
if(!deep[v])
deep[v] = deep[p] + 1,q[r++] = v;
}
}
return deep[T];
}
int DFS(int p,int W)
{
if(!W || p == T) return W;
int res = 0;
for(int& i = nbgn[p];i;i = nxt[i]) if(deep[to[i]] == deep[p] + 1)
{
int x = DFS(to[i],min(W,c[i] - u[i]));
res += x,W -= x,u[i] += x,u[i ^ 1] -= x;
if(!W) break;
}
return res;
}
void Flow()
{
flow = 0;
for(int i = 2;i <= idx;i++) u[i] = 0;
while(BFS())
flow += DFS(S,inf);
}
int val[211];
int n,m,k,s,t;
long long ans;
set<int> res;
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin >> n >> m >> k;
cin >> s >> t;
S = s,T = t + n;
usv = 2 * n;
for(int i = 1;i <= n;i++)
{
cin >> val[i];
add(i,i + n,val[i]);
}
while(m--)
{
int x,y;
cin >> x >> y;
add(x + n,y,inf);
}
BFS();
if(deep[T] == 0)
{
cout << 0;
return 0;
}
if(deep[T] < (k << 1))
{
cout << -1;
return 0;
}
while(k--)
{
Flow();
ans += flow;
for(int i = 1;i <= n;i++) if(deep[i] && !deep[i + n])
c[i * 2] = inf,res.insert(i);
}
cout << res.size() << "\n";
for(auto i:res) cout << i << " ";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3368kb
input:
3 2 5 1 3 1 60 35 1 2 2 3
output:
-1
result:
ok answer = IMPOSSIBLE
Test #2:
score: 0
Accepted
time: 1ms
memory: 3640kb
input:
7 11 1 1 7 100 5 7 16 11 12 100 1 2 1 3 1 4 1 5 2 3 2 6 3 6 4 3 4 7 5 7 6 7
output:
4 2 3 4 5
result:
ok answer = 39
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3656kb
input:
11 17 2 1 11 1000 10 10 10 10 10 10 10 10 10 1000 1 2 1 3 1 4 1 5 1 6 2 7 3 7 4 7 5 8 6 8 7 8 7 9 7 10 8 9 8 11 9 11 10 11
output:
7 2 3 4 5 6 7 8
result:
wrong answer User answer is not optimal; judge: 60, user: 70