답안 #589796

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
589796 2022-07-05T09:35:58 Z daria 낙하산 고리들 (IOI12_rings) C++14
52 / 100
1503 ms 262144 KB
#include "bits/stdc++.h"
using namespace std;
#define ll int
#define MAXN 1000005
#define _ << " " <<
//definizioni globali

vector<array<ll, 2> > edges;
ll ris=-1, stato = 0;
ll n;

struct grafo{
 ll par[MAXN], size[MAXN];
 vector<ll> adj[MAXN];
 ll can = -1, nc = 0, idx = -1;

 //union find
 ll find(ll a){
  if(par[a] == a) return a;
  return par[a]=find(par[a]);
 }

 bool same(ll a, ll b){
  return find(a) == find(b);
 }

 void unite(ll a, ll b){
  a = find(a);
  b = find(b);
  if(size[a] > size[b]) swap(a, b);
  par[a] = b;
  size[b] += size[a];
 }

 //archi
 void link(ll a, ll b){
  if(a == can || b == can) return;
  //cout << a _ b _ idx <<  " ";

  adj[a].push_back(b);
  adj[b].push_back(a);

  ll dega = adj[a].size(), degb = adj[b].size();
  bool check = 0;
  if(dega == 2 && degb == 2 && same(a, b)) check = 1; //creo un ciclo
  if(dega == 3 || degb ==  3) check = 1; //nodo con grado >= 3

  if(!same(a, b)) unite(a, b);

  if(check){
   if(idx == -1 || !same(idx, a)){
    nc++; idx = a;
   }
  }
  if(idx != -1) idx = find(idx);
  //cout << idx << endl;
 }

 //build
 void init(ll n){
  for(ll i=0; i<n; ++i){
   par[i] = i;
   size[i] = 1;
  }
  for(auto u : edges)
   link(u[0], u[1]);
 }

};


grafo G[5];

void Init(int N) {
 n = N;
 G[0].init(N);
}

void Link(int a, int b) {
 edges.push_back({a, b});
 grafo &g = G[0];
 g.link(a, b);
 for(ll i=0; i<n; ++i){
  //cout << i _ g.find(i) << endl;
 }
 ll dega = g.adj[a].size(), degb = g.adj[b].size();

 // aggiorno i 4 grafi alternativi
 if(stato == 1) for(ll i=1; i<5; ++i) G[i].link(a, b);

 //primo nodo con grado >= 3
 if(stato == 0){
  if(dega == 3){
   stato = 1;
   G[1].can = a; G[2].can = g.adj[a][0]; G[3].can = g.adj[a][1]; G[4].can = g.adj[a][2]; }
  else if(degb == 3){
   stato = 1;
   G[1].can = b; G[2].can = g.adj[b][0]; G[3].can = g.adj[b][1]; G[4].can = g.adj[b][2]; }

  // costruisco i 4 grafi alternativi
  if(stato == 1) for(ll i=1; i<5; ++i) G[i].init(n);
 }
}


int CountCritical() {
 if(ris == 0)
  return 0;

 grafo &g = G[0];

 //cout << endl <<  g.nc << " " << g.idx << endl;
 if(g.nc == 0)
  return n;

 if(g.nc >= 2)
  return ris = 0;

 //g.nc == 1
 if(stato == 0)
  return g.size[g.idx];

 //stato >= 1
 ll cnt =0;
 for(ll i= 1; i<5; ++i)
  cnt += (G[i].nc == 0);
 return ris = cnt;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 117636 KB Output is correct
2 Correct 66 ms 118712 KB Output is correct
3 Correct 60 ms 118840 KB Output is correct
4 Correct 53 ms 117712 KB Output is correct
5 Correct 71 ms 117868 KB Output is correct
6 Correct 66 ms 118132 KB Output is correct
7 Correct 68 ms 118056 KB Output is correct
8 Correct 56 ms 117900 KB Output is correct
9 Correct 68 ms 118776 KB Output is correct
10 Correct 61 ms 118860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 415 ms 149004 KB Output is correct
2 Runtime error 1503 ms 262144 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 117636 KB Output is correct
2 Correct 66 ms 118712 KB Output is correct
3 Correct 60 ms 118840 KB Output is correct
4 Correct 53 ms 117712 KB Output is correct
5 Correct 71 ms 117868 KB Output is correct
6 Correct 66 ms 118132 KB Output is correct
7 Correct 68 ms 118056 KB Output is correct
8 Correct 56 ms 117900 KB Output is correct
9 Correct 68 ms 118776 KB Output is correct
10 Correct 61 ms 118860 KB Output is correct
11 Correct 62 ms 118800 KB Output is correct
12 Correct 77 ms 119880 KB Output is correct
13 Correct 64 ms 119884 KB Output is correct
14 Correct 72 ms 119168 KB Output is correct
15 Correct 71 ms 119344 KB Output is correct
16 Correct 64 ms 118384 KB Output is correct
17 Correct 68 ms 119896 KB Output is correct
18 Correct 73 ms 120788 KB Output is correct
19 Correct 61 ms 118356 KB Output is correct
20 Correct 68 ms 119884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 117636 KB Output is correct
2 Correct 66 ms 118712 KB Output is correct
3 Correct 60 ms 118840 KB Output is correct
4 Correct 53 ms 117712 KB Output is correct
5 Correct 71 ms 117868 KB Output is correct
6 Correct 66 ms 118132 KB Output is correct
7 Correct 68 ms 118056 KB Output is correct
8 Correct 56 ms 117900 KB Output is correct
9 Correct 68 ms 118776 KB Output is correct
10 Correct 61 ms 118860 KB Output is correct
11 Correct 62 ms 118800 KB Output is correct
12 Correct 77 ms 119880 KB Output is correct
13 Correct 64 ms 119884 KB Output is correct
14 Correct 72 ms 119168 KB Output is correct
15 Correct 71 ms 119344 KB Output is correct
16 Correct 64 ms 118384 KB Output is correct
17 Correct 68 ms 119896 KB Output is correct
18 Correct 73 ms 120788 KB Output is correct
19 Correct 61 ms 118356 KB Output is correct
20 Correct 68 ms 119884 KB Output is correct
21 Correct 75 ms 119748 KB Output is correct
22 Correct 82 ms 120832 KB Output is correct
23 Correct 93 ms 121700 KB Output is correct
24 Correct 202 ms 129792 KB Output is correct
25 Correct 81 ms 122848 KB Output is correct
26 Correct 177 ms 133080 KB Output is correct
27 Correct 96 ms 122820 KB Output is correct
28 Correct 246 ms 136736 KB Output is correct
29 Correct 145 ms 129728 KB Output is correct
30 Correct 112 ms 123484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 117636 KB Output is correct
2 Correct 66 ms 118712 KB Output is correct
3 Correct 60 ms 118840 KB Output is correct
4 Correct 53 ms 117712 KB Output is correct
5 Correct 71 ms 117868 KB Output is correct
6 Correct 66 ms 118132 KB Output is correct
7 Correct 68 ms 118056 KB Output is correct
8 Correct 56 ms 117900 KB Output is correct
9 Correct 68 ms 118776 KB Output is correct
10 Correct 61 ms 118860 KB Output is correct
11 Correct 415 ms 149004 KB Output is correct
12 Runtime error 1503 ms 262144 KB Execution killed with signal 9
13 Halted 0 ms 0 KB -