結果
| 問題 | No.3086 Re One Two |
| コンテスト | |
| ユーザー |
SnowBeenDiding
|
| 提出日時 | 2025-04-04 21:44:54 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 198 ms / 2,000 ms |
| コード長 | 1,292 bytes |
| 記録 | |
| コンパイル時間 | 6,523 ms |
| コンパイル使用メモリ | 333,148 KB |
| 実行使用メモリ | 28,092 KB |
| 最終ジャッジ日時 | 2025-04-04 21:45:22 |
| 合計ジャッジ時間 | 13,233 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#include <atcoder/all>
#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
using namespace atcoder;
using namespace std;
typedef long long ll;
void solve(int n, int m, vector<int> u, vector<int> v) {
map<int, int> ma;
vector<vector<int>> gr(n);
rep(i, 0, m) {
gr[u[i]].push_back(v[i]);
ma[v[i]]++;
}
priority_queue<int, vector<int>, greater<int>> pq;
rep(i, 0, n) {
if (ma[i] == 0)
pq.push(i);
}
vector<int> ans;
while (!pq.empty()) {
int x;
x = pq.top();
pq.pop();
ans.push_back(x);
for (auto y : gr[x]) {
ma[y]--;
if (ma[y] == 0) {
pq.push(y);
}
}
}
rep(i, 0, n) cout << ans[i] + 1 << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
int ind = -1;
vector<int> u, v;
rep(i, 0, n) {
int a, b;
cin >> a >> b;
if (a == 1) {
u.emplace_back(i + 1);
v.emplace_back(i);
}
if (b == 2)
ind = i;
if (b == 1) {
u.emplace_back(i);
v.emplace_back(ind);
}
}
int m = u.size();
solve(n, m, u, v);
}
SnowBeenDiding