QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#283380 | #1359. Setting Maps | tomlusu | WA | 6ms | 3888kb | C++14 | 2.5kb | 2023-12-14 15:50:45 | 2023-12-14 15:50:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
int n, m, k, c[205];
struct Edge{
int v, nxt; long long w;
Edge(int x, int y, long long z){v = x, nxt = y, w = z;}
Edge(){}
};
struct MF{
Edge e[100005]; int head[2005], cnt = 0, S, T, dep[2005], nw[2005];
void addedge(int u, int v, long long w){
e[cnt] = Edge(v, head[u], w), head[u] = cnt++;
e[cnt] = Edge(u, head[v], 0), head[v] = cnt++;
}
bool bfs(){
for(int i = 1; i <= 2 * k * n; i++) dep[i] = 0;
queue<int> q; q.push(S), dep[S] = 1;
while(!q.empty()){
int x = q.front(); q.pop();
for(int i = head[x]; i != -1; i = e[i].nxt)
if(!dep[e[i].v] && e[i].w){
dep[e[i].v] = dep[x] + 1, q.push(e[i].v);
if(e[i].v == T) return true;
}
}
return false;
}
long long dfs(int x, long long flow){
if(x == T) return flow;
if(!flow) return 0;
long long lst = flow, ret;
for(int i = nw[x]; i != -1; i = e[i].nxt){
nw[x] = i;
if(e[i].w && (dep[e[i].v] == dep[x] + 1)){
ret = dfs(e[i].v, min(e[i].w, lst));
e[i].w -= ret, lst -= ret, e[i ^ 1].w += ret;
}
}
if(!lst) dep[x] = 0;
return flow - lst;
}
long long dinic(){
long long ans = 0;
while(bfs()){for(int i = 1; i <= 2 * n * k; i++) nw[i] = head[i]; ans = ans + dfs(S, inf);}
return ans;
}
MF(){memset(head, -1, sizeof(head));}
} M;
int in[205][6], ot[205][6];
long long cnt; bool vis[2005];
vector<int> ans;
void cal(){
queue<int> q; q.push(M.S), vis[M.S] = 1;
while(!q.empty()){
int k = q.front(); q.pop();
for(int i = M.head[k]; i != -1; i = M.e[i].nxt)
if(!vis[M.e[i].v] && M.e[i].w)
vis[M.e[i].v] = true, q.push(M.e[i].v);
}
}
int main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> m >> k >> M.S >> M.T;
for(int i = 1; i <= n; i++)
for(int j = 0; j < k; j++) in[i][j] = ++cnt, ot[i][j] = ++cnt;
for(int i = 1, x; i <= n; i++){
cin >> x;
for(int j = 0; j < k; j++) M.addedge(in[i][j], ot[i][j], x);
for(int j = 0; j < k - 1; j++)
for(int t = j + 1; t < k; t++) M.addedge(in[i][j], ot[i][t], 2e9);
}
for(int i = 1, u, v; i <= m; i++){
cin >> u >> v;
for(int j = 0; j < k; j++) M.addedge(ot[u][j], in[v][j], 2e9);
}
M.S = in[M.S][0], M.T = ot[M.T][k - 1], cnt = M.dinic();
if(cnt >= 2e9){cout << -1 << endl; return 0;}
cnt = 0; cal();
for(int i = 1; i <= n; i++)
for(int j = 0; j < k; j++)
if(M.dep[in[i][j]] && (!M.dep[ot[i][j]])) cnt++, ans.push_back(i);
cout << cnt << endl;
for(int i = 0; i < cnt; i++) cout << ans[i] << " ";
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3540kb
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: 0ms
memory: 3524kb
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: 0
Accepted
time: 0ms
memory: 3520kb
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:
6 5 6 7 8 9 10
result:
ok answer = 60
Test #4:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
2 2 2 2 1 100 200 1 2 2 1
output:
2 1 2
result:
ok answer = 300
Test #5:
score: 0
Accepted
time: 1ms
memory: 3600kb
input:
5 5 5 1 5 1 1 1 1 1 1 2 2 3 3 4 4 5 1 5
output:
-1
result:
ok answer = IMPOSSIBLE
Test #6:
score: 0
Accepted
time: 1ms
memory: 3676kb
input:
100 120 5 1 5 5367720 2854323 1799056 9744604 3215334 7580413 6269402 3208439 8812449 3297484 2047196 4044341 7514502 2928715 9335004 3935096 6660663 3356480 4801491 5786147 895995 6710240 222342 4469390 1543213 6678041 8838445 6741919 8138951 5273670 8983795 5131484 4245746 7460466 8357966 8464419 ...
output:
-1
result:
ok answer = IMPOSSIBLE
Test #7:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
2 1 5 1 2 10 10 1 2
output:
-1
result:
ok answer = IMPOSSIBLE
Test #8:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
154 304 2 67 7 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 100000...
output:
2 7 67
result:
ok answer = 20000000
Test #9:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
75 146 1 15 2 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 1000000...
output:
1 15
result:
ok answer = 10000000
Test #10:
score: 0
Accepted
time: 6ms
memory: 3672kb
input:
182 360 4 97 110 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 1000...
output:
-1
result:
ok answer = IMPOSSIBLE
Test #11:
score: 0
Accepted
time: 2ms
memory: 3728kb
input:
136 268 5 132 5 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000...
output:
-1
result:
ok answer = IMPOSSIBLE
Test #12:
score: -100
Wrong Answer
time: 2ms
memory: 3888kb
input:
200 396 3 174 124 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 100...
output:
-1
result:
wrong answer User answer is not optimal; judge: 2000000000, user: 2000000010