# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
32817 |
2017-10-15T18:34:48 Z |
imaxblue |
Pipes (CEOI15_pipes) |
C++14 |
|
5000 ms |
13584 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() (rand() >> 3)*rand()
int n, m, a, b, r[100005], p[100005], p2[100005], d[100005];
bool u[100005];
vector<int> v[100005], com[100005];
bool mrg(int A, int B){
//cout << A << ' ' << B << ' ' ;
A=r[A]; B=r[B];
//cout << A << ' ' << B << ' ';
if (A==B) return 0;
if (com[A].size()<com[B].size()) return mrg(B, A);
for (auto i:com[B]){
com[A].pb(i);
r[i]=A;
}
return 1;
}
void dfs(int N, int P){
p2[N]=p[N]=P;
if (P!=-1) d[N]=d[P]+1;
fox(l, v[N].size()){
if (v[N][l]==P) continue;
dfs(v[N][l], N);
}
}
void lca(int X, int Y){
X=r[X]; Y=r[Y];
if (p[X]!=-1 && r[p[X]]==Y || p[Y]!=-1 && r[p[Y]]==X) return;
//int C=0;
while(X!=Y){
//cout << X << ' ' << p2[X] << ' ' << Y << ' ' << p2[Y]<< endl;
//fox(l, com[X].size()) cout << com[X][l] << ' '; cout << endl;
//fox(l, com[Y].size()) cout << com[Y][l] << ' '; cout << endl;
if (d[X]>d[Y]){
u[X]=1;
p2[X]=p2[r[p2[X]]];
d[X]=d[r[p2[X]]];
mrg(X, p2[X]);
//X=p[X];
} else {
u[Y]=1;
p2[Y]=p2[r[p2[Y]]];
d[Y]=d[r[p2[Y]]];
mrg(Y, p2[Y]);
//Y=p[Y];
}
X=r[X]; Y=r[Y];
}
}
int main(){
scanf("%i%i", &n, &m);
fox1(l, n){
r[l]=l;
com[l].clear(); com[l].pb(l);
}
fox(l, m){
scanf("%i%i", &a, &b);
if (mrg(a, b)){
v[a].pb(b);
v[b].pb(a);
}
}
fox1(l, n){
if (p[l]==0){
dfs(l, -1);
}
}
fox1(l, n){
r[l]=l;
com[l].clear(); com[l].pb(l);
}
rewind(stdin);
scanf("%i%i", &n, &m);
fox(l, m){
scanf("%i%i", &a, &b);
lca(a, b);
}
fox1(l, n){
if (!u[l] && p[l]!=-1){
printf("%i %i\n", l, p[l]);
}
}
return 0;
}
Compilation message
pipes.cpp: In function 'void dfs(int, int)':
pipes.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define fox(k, x) for (int k=0; k<x; ++k)
pipes.cpp:45:9:
fox(l, v[N].size()){
~~~~~~~~~~~~~~
pipes.cpp:45:5: note: in expansion of macro 'fox'
fox(l, v[N].size()){
^~~
pipes.cpp: In function 'void lca(int, int)':
pipes.cpp:52:18: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
if (p[X]!=-1 && r[p[X]]==Y || p[Y]!=-1 && r[p[Y]]==X) return;
~~~~~~~~~^~~~~~~~~~~~~
pipes.cpp: In function 'int main()':
pipes.cpp:75:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i%i", &n, &m);
~~~~~^~~~~~~~~~~~~~~~
pipes.cpp:81:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i%i", &a, &b);
~~~~~^~~~~~~~~~~~~~~~
pipes.cpp:97:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i%i", &n, &m);
~~~~~^~~~~~~~~~~~~~~~
pipes.cpp:99:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i%i", &a, &b);
~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5075 ms |
4992 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5057 ms |
5376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5010 ms |
5332 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5093 ms |
5880 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5002 ms |
7088 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5102 ms |
11036 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5087 ms |
11944 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5011 ms |
13572 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5084 ms |
13584 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5029 ms |
13080 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |