# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
54822 |
2018-07-05T07:33:57 Z |
1등은 나의 것^^(#2059) |
Pipes (CEOI15_pipes) |
C++11 |
|
1444 ms |
8704 KB |
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int N = 100005;
int n, m, p[3][N], par[N], dep[N];
bool vis[N], head[N];
vector<int> adj[N];
vector<pii> edg;
int Find (int T, int I) {
if(p[T][I] == I) return I;
return p[T][I] = Find(T, p[T][I]);
}
void calc (int C, int P) {
vis[C] = true;
par[C] = P;
dep[C] = dep[P] + 1;
for(auto &T : adj[C]) {
if(T == P) continue;
calc(T, C);
}
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) {
p[0][i] = p[1][i] = p[2][i] = i;
}
for(int i=1;i<=m;i++) {
int A, B;
scanf("%d%d",&A,&B);
if(Find(0, A) != Find(0, B)) {
p[0][Find(0, A)] = B;
adj[A].push_back(B);
adj[B].push_back(A);
}
else if(Find(1, A) != Find(1, B)) {
p[1][Find(1, A)] = B;
edg.push_back({A, B});
}
}
for(int i=1;i<=n;i++) {
if(!vis[i]) {
head[i] = true;
calc(i, 0);
}
}
for(auto &T : edg) {
int A, B;
tie(A, B) = T;
while(true) {
int X = Find(2, A);
int Y = Find(2, B);
if(X == Y) break;
if(dep[X] < dep[Y]) swap(X, Y);
p[2][X] = par[X];
}
}
for(int i=1;i<=n;i++) {
if(!head[i] && Find(2, i) == i) {
printf("%d %d\n", i, par[i]);
}
}
}
Compilation message
pipes.cpp: In function 'int main()':
pipes.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
~~~~~^~~~~~~~~~~~~~
pipes.cpp:36:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&A,&B);
~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2688 KB |
Output is correct |
2 |
Correct |
3 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
3072 KB |
Output is correct |
2 |
Correct |
8 ms |
2952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
2936 KB |
Output is correct |
2 |
Correct |
117 ms |
2924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
204 ms |
3300 KB |
Output is correct |
2 |
Correct |
240 ms |
3420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
345 ms |
4080 KB |
Output is correct |
2 |
Correct |
294 ms |
4392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
489 ms |
6840 KB |
Output is correct |
2 |
Correct |
452 ms |
6824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
732 ms |
7512 KB |
Output is correct |
2 |
Correct |
704 ms |
7128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
955 ms |
8572 KB |
Output is correct |
2 |
Correct |
923 ms |
8604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1243 ms |
8588 KB |
Output is correct |
2 |
Correct |
1136 ms |
8704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1444 ms |
8328 KB |
Output is correct |
2 |
Correct |
1376 ms |
8480 KB |
Output is correct |