# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
208246 | 2020-03-10T12:20:43 Z | alexandra_udristoiu | Pipes (CEOI15_pipes) | C++14 | 2241 ms | 7800 KB |
#include<iostream> #include<vector> #include<cstdio> #define DIM 100005 using namespace std; int n, m, i, x, y, r1, r2, nr; int r[DIM], t[DIM], nxt[DIM], niv[DIM]; char ok[DIM]; vector<int> v[DIM]; int rad(int x){ while(r[x] > 0){ x = r[x]; } return x; } int urm(int x){ int y, aux; y = nxt[x]; while(ok[y] == 1){ y = nxt[y]; } while(x != y){ aux = nxt[x]; nxt[x] = y; x = aux; } return y; } void dfs(int nod, int tt){ niv[nod] = 1 + niv[tt]; for(int i = 0; i < v[nod].size(); i++){ if(v[nod][i] != tt){ dfs(v[nod][i], nod); } } if(t[nod] != tt){ ok[ t[nod] ] = ok[nod]; t[nod] = tt; nxt[nod] = t[nod]; } } int main(){ scanf("%d%d", &n, &m); for(i = 1; i <= n; i++){ r[i] = -1; } for(; m; m--){ scanf("%d%d", &x, &y); r1 = rad(x); r2 = rad(y); if(r1 != r2){ /*nr++; if(nr == n){ break; }*/ v[x].push_back(y); v[y].push_back(x); if(r[r1] < r[r2]){ r[r1] += r[r2]; r[r2] = r1; dfs(y, x); ok[y] = 0; } else{ r[r2] += r[r1]; r[r1] = r2; dfs(x, y); ok[x] = 0; } } else{ while(x != y){ if(niv[x] > niv[y]){ ok[x] = 1; x = urm(x); } else{ ok[y] = 1; y = urm(y); } } } } for(i = 1; i <= n; i++){ if(ok[i] == 0 && t[i] != 0){ cout<< i <<" "<< t[i] <<"\n"; } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 2680 KB | Output is correct |
2 | Correct | 6 ms | 2680 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 2936 KB | Output is correct |
2 | Correct | 10 ms | 2936 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 174 ms | 2812 KB | Output is correct |
2 | Correct | 174 ms | 2892 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 308 ms | 3192 KB | Output is correct |
2 | Correct | 368 ms | 3192 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 502 ms | 3832 KB | Output is correct |
2 | Correct | 431 ms | 4084 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 660 ms | 6008 KB | Output is correct |
2 | Correct | 611 ms | 6008 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1063 ms | 6520 KB | Output is correct |
2 | Correct | 1020 ms | 6744 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1383 ms | 7416 KB | Output is correct |
2 | Correct | 1346 ms | 7512 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1746 ms | 7416 KB | Output is correct |
2 | Correct | 1765 ms | 7544 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2241 ms | 7160 KB | Output is correct |
2 | Correct | 2129 ms | 7800 KB | Output is correct |