# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
208730 | E869120 | Senior Postmen (BOI14_postmen) | C++14 | 531 ms | 42080 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <set>
using namespace std;
#pragma warning (disable: 4996)
struct Node {
int to, cap, rev;
};
int N, M, A[1 << 19], B[1 << 19];
vector<Node> X[1 << 19]; int cur[1 << 19];
bool used[1 << 19];
int vec[1 << 19], sz;
int v1[1 << 19], sz1;
int main() {
scanf("%d%d", &N, &M);
for (int i = 1; i <= M; i++) {
scanf("%d%d", &A[i], &B[i]);
X[A[i]].push_back(Node{ B[i], 1, (int)X[B[i]].size() });
X[B[i]].push_back(Node{ A[i], 1, (int)X[A[i]].size() - 1 });
}
int num = M, cnt = 1;
while (num > 0) {
while (true) {
while (cur[cnt] < X[cnt].size() && X[cnt][cur[cnt]].cap == 0) cur[cnt]++;
if (cur[cnt] < X[cnt].size()) break;
cnt++;
}
int cx = cnt; sz = 0;
while (true) {
vec[sz] = cx; sz++;
int nex = -1, res = -1;
while (X[cx][cur[cx]].cap == 0) cur[cx]++;
nex = X[cx][cur[cx]].to;
res = X[cx][cur[cx]].rev;
X[cx][cur[cx]].cap = 0;
X[nex][res].cap = 0;
num--;
if (nex == cnt) break;
cx = nex;
}
vec[sz] = cnt; sz++;
for (int i = 0; i < sz; i++) used[vec[i]] = false;
sz1 = 0;
for (int i = 0; i < sz; i++) {
if (used[vec[i]] == true) {
int num = 0;
while (true) {
int cp = v1[sz1 - 1]; if (num) printf(" ");
printf("%d", cp); num++; used[cp] = false;
sz1--;
if (cp == vec[i]) break;
}
printf("\n");
}
used[vec[i]] = true;
v1[sz1] = vec[i]; sz1++;
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |