QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#486312#1359. Setting MapsYansuan_HClRE 1ms4188kbC++143.7kb2024-07-21 18:47:072024-07-21 18:47:09

Judging History

你现在查看的是最新测评结果

  • [2024-07-21 18:47:09]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:4188kb
  • [2024-07-21 18:47:07]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define U(i,l,r) for (int i(l),END##i(r); i<=END##i; ++i)
#define D(i,l,r) for (int i(l),END##i(r); i>=END##i; --i)
#define ms(x, v) memset(x, v, sizeof(x))
#define il __attribute__((always_inline))
#define vc vector
#define ar array
#define pb push_back
#define eb emplace_back
#define el '\n'
using ll = long long;

#define int ll
const int INF = 0x3f3f3f3f3f3f3f3f;
namespace dinic {
	const int N = 2405, M = N * 8;
  struct edge { int v, f, pre; } e[M]; int tail[N], ptr = 1;
  void single(int u, int v, int f) {
    e[++ptr] = {v, f, tail[u]};
    tail[u] = ptr;
  }
  void add(int u, int v, int f) {
    single(u, v, f);
    single(v, u, 0);
		// clog << u << ' ' << v << ' ' << (f == INF ? 999 : f) << endl;
  }
  int layer[N], que[N];
  bool bfs(int s, int t) {
    ms(layer, 0); int l = 0, r = 1; que[0] = s; layer[s] = 1;
    while (l < r) {
      int u = que[l++];
      for (int p = tail[u]; p; p = e[p].pre) {
        auto [v, f, _] = e[p];
        if (!layer[v] && f)
          layer[que[r++] = v] = layer[u] + 1;
      }
    }
    return layer[t];
  }
  int dfs(int u, int in, int t) {
    if (u == t || !in) return in;
    int out = 0;
    for (int &p = tail[u]; p; p = e[p].pre) {
      auto &[v, f, _] = e[p];
      if (!f || layer[v] != layer[u] + 1) continue;
      
      int c = dfs(v, min(f, in), t);
      f -= c; e[p ^ 1].f += c;
      in -= c; out += c;
      if (!in) break;
    }
    return out;
  }
  int flow(int s, int t) {
    int orig[N], res = 0;
    while (bfs(s, t)) {
      memcpy(orig, tail, sizeof(tail));
      int cur = dfs(s, INF, t);
      res += cur;
      // clog << cur << endl;
      memcpy(tail, orig, sizeof(tail));
    }
    return res;
  }
}
#define de dinic::

const int N = 200;
int n, m, k, a, b, c[N]; vc<int> g[N], rg[N];

void bfs(int s, bool *vis, const auto &f) {
	queue<int> q; q.push(s); vis[s] = 1;
	while (q.size()) {
		int u = q.front(); q.pop();
		for (int v : f[u]) if (!vis[v]) {
			vis[v] = 1;
			q.push(v);
		}
	}
}
bool via[N], vib[N];

signed main() {
	// freopen("ava2.in", "r", stdin);
	// freopen(".out", "w", stdout);
	ios::sync_with_stdio(0);

	cin >> n >> m >> k >> a >> b; 
	U (i, 1, n) cin >> c[i];
	pair<int, int> eg[505] {};
	U (i, 1, m) {
		auto &[u, v] = eg[i]; cin >> u >> v;
		g[u].pb(v); rg[v].pb(u);
	}
	bfs(a, via, g);
	bfs(b, vib, rg);
	if (!vib[a]) { cout << -1 << el; exit(0); }

	int s = de N - 1, t = de N - 2;
	#define ot n+
	#define val(x) (via[x] && vib[x])
	int pt[N * 2][6] {};
	U (i, 1, n * 2) U (j, 0, k) pt[i][j] = n * 2 * j + i;
	U (i, 1, n * 2) if (val((i - 1) % n + 1)) {
		de add(s, pt[i][0], INF);
		U (j, 0, k) {
			int f = (j ? pt[i][j - 1] : s);
			de add(pt[i][j], f, INF);
		}
		de add(t, pt[i][k], INF);
	}
	U (j, 1, k)
		de add(pt[a][j], (j == k ? t : pt[a][j + 1]), INF);
	U (j, 1, k)
		de add(pt[ot b][j - 1], pt[ot b][j], INF);

	int mark[de M] {};
	U (i, 1, n) if (val(i)) {
		U (j, 0, k) {
			de add(pt[i][j], pt[ot i][j], INF);
			de add(pt[ot i][j], pt[i][j], c[i]);
			mark[de ptr - 1] = mark[de ptr] = i;
		}
		U (j, 1, k)
			de add(pt[ot i][j], pt[i][j - 1], INF);
	}
	U (i, 1, m) {
		auto [u, v] = eg[i];
		if (!val(u) || !val(v)) continue;

		U (j, 0, k) {
			de add(pt[v][j], pt[ot u][j], INF);
		}
	}

	int f = de flow(s, t);
	clog << "#" << f << endl;
	if (f > 2e9) { cout << -1 << el; exit(0); }
	
	vc<int> ans;
	U (i, 1, de N - 1) for (int p = de tail[i]; p; p = de e[p].pre) if (mark[p]) {
		int v = de e[p].v;
		if (de layer[i] && !de layer[v])  {
			ans.pb(mark[p]);
		}
	}
	// clog << "fin" << endl;

	cout << ans.size() << el;
	for (int u : ans) cout << u << ' ';
	cout << el;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3896kb

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: 3836kb

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:

3
4 5 6 

result:

ok answer = 39

Test #3:

score: 0
Accepted
time: 0ms
memory: 3844kb

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: 3824kb

input:

2 2 2
2 1
100 200
1 2
2 1

output:

2
2 1 

result:

ok answer = 300

Test #5:

score: 0
Accepted
time: 1ms
memory: 4068kb

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: 4028kb

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: 1ms
memory: 3832kb

input:

2 1 5
1 2
10 10
1 2

output:

-1

result:

ok answer = IMPOSSIBLE

Test #8:

score: 0
Accepted
time: 1ms
memory: 4116kb

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
67 7 

result:

ok answer = 20000000

Test #9:

score: 0
Accepted
time: 1ms
memory: 3968kb

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
2 

result:

ok answer = 10000000

Test #10:

score: 0
Accepted
time: 1ms
memory: 4188kb

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: 1ms
memory: 4148kb

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
Runtime Error

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:


result: