QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#320759 | #3855. Regional development | algotester# | WA | 0ms | 11428kb | C++14 | 3.9kb | 2024-02-03 21:06:23 | 2024-02-03 21:06:24 |
Judging History
answer
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:16777216")
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <bitset>
#include <random>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(A,value) memset(A,value,sizeof(A))
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
const double PI=acos(-1.0);
typedef long long Int;
typedef long long LL;
typedef unsigned long long UINT;
typedef vector <int> VI;
typedef pair <int, int> PII;
typedef pair <double, double> PDD;
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;
const int MAX = 200007;
const int MAXK = 51;
const int MAX2 = 24000000;
const int LEN = 21;
const int BASE = 1000000000;
struct edge
{
int x, y, id;
LL c, f;
};
vector<edge> E;
VI g[MAX];
int D[MAX];
int Q[MAX];
int Ptr[MAX];
int N; // number of vertices in the network (required)
void add_edge(int x, int y, LL c, int id)
{
// cout << x << ' ' << y << ' ' << c << endl;
edge e;
e. id = id;
e.x = x; e.y = y;
e.c = c; e.f = 0;
g[x].PB(SZ(E));
E.PB(e);
e.id = id;
e.x = y; e.y = x;
e.c = 0; e.f = 0;
g[y].PB(SZ(E));
E.PB(e);
}
int bfs(int s, int t)
{
FOR (i, 0, N)
D[i] = -1;
D[s] = 0;
Q[0] = s;
int qh = 0, qt = 1;
while(qh < qt && D[t] == -1)
{
int x = Q[qh++];
FOR (i, 0, SZ(g[x]))
{
int e = g[x][i];
if (E[e].f == E[e].c) continue;
int to = E[e].y;
if (D[to] == -1)
{
D[to] = D[x] + 1;
Q[qt++] = to;
}
}
}
return D[t];
}
LL dfs(int x, int t, LL flow)
{
if (x == t || flow == 0) return flow;
for (; Ptr[x] < SZ(g[x]); Ptr[x]++)
{
int e = g[x][Ptr[x]];
LL c = E[e].c;
LL f = E[e].f;
int to = E[e].y;
if (c == f) continue;
if (D[to] == D[x] + 1)
{
LL push = dfs(to, t, min(flow, c - f));
if (push > 0)
{
E[e].f += push;
E[e^1].f -= push;
return push;
}
}
}
return 0;
}
LL Flow(int s, int t)
{
LL res = 0;
while(bfs(s, t) != -1)
{
FOR (i, 0, N)
{
Ptr[i] = 0;
}
while(true)
{
LL push = dfs(s, t, LINF);
if (push == 0) break;
res += push;
}
}
return res;
}
int n, m, k;
vector<pair<PII, int> > W;
int X[MAX];
int Res[MAX];
int main()
{
cin >> n >> m >> k;
FOR (i,0,m)
{
int u, v, x;
scanf("%d %d %d", &u, &v, &x);
-- u;
-- v;
W.PB(MP(MP(u, v), x));
X[u] -= x;
X[v] += x;
}
FOR (i,0,SZ(W))
{
int u = W[i].first.first;
int v = W[i].first.second;
int x = W[i].second;
if (X[u] > 0 && X[v] <= 0)
{
add_edge(n+u, v, 1, i);
}
else
if (X[u] <= 0 && X[v] > 0)
{
add_edge(u, n+v, 1, i);
}
Res[i] = x;
}
N = 2*n+2;
int s = N-2, t = N-1;
int sum = 0;
FOR (i,0,n)
if (X[i] < 0)
{
add_edge(s, i, -X[i]/k, -1);
sum += -X[i]/k;
}
FOR (i,0,n)
if (X[i] > 0)
add_edge(n+i, t, X[i]/k, -1);
int x = Flow(s, t);
if (x != sum)
{
cout << "IMPOSSIBLE" << endl;
return 0;
}
FOR (i,0,N)
FOR (j,0,SZ(g[i]))
{
edge e = E[g[i][j]];
if (e.f > 0 && e.id != -1)
{
Res[e.id] = -(k-Res[e.id]);
}
}
FOR (i,0,m)
printf("%d\n", Res[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 11428kb
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:
IMPOSSIBLE
result:
wrong output format Expected integer, but "IMPOSSIBLE" found