답안 #557891

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
557891 2022-05-06T09:15:10 Z 600Mihnea 조이터에서 친구를 만드는건 재밌어 (JOI20_joitter2) C++17
1 / 100
5000 ms 95600 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);
  }

  vector<int> cs;

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

void add_fl(int a,int b) {
  assert(a!=b);
  assert(1<=a&&a<=n);
  assert(1<=b&&b<=n);
  fl[a].push_back(b);
  fl[b].push_back(a);
  vector<int> bs,as;
  for (auto &inv:ig[a]) {
    if(inv!=b&&!edges.count({inv, b})) {
      assert(1<=b&&b<=n);
     /// add_g(inv, b);
      bs.push_back(inv);
    }
  }
  for (auto &inv:ig[b]) {
    if(inv!=a&&!edges.count({inv, a})) {
      assert(1<=a&&a<=n);
     /// add_g(inv, a);
      as.push_back(inv);
    }
  }
  for(auto &inv:bs) add_g(inv,b);
  for(auto &inv:as) 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;
    assert(1<=b&&b<=n);
    add_g(a,b);
    cout<<sol<<"\n";
  }
}

Compilation message

joitter2.cpp: In function 'int main()':
joitter2.cpp:80:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |     freopen("I_am_iron_man", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7364 KB Output is correct
3 Correct 5 ms 7252 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 6 ms 7252 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Correct 18 ms 7604 KB Output is correct
8 Correct 20 ms 7892 KB Output is correct
9 Correct 18 ms 8060 KB Output is correct
10 Correct 13 ms 7472 KB Output is correct
11 Correct 19 ms 7636 KB Output is correct
12 Correct 14 ms 7660 KB Output is correct
13 Correct 13 ms 7496 KB Output is correct
14 Correct 14 ms 7508 KB Output is correct
15 Correct 14 ms 7520 KB Output is correct
16 Correct 13 ms 7508 KB Output is correct
17 Correct 13 ms 7464 KB Output is correct
18 Correct 15 ms 7628 KB Output is correct
19 Correct 14 ms 7496 KB Output is correct
20 Correct 17 ms 7752 KB Output is correct
21 Correct 18 ms 8020 KB Output is correct
22 Correct 19 ms 7588 KB Output is correct
23 Correct 20 ms 8020 KB Output is correct
24 Correct 21 ms 8012 KB Output is correct
25 Correct 18 ms 7892 KB Output is correct
26 Correct 19 ms 8012 KB Output is correct
27 Correct 18 ms 8072 KB Output is correct
28 Correct 19 ms 8096 KB Output is correct
29 Correct 18 ms 8012 KB Output is correct
30 Correct 14 ms 7636 KB Output is correct
31 Correct 16 ms 7636 KB Output is correct
32 Correct 16 ms 7624 KB Output is correct
33 Correct 21 ms 7764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7364 KB Output is correct
3 Correct 5 ms 7252 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 6 ms 7252 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Correct 18 ms 7604 KB Output is correct
8 Correct 20 ms 7892 KB Output is correct
9 Correct 18 ms 8060 KB Output is correct
10 Correct 13 ms 7472 KB Output is correct
11 Correct 19 ms 7636 KB Output is correct
12 Correct 14 ms 7660 KB Output is correct
13 Correct 13 ms 7496 KB Output is correct
14 Correct 14 ms 7508 KB Output is correct
15 Correct 14 ms 7520 KB Output is correct
16 Correct 13 ms 7508 KB Output is correct
17 Correct 13 ms 7464 KB Output is correct
18 Correct 15 ms 7628 KB Output is correct
19 Correct 14 ms 7496 KB Output is correct
20 Correct 17 ms 7752 KB Output is correct
21 Correct 18 ms 8020 KB Output is correct
22 Correct 19 ms 7588 KB Output is correct
23 Correct 20 ms 8020 KB Output is correct
24 Correct 21 ms 8012 KB Output is correct
25 Correct 18 ms 7892 KB Output is correct
26 Correct 19 ms 8012 KB Output is correct
27 Correct 18 ms 8072 KB Output is correct
28 Correct 19 ms 8096 KB Output is correct
29 Correct 18 ms 8012 KB Output is correct
30 Correct 14 ms 7636 KB Output is correct
31 Correct 16 ms 7636 KB Output is correct
32 Correct 16 ms 7624 KB Output is correct
33 Correct 21 ms 7764 KB Output is correct
34 Correct 167 ms 10560 KB Output is correct
35 Execution timed out 5049 ms 95600 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7364 KB Output is correct
3 Correct 5 ms 7252 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 6 ms 7252 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Correct 18 ms 7604 KB Output is correct
8 Correct 20 ms 7892 KB Output is correct
9 Correct 18 ms 8060 KB Output is correct
10 Correct 13 ms 7472 KB Output is correct
11 Correct 19 ms 7636 KB Output is correct
12 Correct 14 ms 7660 KB Output is correct
13 Correct 13 ms 7496 KB Output is correct
14 Correct 14 ms 7508 KB Output is correct
15 Correct 14 ms 7520 KB Output is correct
16 Correct 13 ms 7508 KB Output is correct
17 Correct 13 ms 7464 KB Output is correct
18 Correct 15 ms 7628 KB Output is correct
19 Correct 14 ms 7496 KB Output is correct
20 Correct 17 ms 7752 KB Output is correct
21 Correct 18 ms 8020 KB Output is correct
22 Correct 19 ms 7588 KB Output is correct
23 Correct 20 ms 8020 KB Output is correct
24 Correct 21 ms 8012 KB Output is correct
25 Correct 18 ms 7892 KB Output is correct
26 Correct 19 ms 8012 KB Output is correct
27 Correct 18 ms 8072 KB Output is correct
28 Correct 19 ms 8096 KB Output is correct
29 Correct 18 ms 8012 KB Output is correct
30 Correct 14 ms 7636 KB Output is correct
31 Correct 16 ms 7636 KB Output is correct
32 Correct 16 ms 7624 KB Output is correct
33 Correct 21 ms 7764 KB Output is correct
34 Correct 167 ms 10560 KB Output is correct
35 Execution timed out 5049 ms 95600 KB Time limit exceeded
36 Halted 0 ms 0 KB -