Submission #701170

# Submission time Handle Problem Language Result Execution time Memory
701170 2023-02-20T10:04:06 Z Quan2003 Swapping Cities (APIO20_swap) C++17
0 / 100
666 ms 49356 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 100;
const int INF = 1e7 + 10; 
long long n,m,q,dsz,E;
int timer = 1;
vector<int>adj[N + 1];
int fa[N + 1];
int deg[N + 1],deg1[N + 1],deg3[N + 1]; 
int up[23][N + 1],dp[N + 1],val[N + 1];
int lf[N + 1],ri[N + 1]; 
int in[N + 1],to[N + 1]; 
struct edge{
     int w,u,v;
} edges[N + 1]; 
int find(int u){
     if(u == fa[u]) return u;
     return fa[u] = find(fa[u]); 
}
void dfs_calc(int u,int p){
    to[timer] = u; 
    in[u] = timer++; 
   // if(u == 6) cout<<val[p]<<endl; 
    if(!val[u]) val[u] = val[p]; 
    for(int i = 1; i < 23 ; i++){
        up[i][u] = up[i - 1][up[i - 1][u]];
    }
    for(int i = 0; i < adj[u].size(); i++){
        int v = adj[u][i]; 
        dp[v] = dp[up[0][v] = u] + 1;      
        dfs_calc(v,u);
    }
}
int lca(int a, int b){
    if(dp[a] < dp[b]) swap(a,b);
    int d = dp[a] - dp[b];
    for(int i = 0; i < 23 ; i++){
        if( (d >> i) & 1) a = up[i][a];
    }
    if(a == b) return a;
    for(int i = 22; i >= 0; i--){
         int tA = up[i][a]; int tB = up[i][b];
         if(tA != tB) {
            a = tA; b = tB;
         }
    } 
    return up[0][a];
} 
bool cmp(edge &a, edge &b){
     return a.w < b.w; 
}
void init(int N, int M,std::vector<int> U, std::vector<int> V, std::vector<int> W){
         for(int i = 0; i < M; i++){
              edges[i].u = ++U[i]; edges[i].v = ++V[i];
              edges[i].w = W[i]; 
         }
         sort(edges,edges + M,cmp);
         E = N;
         for(int i = 1; i <= N;i++) fa[i] = i; 
         for(int i = 0; i < M; i++){
              int x = find(edges[i].u); int y = find(edges[i].v);
              if(deg[edges[i].u] == 1) deg1[x]--; 
              if(deg[edges[i].v] == 1) deg1[y]--; 
              deg[edges[i].u]++; deg[edges[i].v]++; 
              if(deg[edges[i].u] == 1) deg1[x]++;  
              else if(deg[edges[i].u] == 3) deg3[x]++;
              if(deg[edges[i].v] == 1) deg1[y]++;
              else if(deg[edges[i].v] == 3) deg3[y]++; 
              E++; 
              if(x == y){
                   fa[x] = fa[E] = E;
                   deg3[E] += deg3[x];
                   deg1[E] += deg1[x];
                   adj[E].push_back(x); 
              }
              else{
                   ////if(x < y) swap(x,y); 
                   fa[x] = fa[y] = fa[E] = E; 
                   deg3[E] += deg3[x] + deg3[y];
                   deg1[E] += deg1[x] + deg1[y];
                   adj[E].push_back(x);
                   adj[E].push_back(y); 
              }
              if(!deg1[E] or deg3[E]) val[E] = edges[i].w;
         }
         for(int i = 0; i <= E; i++) if(!up[0][i]) dfs_calc(i,i);
}
int getMinimumFuelCapacity(int X, int Y){
      int anc = lca(X,Y);
      return val[anc] != 0 ? val[anc] : - 1;     
}

Compilation message

swap.cpp: In function 'void dfs_calc(int, int)':
swap.cpp:29:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for(int i = 0; i < adj[u].size(); i++){
      |                    ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7508 KB Output is correct
2 Correct 4 ms 7484 KB Output is correct
3 Correct 4 ms 7508 KB Output is correct
4 Correct 6 ms 7636 KB Output is correct
5 Correct 7 ms 7892 KB Output is correct
6 Correct 6 ms 7892 KB Output is correct
7 Correct 7 ms 7892 KB Output is correct
8 Correct 43 ms 9808 KB Output is correct
9 Incorrect 666 ms 37000 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7508 KB Output is correct
2 Correct 4 ms 7484 KB Output is correct
3 Incorrect 494 ms 49356 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7508 KB Output is correct
2 Correct 4 ms 7484 KB Output is correct
3 Correct 4 ms 7508 KB Output is correct
4 Correct 6 ms 7636 KB Output is correct
5 Correct 7 ms 7892 KB Output is correct
6 Correct 6 ms 7892 KB Output is correct
7 Correct 7 ms 7892 KB Output is correct
8 Correct 43 ms 9808 KB Output is correct
9 Incorrect 4 ms 7484 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 7484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7508 KB Output is correct
2 Correct 4 ms 7484 KB Output is correct
3 Correct 4 ms 7508 KB Output is correct
4 Correct 6 ms 7636 KB Output is correct
5 Correct 7 ms 7892 KB Output is correct
6 Correct 6 ms 7892 KB Output is correct
7 Correct 7 ms 7892 KB Output is correct
8 Correct 43 ms 9808 KB Output is correct
9 Incorrect 666 ms 37000 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 7484 KB Output isn't correct
2 Halted 0 ms 0 KB -