# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
54806 |
2018-07-05T06:39:07 Z |
윤교준(#1510) |
Pipes (CEOI15_pipes) |
C++11 |
|
1217 ms |
12436 KB |
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[sz(V)-2])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define upmax(a,b) (a)=max((a),(b))
#define upmin(a,b) (a)=min((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
struct DJF {
DJF() { init(); }
int ud[100001];
void init() { iota(ud, ud+100001, 0); }
int uf(int i) { return i == ud[i] ? i : (ud[i] = uf(ud[i])); }
void uf(int a, int b) { ud[uf(b)] = uf(a); }
} djf1, djf2;
int GE[100001], GD[300005], GI[300005], Gn = 100001;
int EA[100001], EB[100001], En;
int prt[100001][17], dep[100001];
int cnt[2][100001];
bitset<100001> chk;
int N, M;
int lca(int a, int b) {
if(dep[a] > dep[b]) swap(a, b);
const int dt = dep[b] - dep[a];
for(int i = 0; i < 17; i++) if(dt & (1<<i))
b = prt[b][i];
if(a == b) return a;
for(int i = 16; ~i; i--) if(prt[a][i] != prt[b][i]) {
a = prt[a][i]; b = prt[b][i];
}
return prt[a][0];
}
void f(int i) {
for(int gi = i, v;;) {
v = GD[gi];
if(!v || !gi || gi == GE[i]) break;
if(!dep[v]) {
prt[v][0] = i;
dep[v] = dep[i] + 1;
f(v);
}
gi = GI[gi];
}
}
void g(int i) {
for(int gi = i, v;;) {
v = GD[gi];
if(!v || !gi || gi == GE[i]) break;
if(dep[i] < dep[v]) {
g(v);
cnt[1][i] += cnt[1][v];
}
gi = GI[gi];
}
cnt[1][i] -= cnt[0][i];
chk[i] = !!cnt[1][i];
}
int main() {
//freopen("input.txt", "r", stdin);
ios::sync_with_stdio(false); cin.tie(0);
cin >> N >> M;
iota(GE, GE+N+1, 0);
for(int i = 0, a, b; i < M; i++) {
cin >> a >> b;
if(djf1.uf(a) == djf1.uf(b)) {
if(djf2.uf(a) == djf2.uf(b)) continue;
djf2.uf(a, b);
En++;
EA[En] = a; EB[En] = b;
continue;
}
djf1.uf(a, b);
{
GD[GE[a]] = b;
GI[GE[a]] = Gn;
GE[a] = Gn;
Gn++;
}
{
GD[GE[b]] = a;
GI[GE[b]] = Gn;
GE[b] = Gn;
Gn++;
}
}
for(int i = 1; i <= N; i++) {
if(dep[i]) continue;
dep[i] = 1;
f(i);
}
for(int j = 1; j < 17; j++) for(int i = 1; i <= N; i++)
prt[i][j] = prt[prt[i][j-1]][j-1];
for(int i = 1, a, b, c; i <= En; i++) {
a = EA[i]; b = EB[i];
c = lca(a, b);
if(a == c) {
cnt[0][a]++;
cnt[1][b]++;
} else {
cnt[0][c] += 2;
cnt[1][a]++;
cnt[1][b]++;
}
}
chk.reset();
for(int i = 1; i <= N; i++) if(1 == dep[i]) g(i);
for(int i = 1; i <= N; i++) if(1 < dep[i] && !chk[i])
printf("%d %d\n", i, prt[i][0]);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1152 KB |
Output is correct |
2 |
Correct |
3 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1664 KB |
Output is correct |
2 |
Correct |
6 ms |
1664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
1568 KB |
Output is correct |
2 |
Correct |
94 ms |
1564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
188 ms |
2300 KB |
Output is correct |
2 |
Correct |
202 ms |
2296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
276 ms |
3812 KB |
Output is correct |
2 |
Correct |
255 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
411 ms |
9016 KB |
Output is correct |
2 |
Correct |
401 ms |
9016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
654 ms |
10388 KB |
Output is correct |
2 |
Correct |
633 ms |
9848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
830 ms |
12280 KB |
Output is correct |
2 |
Correct |
749 ms |
12436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
974 ms |
12384 KB |
Output is correct |
2 |
Correct |
943 ms |
12360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1211 ms |
11776 KB |
Output is correct |
2 |
Correct |
1217 ms |
12280 KB |
Output is correct |