답안 #1011857

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1011857 2024-07-01T09:53:39 Z PenguinsAreCute Pipes (CEOI15_pipes) C++17
20 / 100
887 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;
#define speed ios_base::sync_with_stdio(false); cin.tie(0)
typedef vector<int> vi;
#define pb push_back
#define REP(i, a, b) for(int i = a; i < b; i++)
#define MAXN 100005
vi adj[MAXN], adj_dfs3[MAXN];
int h[MAXN], crossEdges[MAXN], par[MAXN];
bitset<MAXN> visited;
void dfs(int x) {
    visited[x] = true;
    for(auto i: adj[x]) if(!visited[i]) {
		par[i]=x;
    	adj_dfs3[x].pb(i);
        adj_dfs3[i].pb(x);
        h[i]=h[x]+1;
        dfs(i);
	}
}
int dp(int x) {
    if(visited[x]) return crossEdges[x];
    visited[x] = 1;
    //crossEdges[x]=bEdgeU[x]-bEdgeD[x];
    for(auto i:adj_dfs3[x]) if(h[i]>h[x]) crossEdges[x]+=dp(i);
    return crossEdges[x];
}
int32_t main() {
	speed;
    int N, E, A, B, ans; cin >> N >> E;
    REP(i,0,E) {
        cin>>A>>B;
        adj[A].pb(B);
        adj[B].pb(A);
    }
    REP(i,1,N+1)if(!visited[i]) dfs(i);
    REP(i,1,N+1) visited[i]=0;
	REP(i,1,N+1) for(auto j: adj[i]) {
        if(h[i]>h[j]) crossEdges[i]++;
        else crossEdges[i]--;
    }
	//REP(i,1,N+1) crossEdges[i]=-1;
	vector<int> v;
	REP(i,1,N+1) if(par[i]&&dp(i)==1) v.push_back(i);
	REP(i,0,v.size()) {if(i) cout<<"\n"; cout<<v[i]<<" "<<par[v[i]];}
}

Compilation message

pipes.cpp: In function 'int32_t main()':
pipes.cpp:6:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 | #define REP(i, a, b) for(int i = a; i < b; i++)
......
   45 |  REP(i,0,v.size()) {if(i) cout<<"\n"; cout<<v[i]<<" "<<par[v[i]];}
      |      ~~~~~~~~~~~~                      
pipes.cpp:45:2: note: in expansion of macro 'REP'
   45 |  REP(i,0,v.size()) {if(i) cout<<"\n"; cout<<v[i]<<" "<<par[v[i]];}
      |  ^~~
pipes.cpp:30:21: warning: unused variable 'ans' [-Wunused-variable]
   30 |     int N, E, A, B, ans; cin >> N >> E;
      |                     ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5980 KB Output is correct
2 Correct 1 ms 5980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6892 KB Output is correct
2 Correct 4 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 78 ms 19800 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 145 ms 27228 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 242 ms 44632 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 345 ms 55376 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 559 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 651 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 798 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 887 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -