Submission #876888

# Submission time Handle Problem Language Result Execution time Memory
876888 2023-11-22T13:03:11 Z hyakup Pipes (CEOI15_pipes) C++17
0 / 100
2598 ms 7612 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 ), tempo( maxn, -1 );
vector<pair< int, int >> edge( maxn, pair< int, int>( -1, -1 ) );
int _a, _b;

int find( int& a ){ return (( a == pai[a] ) ? a : find(pai[a]) ); }
bool query( int& a, int& b ){
     v.clear();
     while( (pai[a] != a || pai[b] != b) && a != b ){
          if( tempo[a] > tempo[b] ){
               if( edge[a] != make_pair( -1, -1 ) ) v.push_back(a);
               a = pai[a];
          }
          else{
               if( edge[b] != make_pair( -1, -1 ) ) v.push_back(b);
               b = pai[b];
          }
     }
     return ( a == b );
}

void join( int& a, int& b, int& t ){
     _a = find(a);
     _b = find(b);
     if( tam[_a] < tam[_b] ) swap( _a, _b );
     tam[_a] += tam[_b];
     pai[_b] = _a;
     tempo[_b] = t + 10;
     edge[_b] = make_pair(a, b);
}

int main(){
     int n, m; cin >> n >> m;
     for( int i = 1; i <= n; i++ ) pai[i] = i;
     int a, b;
     while( m-- ){
          cin >> a >> b;
          if( !query( a, b ) ) join( a, b, m );
          else for( int x : v ) edge[x] = make_pair( -1, -1 );
     }
     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 2396 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2396 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 233 ms 2396 KB Output is correct
2 Incorrect 211 ms 2396 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 383 ms 2392 KB Output is correct
2 Incorrect 452 ms 2396 KB Mismatched edge
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 641 ms 2396 KB Output is correct
2 Incorrect 534 ms 2408 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 768 ms 2392 KB Output is correct
2 Incorrect 704 ms 2392 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1295 ms 2396 KB Output is correct
2 Incorrect 1331 ms 2640 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1633 ms 2392 KB Output is correct
2 Incorrect 1546 ms 2392 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2068 ms 2392 KB Output is correct
2 Incorrect 2011 ms 2648 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2598 ms 2392 KB Output is correct
2 Incorrect 2585 ms 7612 KB Wrong number of edges
3 Halted 0 ms 0 KB -