# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
54800 |
2018-07-05T05:52:39 Z |
윤교준(#1510) |
Pipes (CEOI15_pipes) |
C++11 |
|
4955 ms |
11328 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;
int GE[100001], GD[300005], GI[300005], Gn = 100001;
int prt[100001][17], dep[100001];
int ud[100001], cnt[2][100001];
bitset<100001> chk;
int N, M;
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); }
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(ud, ud+N+1, 0);
iota(GE, GE+N+1, 0);
for(int i = 0, a, b; i < M; i++) {
cin >> a >> b;
if(uf(a) == uf(b)) continue;
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];
cin.seekg(0, std::ios::beg);
cin >> N >> M;
for(int i = 0, a, b, c; i < M; i++) {
cin >> a >> b;
if(dep[a] > dep[b]) swap(a, b);
if(prt[b][0] == a && !chk[b]) {
chk[b] = true;
continue;
}
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 |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
896 KB |
Output is correct |
2 |
Correct |
7 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
248 ms |
808 KB |
Output is correct |
2 |
Correct |
237 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
454 ms |
1532 KB |
Output is correct |
2 |
Correct |
512 ms |
1400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
787 ms |
2948 KB |
Output is correct |
2 |
Correct |
669 ms |
3608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1289 ms |
8060 KB |
Output is correct |
2 |
Correct |
1079 ms |
8056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2113 ms |
9188 KB |
Output is correct |
2 |
Correct |
1752 ms |
9276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2893 ms |
11228 KB |
Output is correct |
2 |
Correct |
2739 ms |
11320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3765 ms |
11232 KB |
Output is correct |
2 |
Correct |
3872 ms |
11288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4955 ms |
10640 KB |
Output is correct |
2 |
Correct |
3645 ms |
11328 KB |
Output is correct |