結果
| 問題 | No.3568 Range Restriction |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-07-22 14:31:33 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 158 ms / 2,000 ms |
| + 998µs | |
| コード長 | 3,024 bytes |
| 記録 | |
| コンパイル時間 | 2,501 ms |
| コンパイル使用メモリ | 364,388 KB |
| 実行使用メモリ | 34,560 KB |
| 最終ジャッジ日時 | 2026-07-22 14:31:47 |
| 合計ジャッジ時間 | 12,910 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
struct Constraint {
int x, y, z;
int64 v, low, high;
};
struct Event {
int64 threshold;
int constraintId;
int version;
bool operator>(const Event& other) const {
if (threshold != other.threshold) return threshold > other.threshold;
if (constraintId != other.constraintId) return constraintId > other.constraintId;
return version > other.version;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int testCount;
cin >> testCount;
while (testCount--) {
int n, m;
cin >> n >> m;
vector<Constraint> constraints(m);
for (Constraint& c : constraints) {
cin >> c.x >> c.y >> c.z >> c.v >> c.low >> c.high;
--c.x;
--c.y;
--c.z;
}
vector<int64> value(n, 0);
vector<int> version(m, 0);
vector<priority_queue<Event, vector<Event>, greater<Event>>> events(n);
vector<int> pending;
pending.reserve(m);
auto schedule = [&](int id) {
const Constraint& c = constraints[id];
int64 deficit = c.v - value[c.x] - value[c.y];
int64 increase = (deficit + 1) / 2;
events[c.x].push({value[c.x] + increase, id, version[id]});
events[c.y].push({value[c.y] + increase, id, version[id]});
};
for (int id = 0; id < m; ++id) {
if (constraints[id].v == 0) {
pending.push_back(id);
} else {
schedule(id);
}
}
while (!pending.empty()) {
int id = pending.back();
pending.pop_back();
const Constraint& c = constraints[id];
if (value[c.z] >= c.low) continue;
value[c.z] = c.low;
auto& heap = events[c.z];
while (!heap.empty() && heap.top().threshold <= value[c.z]) {
Event event = heap.top();
heap.pop();
if (event.version != version[event.constraintId]) continue;
int nextId = event.constraintId;
++version[nextId];
const Constraint& next = constraints[nextId];
if (value[next.x] + value[next.y] >= next.v) {
pending.push_back(nextId);
} else {
schedule(nextId);
}
}
}
bool possible = true;
for (const Constraint& c : constraints) {
if (value[c.x] + value[c.y] >= c.v &&
(value[c.z] < c.low || value[c.z] > c.high)) {
possible = false;
break;
}
}
if (!possible) {
cout << -1 << '\n';
} else {
for (int i = 0; i < n; ++i) {
if (i) cout << ' ';
cout << value[i];
}
cout << '\n';
}
}
return 0;
}