# | 제출 시각UTC-0 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
575877 | eecs | Naboj (COCI22_naboj) | C++17 | 799 ms | 61048 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int n, m, c0[maxn], c1[maxn];
bool vis[maxn];
set<pair<int, int>> G[maxn];
vector<array<int, 2>> res;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> m;
while (m--) {
int u, v;
cin >> u >> v;
G[u].emplace(v, 1), G[v].emplace(u, 0);
c0[u]++, c1[v]++;
}
queue<int> Q;
for (int i = 1; i <= n; i++) {
if (!c0[i] || !c1[i]) Q.push(i);
}
while (!Q.empty()) {
int x = Q.front(); Q.pop();
if (vis[x]) continue;
res.push_back({x, c0[x] ? 1 : 0}), vis[x] = 1;
for (auto &e : G[x]) if (!vis[e.first]) {
(e.second ? c1[e.first] : c0[e.first])--;
G[e.first].erase({x, !e.second});
if (!c0[e.first] || !c1[e.first]) Q.push(e.first);
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |