QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#253357 | #3855. Regional development | oogerbooger | WA | 0ms | 3724kb | C++14 | 4.2kb | 2023-11-16 21:59:08 | 2023-11-16 21:59:09 |
Judging History
answer
#include <bits/stdc++.h>
#include <cassert>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define int long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define vvi vector<vi>
#define fi first
#define se second
#define ll long long
const int N = 1005;
const int R = 10005;
int root[N];
vector<pair<int,int>> adj[N], rev[N];
bool used[N];
int in[N], out[N];
int w[R], rw[R];
bool zrobione[R];
vi topo, component;
void dfs1(int v) {
used[v] = true;
for (auto u : adj[v]) {
if (!used[u.fi]) dfs1(u.fi);
}
topo.pb(v);
}
void dfs2(int v) {
used[v] = true;
component.pb(v);
for (auto u : rev[v]) {
if (!used[u.fi]) dfs2(u.fi);
}
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, r, m;
cin >> n >> r >> m;
for (int i = 0; i < r; i ++) {
int a, b, c;
cin >> a >> b >> c;
a--, b--;
adj[a].pb({b, i});
rev[b].pb({a, i});
in[b] += c;
out[a] += c;
w[i] = c;
rw[i] = -c;
}
for (int i = 0; i < n; i ++) {
if (!used[i]) {
dfs1(i);
}
}
fill(used, used + n, false);
reverse(all(topo));
for (auto u : topo) {
if (!used[u]) {
dfs2(u);
int Root = component.front();
for (auto v : component) root[v] = Root;
component.clear();
}
}
bool flag = true;
for (int i = 0; i < n; i ++) {
for (auto u : adj[i]) {
if (root[i] != root[u.fi]) {
flag = false;
break;
}
}
}
if (!flag) {
cout << "IMPOSSIBLE\n";
return 0;
}
fill(used, used + n, false);
for (int i = 0; i < n; i ++) {
if (in[i] == out[i]) {
continue;
}
if (in[i] > out[i]) {
for (auto edge : rev[i]) {
if (in[i] == out[i]) break;
int u = edge.fi;
int ind = edge.se;
//int c = w[ind];
if (zrobione[ind]) continue;
//w[ind] -= m;
out[u] -= m;
in[i] -= m;
rw[ind] += m;
zrobione[ind] = true;
}
} else {
for (auto edge : adj[i]) {
if (in[i] == out[i]) break;
int u = edge.fi;
int ind = edge.se;
// int c = w[ind];
if (zrobione[ind]) continue;
//w[ind] -= m;
out[i] -= m;
in[u] -= m;
w[ind] -= m;
zrobione[ind] = true;
}
}
}
for (int i = 0; i < n; i ++) {
if (in[i] != out[i]) {
flag = false;
}
}
if (!flag) {
cout << "IMPOSSIBLE\n";
return 0;
}
for (int i = 0; i < r; i ++) {
cout << w[i] << '\n';
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3724kb
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