# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
152751 |
2019-09-09T10:35:04 Z |
toloraia |
Pipes (CEOI15_pipes) |
C++14 |
|
5000 ms |
65536 KB |
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
//#define ll long long
//#define ll __int128
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
/*
#pragma comment(linker, "/STACK: 20000000005")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
using namespace std;
const int N = 1e5 + 5, M = 6e6 + 5;
int n, m;
int K;
vector < int > g[N];
int A[N], AA[N];
int B[N], BB[N];
int x, y;
int T;
int in[N], up[N];
int nn[N], mi[N], sz[N];
int pr[N];
void dfs (int k){
in[k] = ++T;
up[k] = in[k];
int to, i, toto;
int X;
bool ok;
for (i = 0; i < nn[k]; i++){
X = g[k][i];
ok = 0;
if (X % 2 == 0)
ok = 1;
X /= 2;
while (X){
toto = X % K;
X /= K;
to = toto;
if (to > n)
to -= n;
if (to == pr[k])
continue;
if (in[to]){
up[k] = min (up[k], in[to]);
continue;
}
pr[to] = k;
dfs (to);
if (up[to] > in[k] && ok == 1){
cout << k << " " << to << endl;
}
up[k] = min (up[k], up[to]);
}
}
}
void dam (int k, int x){
if (nn[k] >= sz[k]){
g[k].pb (x);
nn[k]++;
return;
}
g[k][nn[k]++] = x;
}
int p;
bool ok;
void midi (int k){
if (mi[k] >= sz[k])
return;
p = g[k][mi[k]];
ok = 0;
if (mi[k] < sz[k] - 1 && g[k][mi[k] + 1] == p)
ok = 1;
while (mi[k] < sz[k] - 1 && g[k][mi[k] + 1] == p)
mi[k]++;
mi[k]++;
if (ok){
AA[k] = AA[k] * K + p;
BB[k]++;
AA[p] = AA[p] * K + k;
BB[p]++;
if (BB[k] == 2){
dam (k, AA[k] * 2 + 1);
BB[k] = 0;
AA[k] = 0;
}
if (BB[p] == 2){
dam (p, AA[p] * 2 + 1);
BB[p] = 0;
AA[p] = 0;
}
midi (p);
return;
}
A[k] = A[k] * K + p;
B[k]++;
A[p] = A[p] * K + k;
B[p]++;
if (B[k] == 2){
dam (k, A[k] * 2);
B[k] = 0;
A[k] = 0;
}
if (B[p] == 2){
dam (p, A[p] * 2);
B[p] = 0;
A[p] = 0;
}
midi (p);
}
int t, num;
int j;
int i, to;
main()
{
//freopen ("in.in", "r", stdin);freopen ("out.out", "w", stdout);
//ios_base::sync_with_stdio(false);
cin >> n >> m;
K = n + 1;
for (i = 1; i <= m; i++){
cin >> x >> y;
if (x > y)
swap (x, y);
g[x].pb (y);
sz[x]++;
}
for (i = 1; i <= n; i++){
sort (g[i].begin(), g[i].end());
}
for (int i = 1; i <= n; i++){
while (mi[i] < sz[i])
midi (i);
}
for (i = 1; i <= n; i++)
if (A[i])
dam (i, A[i] * 2);
for (i = 1; i <= n; i++)
if (AA[i])
dam (i, AA[i] * 2 + 1);
for (i = 1; i <= n; i++)
if (in[i] == 0)
dfs (i);
return 0;
}
Compilation message
pipes.cpp:138:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2684 KB |
Output is correct |
2 |
Correct |
4 ms |
2680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
3196 KB |
Output is correct |
2 |
Correct |
18 ms |
3064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
587 ms |
7940 KB |
Output is correct |
2 |
Correct |
560 ms |
6928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1049 ms |
11072 KB |
Output is correct |
2 |
Correct |
1236 ms |
10984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1800 ms |
17684 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 |
2422 ms |
38896 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3938 ms |
65536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5044 ms |
35352 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5057 ms |
34464 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5064 ms |
33120 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |