QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#351424 | #4513. Slide Parade | SampsonYW | 0 | 0ms | 0kb | C++14 | 2.1kb | 2024-03-11 21:59:21 | 2024-03-11 21:59:23 |
answer
#include <bits/stdc++.h>
#define db double
#define re register
#define il inline
#define ll long long
#define ull unsigned ll
#define i128 __int128
#define pii pair<int, int>
#define fi first
#define se second
#define eb emplace_back
#define SZ(v) (int)v.size()
#define ALL(v) v.begin(), v.end()
#define mems(v, x) memset(v, x, sizeof(v))
#define FOR(i, L, R) for(re int i = (L); i <= (R); ++i)
#define ROF(i, R, L) for(re int i = (R); i >= (L); --i)
#define LS i << 1, l, mid
#define RS i << 1 | 1, mid + 1, r
using namespace std;
#define N 400005
#define M 5000005
int n, m, u[M], v[M], mt[N];
vector<int> e[N]; bool vis[N];
il bool dfs(int x) {
for(auto y : e[x]) if(!vis[y]) {
vis[y] = 1; if(!mt[y] || dfs(mt[y])) return mt[y] = x, mt[x] = y, 1;
}
return 0;
}
namespace euler {
vector<int> e[N], ns;
il void add(int x, int y) {e[x].eb(y);}
il void clr() {FOR(i, 1, n) vector<int>().swap(e[i]);}
il void dfs(int x) {
while(!e[x].empty()) {
int y = e[x].back(); e[x].pop_back(); dfs(y);
}
ns.eb(x);
}
il void solve() {
vector<int>().swap(ns);
dfs(1), reverse(ALL(ns));
cout << SZ(ns) << "\n";
for(auto x : ns) cout << x << " ";
cout << "\n";
}
}
il void WORK(int TC) {
cout << "Case #" << TC << ": ";
cin >> n >> m;
FOR(i, 1, n * 2)
vector<int>().swap(e[i]), mt[i] = 0;
FOR(i, 1, m) cin >> u[i] >> v[i], e[u[i]].eb(v[i] + n);
FOR(i, 1, n) {
mems(vis, 0);
if(!dfs(i)) {cout << "IMPOSSIBLE\n"; return ;}
}
// cerr << "ok\n";
// FOR(i, 1, n) cerr << i << " " << mt[i] << "\n";
euler::clr();
FOR(i, 1, m) {
int x = u[i], y = v[i] + n;
if(mt[x] != y) {
int p = mt[y];
mems(vis, 0), vis[y] = 1;
mt[mt[x]] = mt[p] = 0;
mt[x] = y, mt[y] = x;
dfs(p);
}
FOR(u, 1, n) euler::add(u, mt[u] - n);
}
// cerr << "ok\n";
euler::solve();
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T, TC = 0; cin >> T;
while(T--) WORK(++TC);
cerr << 1.0 * clock() / CLOCKS_PER_SEC;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
100 5 8 1 2 1 3 1 4 1 5 2 1 3 1 4 1 5 1 5 10 1 3 1 4 2 3 2 5 3 1 3 4 3 5 4 2 5 1 5 3 5 10 1 4 2 3 2 5 3 1 3 5 4 2 4 3 4 5 5 1 5 2 3 6 1 2 1 3 2 1 2 3 3 1 3 2 5 10 1 2 1 5 2 3 2 4 3 1 4 3 4 5 5 2 5 3 5 4 4 10 1 2 1 3 1 4 2 1 2 3 2 4 3 1 3 4 4 2 4 3 5 10 1 2 1 3 2 1 2 4 3 1 3 5 4 2 4 5 5 3 5 4 5 10 1 ...
output:
result:
Test #2:
score: 0
Runtime Error
input:
100 199 4980 1 95 1 96 1 105 1 124 1 130 1 131 1 135 1 137 1 139 1 140 1 141 1 147 1 155 1 172 1 174 1 179 1 183 1 188 1 193 1 196 1 197 2 3 2 5 2 13 2 14 2 17 2 20 2 24 2 26 2 30 2 41 2 44 2 45 2 52 2 56 2 67 2 70 2 71 2 74 2 78 2 84 2 85 2 90 2 92 2 93 2 97 2 107 2 111 2 113 2 122 2 124 2 128 2 13...