QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#866597#3855. Regional developmentFislettRE 0ms5708kbC++203.2kb2025-01-22 16:28:162025-01-22 16:28:21

Judging History

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

  • [2025-01-22 16:28:21]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:5708kb
  • [2025-01-22 16:28:16]
  • 提交

answer

#include <bits/stdc++.h>
#define N 1005
#define inf 0x3f3f3f3f
#define ll long long 
#define ull unsigned long long 
static char buf[1048576], *P1 = buf, *P2 = buf, obuf[1048576], *P3 = obuf;
#define getchar() P1 == P2 && (P2 = (P1 = buf) + fread(buf, 1, 1048576, stdin), P1 == P2) ? EOF : *P1 ++
#define putchar(c) (P3 - obuf < 1048576) ? (*P3 ++ = c) : (fwrite(obuf, 1048576, 1, stdout), P3 = obuf, *P3 ++ = c)
#define flush() fwrite(obuf, P3 - obuf, 1, stdout)
#define file(s) freopen(#s".in", "r", stdin), freopen(#s".out", "w", stdout)
using namespace std;
inline void read(char &c) {while ((c = getchar()) <= 32);}
inline void read(char *s) {while ((*s = getchar()) <= 32) ; ++ s; while ((*s = getchar()) > 32) ++ s; *s = 0;}
inline void read(string &s) {s.clear(); char c; while ((c = getchar()) <= 32) ; s.push_back(c); while ((c = getchar()) > 32) s.push_back(c);}
template <typename T>
inline void read(T &x)
{
    x = 0; short flag = 1, ch = getchar();
    for (; ch < '0' || ch > '9'; ch = getchar()) flag = (ch ^ '-' ? 1 : -1);
    for (; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48);
    x *= flag;
}
template<typename T, typename... More>
inline void read(T &x, More&... more) {read(x), read(more...);}
inline void print(const char s[]) {while (*s) putchar(*s ++);}
inline void print(char *s) {while (*s) putchar(*s ++);}
inline void print(const string s) {for (const char ch : s) putchar(ch);}
inline void print(const char c) {putchar(c);}
template<typename T>
inline void print(T x)
{
    if (x < 0) putchar('-'), x = ~(x - 1);
    if (x > 9) print(x / 10);
    putchar(x % 10 + 48);
}
template<typename T, typename... More>
inline void print(T x, More... more) {print(x), print(more...);}
template <typename T> inline void ckmin(T &x, T y) {(y < x) && (x = y);}
template <typename T> inline void ckmax(T &x, T y) {(y > x) && (x = y);}
struct {int to, w, next;} e[22005];
int n, m, k, S, T, tot = 1, head[N], d[N], now[N], val[N], ed[N], q[N];
inline void add(int u, int v, int w) {e[++ tot] = {v, w, head[u]}, head[u] = tot, e[++ tot] = {u, 0, head[v]}, head[v] = tot;}
inline bool bfs()
{
    memset(d, 0x00, T + 1 << 2), memcpy(now, head, T + 1 << 2), d[S] = 1, q[1] = S;
    for (int h = 1, t = 1, u, i, v; h <= t; ++ h)
    {
        u = q[h];
        for (i = head[u]; i; i = e[i].next)
            if (e[i].w && !d[v = e[i].to]) q[++ t] = v, d[v] = d[u] + 1;
    }
    return d[T];
}
inline int dinic(int u, int flow)
{
    if (u == T) return flow; int res = 0;
    for (int v, k; now[u] && flow; now[u] = e[now[u]].next)
        if (e[now[u]].w && d[v = e[now[u]].to] == d[u] + 1) (k = dinic(v, min(flow, e[now[u]].w))) ? e[now[u]].w -= k, e[now[u] ^ 1].w += k, flow -= k, res += k : d[v] = -1;
    return res;
}
signed main()
{
    read(n, m, k), T = n + 1;
    for (int i = 1, u, v, w; i <= m; ++ i) read(u, v, w), val[v] += w, val[u] -= w, add(v, u, 1), ed[i] = w;
    for (int i = 1; i <= n; ++ i)
    {
        val[i] /= k;
        if (val[i] > 0) add(S, i, val[i]);
        else add(i, T, -val[i]);
    }
    while (bfs()) while (dinic(S, inf));
    for (int i = 1; i <= m; ++ i) assert(ed[i] % k), print(ed[i] - e[i << 1 | 1].w * k, '\n');
    return flush(), 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5708kb

input:

10 23 3
2 10 1
2 6 1
6 9 1
7 9 1
6 7 1
3 6 1
1 3 1
1 6 2
6 10 1
2 9 1
4 9 2
4 7 2
3 10 2
3 9 1
6 8 1
7 8 2
3 5 1
5 9 1
8 9 2
3 8 2
1 5 2
1 4 1
5 10 2

output:

-2
1
1
1
1
1
-2
2
1
1
-1
2
-1
-2
1
2
1
-2
2
-1
-1
1
2

result:

ok correct plan

Test #2:

score: -100
Runtime Error

input:

100 1297 11
27 34 5
7 34 6
7 90 3
80 90 6
37 80 6
37 48 5
47 48 6
47 86 5
56 86 6
56 84 5
63 84 6
38 63 6
66 91 8
12 91 6
12 15 5
15 22 1
22 87 5
46 87 6
46 63 10
63 87 8
71 87 6
65 71 6
38 65 1
38 67 4
29 67 6
9 29 6
9 21 5
16 21 6
16 89 2
89 98 5
4 98 6
4 13 4
13 33 5
14 33 6
14 66 10
66 86 10
57 ...

output:


result: