답안 #246241

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
246241 2020-07-08T12:30:10 Z dantoh000 Pipes (CEOI15_pipes) C++14
10 / 100
2832 ms 65540 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
const int N = 100005;
int n,m;
vector<int> G[N];
vector<ii> bad;
int p[N], d[N], sz[N], h[N], pos[N], S[N];
int ct = 1;
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];
		}
		else{
            if (p[u] == v) continue;
            else{
                bad.push_back({u,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);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    iota(h,h+N,0);
    for (int i = 1; i <= n; i++){
        if (p[i] == 0){
            p[i] = -1;
            dfs(i);
            decomp(i);
        }
    }
    for (auto X : bad){
        int u,v;
        tie(u,v) = X;
        //printf("%d %d bad\n",u,v);
        up(u,v);
    }
    for (int i = 1; i <= n; 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:60: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:64:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&u,&v);
         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 3072 KB Output is correct
2 Incorrect 7 ms 3072 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 3968 KB Output is correct
2 Correct 12 ms 3816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 229 ms 28008 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 415 ms 31428 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 727 ms 65536 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1127 ms 65536 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1531 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2079 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2543 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2832 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -