# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
246264 |
2020-07-08T13:09:17 Z |
dantoh000 |
Pipes (CEOI15_pipes) |
C++14 |
|
2537 ms |
65540 KB |
#include <utility>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef pair<int,int> ii;
const int N = 100005;
int n,m;
ii edg[6000006];
vector<ii> bad;
vector<int> G[N];
int p[N], d[N], sz[N], h[N], pos[N], S[N];
int ct = 0;
int badct = 0;
void dfs(int u){
sz[u] = 1;
for (auto v : G[u]){
if (p[v] == 0){
p[v] = u;
d[v] = d[u]+1;
dfs(v);
sz[u] += sz[v];
}
}
}
void decomp(int u){
pos[u] = ct++;
//printf("%d %d\n",u,ct);
int heavy = 0;
for (auto v : G[u]){
if (p[v] != u) continue;
if (sz[heavy] < sz[v]) heavy = v;
}
if (heavy == 0) return;
h[heavy] = h[u];
decomp(heavy);
for (auto v : G[u]){
if (p[v] != u) continue;
if (v != heavy && v != p[u]) decomp(v);
}
}
void up(int u, int v){
while (h[u] != h[v]){
if (u == -1 || v == -1) return;
if (d[h[u]] > d[h[v]]) swap(u,v);
//printf("updating %d to %d\n",v,h[v]);
S[pos[h[v]]]++;
S[pos[v]+1]--;
v = p[h[v]];
}
if (d[u] > d[v]) swap(u,v);
S[pos[u]+1]++;
S[pos[v]+1]--;
}
int main(){
scanf("%d%d",&n,&m);
for (int i = 0; i < m; i++){
int u,v;
scanf("%d%d",&u,&v);
edg[i] = ii(u,v);
}
sort(edg,edg+m);
for (int i = 0; i < m; i++){
if (i == m-1 || (edg[i].first != edg[i+1].first || edg[i].second != edg[i+1].second)){
int u = edg[i].first,v = edg[i].second;
int Bad = (i && (u == edg[i-1].first && v == edg[i-1].second));
if (!Bad) edg[i] = ii(-1,-1);
G[u].push_back(v);
G[v].push_back(u);
}
}
for (int i =1 ; i <= n; i++) h[i] = i;
for (int i = 1; i <= n; i++){
if (p[i] == 0){
p[i] = -1;
dfs(i);
decomp(i);
}
}
for (int u = 1; u <= n; u++){
sort(G[u].begin(),G[u].end());
for (auto v : G[u]){
if (p[v] != u && p[u] != v) up(u,v);
}
}
for (int i = 0; i < m; i++){
if (edg[i] != ii(-1,-1)) up(edg[i].first,edg[i].second);
}
for (int i = 1; i <= n+1; i++){
S[i] += S[i-1];
}
for (int i = 1; i <= n; i++){
//printf("edge<%d %d> = %d\n",i,p[i],S[pos[i]]);
if (S[pos[i]] == 0 && p[i] != -1){
printf("%d %d\n",p[i],i);
}
}
}
Compilation message
pipes.cpp: In function 'int main()':
pipes.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
~~~~~^~~~~~~~~~~~~~
pipes.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&u,&v);
~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
3200 KB |
Output is correct |
2 |
Correct |
12 ms |
3072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
287 ms |
15300 KB |
Output is correct |
2 |
Incorrect |
278 ms |
15352 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
504 ms |
21608 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
834 ms |
35660 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1140 ms |
42380 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1707 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1802 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2109 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2537 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |