QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#531800 | #2341. Dead-End Detector | Swarthmore# | AC ✓ | 637ms | 110300kb | C++20 | 2.4kb | 2024-08-24 22:20:21 | 2024-08-24 22:20:21 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define F0Rd(i, a) for (int i = (a) - 1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define sz(x) (int)(x).size()
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
const char nl = '\n';
void solve() {
int N, M; cin >> N >> M;
vector<set<int>> graph(N);
F0R(i, M) {
int X, Y; cin >> X >> Y;
X--; Y--;
graph[X].ins(Y); graph[Y].ins(X);
}
bool vis[N]; F0R(i, N) vis[i] = false;
vpi ans;
vpi atEntr[N];
F0R(r, N) {
if (vis[r]) continue;
vis[r] = true;
vi comp;
int edCount;
queue<int> q; q.push(r);
while (!q.empty()) {
int v = q.front(); q.pop();
comp.pb(v);
trav(a, graph[v]) {
if (vis[a]) continue;
vis[a] = true;
q.push(a);
}
}
edCount = 0;
trav(a, comp) edCount += sz(graph[a]);
edCount /= 2;
vpi leafEds;
trav(a, comp) {
if (sz(graph[a]) == 1) {
leafEds.pb({a, *graph[a].begin()});
q.push(a);
}
}
if (edCount == sz(comp) - 1) {
trav(a, leafEds) ans.pb(a);
continue;
}
while (!q.empty()) {
int v = q.front(); q.pop();
trav(a, graph[v]) {
graph[a].erase(v);
atEntr[a].pb({a, v});
if (sz(graph[a]) == 1) {
q.push(a);
}
}
}
trav(a, comp) {
if (sz(graph[a]) >= 2) {
trav(b, atEntr[a]) {
ans.pb(b);
}
}
}
}
sort(all(ans));
ans.resize(unique(all(ans)) - ans.begin());
cout << sz(ans) << nl;
trav(a, ans) {
cout << a.f+1 << " " << a.s+1 << nl;
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
solve();
return 0;
}
Details
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 3612kb
Test #3:
score: 0
Accepted
time: 189ms
memory: 87708kb
Test #4:
score: 0
Accepted
time: 0ms
memory: 3544kb
Test #5:
score: 0
Accepted
time: 0ms
memory: 3556kb
Test #6:
score: 0
Accepted
time: 0ms
memory: 3524kb
Test #7:
score: 0
Accepted
time: 0ms
memory: 3548kb
Test #8:
score: 0
Accepted
time: 27ms
memory: 38864kb
Test #9:
score: 0
Accepted
time: 0ms
memory: 3548kb
Test #10:
score: 0
Accepted
time: 0ms
memory: 3788kb
Test #11:
score: 0
Accepted
time: 0ms
memory: 3524kb
Test #12:
score: 0
Accepted
time: 0ms
memory: 3756kb
Test #13:
score: 0
Accepted
time: 195ms
memory: 50536kb
Test #14:
score: 0
Accepted
time: 546ms
memory: 50524kb
Test #15:
score: 0
Accepted
time: 322ms
memory: 93560kb
Test #16:
score: 0
Accepted
time: 531ms
memory: 100792kb
Test #17:
score: 0
Accepted
time: 632ms
memory: 110300kb
Test #18:
score: 0
Accepted
time: 637ms
memory: 106776kb
Test #19:
score: 0
Accepted
time: 0ms
memory: 3824kb
Test #20:
score: 0
Accepted
time: 0ms
memory: 3644kb
Test #21:
score: 0
Accepted
time: 0ms
memory: 3988kb
Test #22:
score: 0
Accepted
time: 134ms
memory: 35156kb
Test #23:
score: 0
Accepted
time: 309ms
memory: 87764kb
Test #24:
score: 0
Accepted
time: 96ms
memory: 87848kb
Test #25:
score: 0
Accepted
time: 334ms
memory: 87828kb
Test #26:
score: 0
Accepted
time: 85ms
memory: 87696kb
Test #27:
score: 0
Accepted
time: 285ms
memory: 87688kb
Test #28:
score: 0
Accepted
time: 281ms
memory: 87708kb
Test #29:
score: 0
Accepted
time: 287ms
memory: 87724kb
Test #30:
score: 0
Accepted
time: 114ms
memory: 67344kb
Test #31:
score: 0
Accepted
time: 225ms
memory: 67752kb
Test #32:
score: 0
Accepted
time: 243ms
memory: 100404kb
Test #33:
score: 0
Accepted
time: 498ms
memory: 101284kb
Test #34:
score: 0
Accepted
time: 484ms
memory: 87704kb
Test #35:
score: 0
Accepted
time: 342ms
memory: 93648kb
Test #36:
score: 0
Accepted
time: 291ms
memory: 92680kb
Test #37:
score: 0
Accepted
time: 327ms
memory: 92428kb
Test #38:
score: 0
Accepted
time: 314ms
memory: 87636kb
Test #39:
score: 0
Accepted
time: 331ms
memory: 81524kb
Test #40:
score: 0
Accepted
time: 449ms
memory: 91040kb
Test #41:
score: 0
Accepted
time: 582ms
memory: 92092kb
Test #42:
score: 0
Accepted
time: 368ms
memory: 86940kb
Test #43:
score: 0
Accepted
time: 388ms
memory: 86932kb
Test #44:
score: 0
Accepted
time: 612ms
memory: 104296kb
Test #45:
score: 0
Accepted
time: 584ms
memory: 105824kb