Submission #876865

# Submission time Handle Problem Language Result Execution time Memory
876865 2023-11-22T12:47:01 Z hyakup Pipes (CEOI15_pipes) C++17
0 / 100
2780 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;
#define bug(x) cout << #x << " " << x << endl;

const int maxn = 1e5 + 10;

vector<int> v, pai( maxn ), tam( maxn, 1 );
vector<pair< int, int >> edge( maxn, pair< int, int>( -1, -1 ) );

int find( int a ){
     if( a == pai[a] ) return a;
     if( edge[a] != make_pair( -1, -1 ) ) v.push_back(a);
     return find(pai[a]);
}

void join( int a, int b ){
     v.clear();
     int _a = find(a);
     int _b = find(b);
     if( _a == _b ){
          for( int x : v ) edge[x] = make_pair( -1, -1 );
          return;
     }
     if( tam[_a] < tam[_b] ) swap( _a, _b );
     tam[_a] += tam[_b];
     pai[_b] = _a;
     edge[_b] = make_pair(a, b);
}

int main(){
     int n, m; cin >> n >> m;
     for( int i = 1;i <= n; i++ ) pai[i] = i;
     while( m-- ){
          int a, b; cin >> a >> b;
          join( a, b );
     }
     for( int i = 1; i <= n; i++ ){
          if( edge[i] != make_pair( -1, -1 ) ) cout << edge[i].first << " " << edge[i].second << endl;
     }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1880 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2364 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 231 ms 5032 KB Output is correct
2 Incorrect 232 ms 4612 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 416 ms 7312 KB Output is correct
2 Incorrect 475 ms 7752 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 660 ms 10304 KB Output is correct
2 Incorrect 571 ms 15868 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 825 ms 12628 KB Output is correct
2 Runtime error 773 ms 19948 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1335 ms 35256 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1769 ms 45776 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2244 ms 57224 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2780 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -