답안 #1088340

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1088340 2024-09-14T09:17:40 Z modwwe 자매 도시 (APIO20_swap) C++17
6 / 100
162 ms 33720 KB
#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
//#define int long long
//#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP     ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe  int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".ans","w",stdout)
#define pb push_back
#define checktime   cerr << (double)clock() / CLOCKS_PER_SEC * 1000  << " ms";
using namespace std;
#define getchar_unlocked getchar

inline int scan()
{
    char c = getchar_unlocked();
    int x = 0;
    while(c<'0'||c>'9')
    {
        c=getchar_unlocked();
    }
    while(c>='0'&&c<='9')
    {
        x=(x<<1)+(x<<3)+c-'0';
        c=getchar_unlocked();
    }
    return x;
}

void phongbeo();
const int inf=1e9+1;
const int mod2=1e9+9;
const int  mod1=998244353;
struct icd
{
    long double a;
    int b;
};
struct ib
{
    int a;
    int b;
};
struct ic
{
    int a,b,c;
};
struct id
{
    int a,b,c,d;
};
struct ie
{
    int a,b,c,d,e;

};

int n,m,s1,s2,s4,s3,sf,k,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,s33,dem3,dem4,l,r,mid,l2,r2,center;
int  i,s10,s12;
int kk;
int el=29;

bool cmp(ic a,ic b)
{
    return a.c<b.c;
}
struct dsu
{
    ib dsu[100001];
    void reset(int x)
    {
        dsu[x]= {1,x};
    }
    int get(int x)
    {
        if(dsu[x].b!=x) dsu[x].b=get(dsu[x].b);
        return dsu[x].b;
    }
    void noi(int x,int y)
    {
        if(dsu[x].a<dsu[y].a) swap(x,y);
        dsu[x].a+=dsu[y].a;
        dsu[y].b=x;
    }
} ds;
ic a[200001];
bool b[200001];
int st[17][100001];
int st2[17][100001];
int depth[100001];
vector<ib> v[100001];
void dfs(int x,int y)
{
    st[0][x]=y;
    depth[x]=depth[y]+1;
    for(auto f:v[x])
        if(f.a!=y)
        {
            st2[0][f.a]=f.b,dfs(f.a,x);

        }
}
int lca(int x,int y)
{
    if(depth[x]<depth[y]) swap(x,y);
    int ss=depth[x]-depth[y];
    int s=0;
    for(int j=0; j<17; ++j)
        if(bit(ss,j))
            s=max(s,st2[j][x]), x=st[j][x];
    if(x==y) return s;
    for(int j=16; j>=0; --j)
        if(st[j][x]!=st[j][y])
            s=max({st2[j][x],st2[j][y],s}),x=st[j][x],y=st[j][y];
    s=max(s,st2[0][x]);
    s=max(s,st2[0][y]);
    return s;
}
void init(int N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
    n=N;
    m=M;
    for(int i=1; i<=m; i++)
       a[i].a=U[i-1],a[i].b=V[i-1],a[i].c=W[i-1],a[i].a++,a[i].b++;
    for(int i=1; i<=n; i++)
        ds.reset(i);
    sort(a+1,a+1+m,cmp);
    bool de=0;
    s5=inf;
    for(int i=1; i<=m; i++)
    {
        s2=ds.get(a[i].a);
        s3=ds.get(a[i].b);
        if(s2!=s3)
        {
            v[a[i].a].pb({a[i].b,a[i].c});
            v[a[i].b].pb({a[i].a,a[i].c});
            ds.noi(s2,s3);
        }
        else b[i]=1;

    }
    dfs(1,0);
     for(int i=1;i<=m;i++)
         if(b[i])
         if(st[0][a[i].a]!=a[i].b&&st[0][a[i].b]!=a[i].a)
     {
         s5=a[i].c;
          break;
     }
    for(int i=1; i<17; i++)
        for(int j=1; j<=n; j++)
            st[i][j]=st[i-1][st[i-1][j]],
                     st2[i][j]=max(st2[i-1][j],st2[i-1][st[i-1][j]]);
}
int getMinimumFuelCapacity(int l, int r)
{
        l++;
        r++;
        if(s5==inf) return -1;
        else  return max(s5,lca(l,r));
}
/*
main()
 {
      freopen("test.inp","r",stdin);
      freopen("test.out","w",stdout);
      cin>>n>>m ;
      vector<int> a1,a2,a3;
       for(int i=1;i<=m;i++)
       {
           int x,y,z;
            cin>>x>>y>>z;
            a1.pb(x);
            a2.pb(y);
            a3.pb(z);
       }
        init(n,m,a1,a2,a3);
         cin>>m;
          while(m--)
          {
               int x,y;
                cin>>x>>y;
                 cout<<getMinimumFuelCapacity(l,r)<<"\n";
          }
 }*/

Compilation message

swap.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
swap.cpp:133:10: warning: unused variable 'de' [-Wunused-variable]
  133 |     bool de=0;
      |          ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2904 KB Output is correct
2 Correct 2 ms 2908 KB Output is correct
3 Correct 2 ms 2888 KB Output is correct
4 Correct 2 ms 3060 KB Output is correct
5 Correct 2 ms 3164 KB Output is correct
6 Correct 2 ms 3164 KB Output is correct
7 Correct 2 ms 3164 KB Output is correct
8 Correct 3 ms 3164 KB Output is correct
9 Correct 43 ms 22512 KB Output is correct
10 Correct 52 ms 27476 KB Output is correct
11 Correct 52 ms 26912 KB Output is correct
12 Correct 56 ms 28184 KB Output is correct
13 Correct 50 ms 29012 KB Output is correct
14 Correct 45 ms 22628 KB Output is correct
15 Correct 84 ms 31608 KB Output is correct
16 Correct 92 ms 30428 KB Output is correct
17 Correct 94 ms 33152 KB Output is correct
18 Correct 88 ms 32440 KB Output is correct
19 Correct 51 ms 12112 KB Output is correct
20 Correct 144 ms 32464 KB Output is correct
21 Correct 146 ms 31500 KB Output is correct
22 Correct 162 ms 33460 KB Output is correct
23 Correct 153 ms 33720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2904 KB Output is correct
2 Correct 2 ms 2908 KB Output is correct
3 Incorrect 72 ms 29032 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2904 KB Output is correct
2 Correct 2 ms 2908 KB Output is correct
3 Correct 2 ms 2888 KB Output is correct
4 Correct 2 ms 3060 KB Output is correct
5 Correct 2 ms 3164 KB Output is correct
6 Correct 2 ms 3164 KB Output is correct
7 Correct 2 ms 3164 KB Output is correct
8 Correct 3 ms 3164 KB Output is correct
9 Correct 2 ms 2904 KB Output is correct
10 Incorrect 2 ms 3160 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2904 KB Output is correct
2 Correct 2 ms 2904 KB Output is correct
3 Correct 2 ms 2908 KB Output is correct
4 Correct 2 ms 2888 KB Output is correct
5 Correct 2 ms 3060 KB Output is correct
6 Correct 2 ms 3164 KB Output is correct
7 Correct 2 ms 3164 KB Output is correct
8 Correct 2 ms 3164 KB Output is correct
9 Correct 3 ms 3164 KB Output is correct
10 Correct 43 ms 22512 KB Output is correct
11 Correct 52 ms 27476 KB Output is correct
12 Correct 52 ms 26912 KB Output is correct
13 Correct 56 ms 28184 KB Output is correct
14 Correct 50 ms 29012 KB Output is correct
15 Incorrect 2 ms 3160 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2904 KB Output is correct
2 Correct 2 ms 2908 KB Output is correct
3 Correct 2 ms 2888 KB Output is correct
4 Correct 2 ms 3060 KB Output is correct
5 Correct 2 ms 3164 KB Output is correct
6 Correct 2 ms 3164 KB Output is correct
7 Correct 2 ms 3164 KB Output is correct
8 Correct 3 ms 3164 KB Output is correct
9 Correct 43 ms 22512 KB Output is correct
10 Correct 52 ms 27476 KB Output is correct
11 Correct 52 ms 26912 KB Output is correct
12 Correct 56 ms 28184 KB Output is correct
13 Correct 50 ms 29012 KB Output is correct
14 Correct 45 ms 22628 KB Output is correct
15 Correct 84 ms 31608 KB Output is correct
16 Correct 92 ms 30428 KB Output is correct
17 Correct 94 ms 33152 KB Output is correct
18 Correct 88 ms 32440 KB Output is correct
19 Incorrect 72 ms 29032 KB Output isn't correct
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2904 KB Output is correct
2 Correct 2 ms 2904 KB Output is correct
3 Correct 2 ms 2908 KB Output is correct
4 Correct 2 ms 2888 KB Output is correct
5 Correct 2 ms 3060 KB Output is correct
6 Correct 2 ms 3164 KB Output is correct
7 Correct 2 ms 3164 KB Output is correct
8 Correct 2 ms 3164 KB Output is correct
9 Correct 3 ms 3164 KB Output is correct
10 Correct 43 ms 22512 KB Output is correct
11 Correct 52 ms 27476 KB Output is correct
12 Correct 52 ms 26912 KB Output is correct
13 Correct 56 ms 28184 KB Output is correct
14 Correct 50 ms 29012 KB Output is correct
15 Correct 45 ms 22628 KB Output is correct
16 Correct 84 ms 31608 KB Output is correct
17 Correct 92 ms 30428 KB Output is correct
18 Correct 94 ms 33152 KB Output is correct
19 Correct 88 ms 32440 KB Output is correct
20 Incorrect 72 ms 29032 KB Output isn't correct
21 Halted 0 ms 0 KB -