답안 #1028125

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1028125 2024-07-19T14:07:00 Z qwewq Pipes (CEOI15_pipes) C++14
0 / 100
669 ms 49664 KB
#include <bits/stdc++.h>

#define ll long long
using namespace std;
const int N = 1e5;
vector < int > adj[N + 2];
struct dsu{
    int par[N + 2];
    int find_par(const int &u){
        if(par[u] < 0)return u;
        par[u] = find_par(par[u]);
        return par[u];
    }
    bool union_set(int u , int v){
        u = find_par(u);
        v = find_par(v);
        if(u != v){
            if(par[u] > par[v])swap(u , v);
            par[u] += par[v];
            par[v] = u;
            return true;
        }
        return false;
    }

} par1 , par2;
int timer = 0; 
int n , m;
void dfs(int &c, int depth, int &par){
	par1.par[c] = depth;
	par2.par[c] = par1.par[c];
	int op = par;
	for (int i : adj[c]){
		if (i == par){ continue;}
		if (par1.par[i] != -1){ par2.par[c] = min( par2.par[c] ,par1.par[i]); continue;}
		dfs(i,depth+1,c);
		par2.par[c] = min(par2.par[c] , par2.par[i]);
	}
	if (par2.par[c]  >= depth && op != c) cout << c << " " << op << '\n';
}
 
void solve() {
  
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        par1.par[i] = par2.par[i] = -1;
    }
    for(int i = 1; i <= m ;i ++){
        int u , v;
        cin >> u >> v;
        if(par1.union_set(u , v)){
            adj[u].push_back(v);
            adj[v].push_back(u);
         //   cout << u << ' ' <<  v<< '\n';
        }
        else if(par2.union_set(u , v)){
            adj[u].push_back(v);
            adj[v].push_back(u);
          //  cout << u << ' '<< v << '\n';
        }
    }
    for(int  i = 1; i <= n ; i ++){
        par1.par[i] = par2.par[i] = -1;
    }
    for(int i = 1; i <= n ; i++){
        if(par1.par[i] == -1)dfs(i , 0 , i);
    }
    
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    #define _ "maxseq."
    if (fopen(_ "inp", "r")) {
        freopen(_ "inp", "r", stdin);
        freopen(_ "out", "w", stdout);
    }
    
    solve();
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen(_ "inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
pipes.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         freopen(_ "out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Incorrect 1 ms 2652 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3164 KB Output is correct
2 Incorrect 3 ms 2908 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 3156 KB Output is correct
2 Incorrect 54 ms 2972 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 92 ms 3668 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 163 ms 5200 KB Output is correct
2 Runtime error 138 ms 18512 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 229 ms 10068 KB Output is correct
2 Runtime error 200 ms 24752 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 337 ms 11280 KB Output is correct
2 Runtime error 344 ms 41560 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 446 ms 13180 KB Output is correct
2 Runtime error 433 ms 49664 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 554 ms 16468 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 669 ms 28860 KB Memory limit exceeded
2 Halted 0 ms 0 KB -