Submission #345115

# Submission time Handle Problem Language Result Execution time Memory
345115 2021-01-07T03:51:40 Z rrrr10000 Game (IOI14_game) C++14
100 / 100
684 ms 34124 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define rsort(a) {sort(all(a));reverse(all(a));}
#define pb emplace_back
#define lb(v,k) (lower_bound(all(v),(k))-v.begin())
#define fi first
#define se second
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
#define dame(a) {cout<<a<<endl;return 0;}
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vvvp=vector<vvp>;
using vb=vector<bool>;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
const ll inf=1001001001001001001;
vvi g;
int n;
class UF{
public:
    vi data;stack<P> st;
    UF(ll N){
        data=vi(N,1);
    }
    bool heigou(ll x,ll y,bool undo=false){
        x=root(x);y=root(y);
        if(data[x]>data[y])swap(x,y);
        if(undo){st.emplace(y,data[y]);st.emplace(x,data[x]);}
        if(x==y)return false;
        rep(i,n)if(root(i)==i){
            g[i][y]+=g[i][x];
            g[y][i]+=g[i][x];
        }
        data[y]+=data[x];data[x]=-y;
        return true;
    }
    ll root(ll i){if(data[i]>0)return i;return root(-data[i]);}
    ll getsize(ll i){return data[root(i)];}
    bool same(ll a,ll b){return root(a)==root(b);}
    void undo(){rep(i,2){data[st.top().fi]=st.top().se;st.pop();}}
};
UF uf(0);
void initialize(int N){
    n=N;g=vvi(n,vi(n));uf=UF(n);
}
int hasEdge(int a,int b){
    a=uf.root(a);b=uf.root(b);
    if(g[a][b]==uf.getsize(a)*uf.getsize(b)-1){
        uf.heigou(a,b);return 1;
    }
    else{
        g[a][b]++;g[b][a]++;return 0;
    }
}
/*
int main(){
    ll n;cin>>n;
    initialize(n);
    rep(i,n*(n-1)/2){
        ll a,b;cin>>a>>b;
        out(hasEdge(a,b));
    }
}*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 3 ms 492 KB Output is correct
35 Correct 3 ms 492 KB Output is correct
36 Correct 2 ms 492 KB Output is correct
37 Correct 3 ms 492 KB Output is correct
38 Correct 2 ms 492 KB Output is correct
39 Correct 2 ms 492 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Correct 2 ms 492 KB Output is correct
42 Correct 2 ms 492 KB Output is correct
43 Correct 2 ms 492 KB Output is correct
44 Correct 2 ms 492 KB Output is correct
45 Correct 2 ms 492 KB Output is correct
46 Correct 2 ms 492 KB Output is correct
47 Correct 2 ms 492 KB Output is correct
48 Correct 2 ms 492 KB Output is correct
49 Correct 2 ms 492 KB Output is correct
50 Correct 2 ms 492 KB Output is correct
51 Correct 2 ms 492 KB Output is correct
52 Correct 5 ms 492 KB Output is correct
53 Correct 2 ms 492 KB Output is correct
54 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 2 ms 492 KB Output is correct
35 Correct 2 ms 492 KB Output is correct
36 Correct 3 ms 492 KB Output is correct
37 Correct 2 ms 492 KB Output is correct
38 Correct 3 ms 492 KB Output is correct
39 Correct 3 ms 492 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Correct 2 ms 492 KB Output is correct
42 Correct 3 ms 492 KB Output is correct
43 Correct 3 ms 492 KB Output is correct
44 Correct 2 ms 492 KB Output is correct
45 Correct 4 ms 492 KB Output is correct
46 Correct 3 ms 492 KB Output is correct
47 Correct 3 ms 492 KB Output is correct
48 Correct 2 ms 492 KB Output is correct
49 Correct 2 ms 492 KB Output is correct
50 Correct 2 ms 492 KB Output is correct
51 Correct 2 ms 492 KB Output is correct
52 Correct 3 ms 492 KB Output is correct
53 Correct 2 ms 492 KB Output is correct
54 Correct 3 ms 492 KB Output is correct
55 Correct 56 ms 4204 KB Output is correct
56 Correct 54 ms 4236 KB Output is correct
57 Correct 60 ms 4228 KB Output is correct
58 Correct 58 ms 4208 KB Output is correct
59 Correct 53 ms 4204 KB Output is correct
60 Correct 54 ms 4204 KB Output is correct
61 Correct 75 ms 4204 KB Output is correct
62 Correct 70 ms 4332 KB Output is correct
63 Correct 54 ms 4204 KB Output is correct
64 Correct 60 ms 4332 KB Output is correct
65 Correct 57 ms 4204 KB Output is correct
66 Correct 56 ms 4204 KB Output is correct
67 Correct 67 ms 4204 KB Output is correct
68 Correct 63 ms 4204 KB Output is correct
69 Correct 59 ms 4204 KB Output is correct
70 Correct 79 ms 4192 KB Output is correct
71 Correct 72 ms 4204 KB Output is correct
72 Correct 64 ms 4248 KB Output is correct
73 Correct 54 ms 4180 KB Output is correct
74 Correct 58 ms 4332 KB Output is correct
75 Correct 53 ms 4204 KB Output is correct
76 Correct 129 ms 9196 KB Output is correct
77 Correct 148 ms 9116 KB Output is correct
78 Correct 135 ms 9196 KB Output is correct
79 Correct 174 ms 9196 KB Output is correct
80 Correct 178 ms 9292 KB Output is correct
81 Correct 136 ms 9304 KB Output is correct
82 Correct 142 ms 9124 KB Output is correct
83 Correct 159 ms 9324 KB Output is correct
84 Correct 136 ms 9172 KB Output is correct
85 Correct 316 ms 15724 KB Output is correct
86 Correct 264 ms 15848 KB Output is correct
87 Correct 261 ms 15772 KB Output is correct
88 Correct 299 ms 15848 KB Output is correct
89 Correct 333 ms 15728 KB Output is correct
90 Correct 280 ms 15852 KB Output is correct
91 Correct 264 ms 15932 KB Output is correct
92 Correct 247 ms 15832 KB Output is correct
93 Correct 299 ms 15724 KB Output is correct
94 Correct 663 ms 34124 KB Output is correct
95 Correct 614 ms 34040 KB Output is correct
96 Correct 641 ms 34028 KB Output is correct
97 Correct 672 ms 34100 KB Output is correct
98 Correct 608 ms 34048 KB Output is correct
99 Correct 606 ms 34120 KB Output is correct
100 Correct 684 ms 34012 KB Output is correct