Submission #557885

# Submission time Handle Problem Language Result Execution time Memory
557885 2022-05-06T09:09:36 Z 600Mihnea Making Friends on Joitter is Fun (JOI20_joitter2) C++17
0 / 100
10 ms 14792 KB
#include <bits/stdc++.h>

bool home = 1;

using namespace std;

typedef long long ll;

const int N=100000+7;
int n;
int m;
int sol;
vector<int> g[N];
vector<int> ig[N];
vector<int> fl[N];
set<pair<int, int>> edges;

void add_g(int a, int b);
void add_fl(int a, int b);

void add_g(int a,int b){
  if(a==b||edges.count({a, b})) return;
  sol++;
  assert(a!=b);
  assert(1<=a&&a<=n);
  assert(1<=b&&b<=n);
  assert(!edges.count({a, b}));
  edges.insert({a, b});
  g[a].push_back(b);
  ig[b].push_back(a);
  if(edges.count({b, a})) {
    add_fl(a,b);
  }


  for (auto &c:fl[b]) {
    if(a!=c&&!edges.count({a, c})) {
      add_g(a,c);
    }
  }
}

void add_fl(int a,int b) {
  fl[a].push_back(b);
  fl[b].push_back(a);
  for (auto &inv:ig[a]) {
    if(inv!=b&&!edges.count({inv, b})) {
      add_g(inv, b);
    }
  }
  for (auto &inv:ig[b]) {
    if(inv!=a&&!edges.count({inv, a})) {
      add_g(inv, a);
    }
  }
}

signed main() {
#ifdef ONLINE_JUDGE
  home = 0;
#endif

  home=0;

  if (home) {
    freopen("I_am_iron_man", "r", stdin);
  }
  else {
    ios::sync_with_stdio(0); cin.tie(0);
  }


  cin>>n>>m;

  for (int im=1;im<=m;im++) {
    int a, b;
    cin>>a>>b;
    add_g(a,b);
    cout<<sol<<"\n";
  }
}

Compilation message

joitter2.cpp: In function 'int main()':
joitter2.cpp:66:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |     freopen("I_am_iron_man", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7376 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Runtime error 10 ms 14792 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7376 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Runtime error 10 ms 14792 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7376 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Runtime error 10 ms 14792 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -