답안 #370793

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
370793 2021-02-24T16:17:23 Z alirezasamimi100 공장들 (JOI14_factories) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include <factories.h>
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma")
using namespace std;
using ll = long long int;
#define F first
#define S second
#define pb push_back
#define lc v<<1
#define rc v<<1|1
#define fast_io ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int N=5e5+10,LN=20,M=2e2+10,SQ=250,inf=1e9;
const ll INF=1e18;
const int MOD=1000000007 /*998244353*/;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using pll=pair<ll,ll>;
using pii=pair<int,int>;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
ll pow(ll x, ll y, ll mod){
    ll ans=1;
    while (y != 0) {
        if (y & 1) ans = ans * x % mod;
        y >>= 1;
        x = x * x % mod;
    }
    return ans;
}
ll n,h[N],H[N],p[LN][N],st[N],t,q,mp[N],di[N];
vector<pll> adj[N];
vector<ll> z;
stack<ll> s;
priority_queue<pll> pq;
void dfs(ll v, ll P=0){
    p[0][v]=P;
    st[v]=++t;
    for(auto [u,w] : adj[v]){
        if(u!=P) H[u]=H[v]+1,h[u]=h[v]+w,dfs(u,v);
    }
}
bool cmp(ll a, ll b){
    return st[a]<st[b];
}
ll LCA(ll v, ll u){
    if(H[u]<H[v]) swap(v,u);
    for(ll i=LN; i--;){
        if(H[p[i][u]]>=H[v]) u=p[i][u];
    }
    if(v==u) return v;
    for(ll i=LN; i--;){
        if(p[i][u]!=p[i][v]) u=p[i][u],v=p[i][v];
    }
    return p[0][v];
}
ll dist(ll v, ll u){
    ll z=LCA(v,u);
    return h[v]+h[u]-2*h[z];
}
void Init(int n, int A[], int B[], int D[]){
    fast_io;
    cin >> n;
    memset(di,63,sizeof di);
    memset(mp,-1,sizeof mp);
    for(ll i=0; i<n-1; i++){
        ll v=A[i],u=B[i],w=D[i];
        v++;
        u++;
        adj[v].pb({u,w});
        adj[u].pb({v,w});
    }
    dfs(H[1]=1);
    for(ll i=1; i<LN; i++)
        for(ll j=1; j<=n; j++)
            p[i][j]=p[i-1][p[i-1][j]];
}
ll Query(int S, int X[], int T, int Y[]){}
    ll x=S,y=T,ans;
    z.clear();
    while(!pq.empty()) pq.pop();
    while(!s.empty()) s.pop();
    for(ll i=0; i<x; i++){
      ll P=X[i];
      P++;
      z.pb(P);
      mp[P]=0;
    }
    for(ll i=0; i<y; i++){
      ll P=Y[i];
      P++;
      z.pb(P);
      mp[P]=1;
    }
    sort(z.begin(),z.end(),cmp);
    for(ll i=0; i<x+y-1; i++) z.pb(LCA(z[i],z[i+1]));
    z.pb(LCA(z[0],z[x+y-1]));
    sort(z.begin(),z.end(),cmp);
    z.resize(unique(z.begin(),z.end())-z.begin());
    s.push(z[0]);
    if(!mp[z[0]]) di[z[0]]=0,pq.push({0,z[0]});
    adj[z[0]].clear();
    for(ll i=1; i<z.size(); i++){
      adj[z[i]].clear();
      while(LCA(z[i],s.top())!=s.top()) s.pop();
      ll d=dist(s.top(),z[i]);
      adj[s.top()].pb({z[i],d});
      adj[z[i]].pb({s.top(),d});
      s.push(z[i]);
      if(!mp[z[i]]) di[z[i]]=0,pq.push({0,z[i]});
    }
    while(!pq.empty()){
      auto [d,v]=pq.top();
      pq.pop();
      d=-d;
      if(d!=di[v]) continue;
      if(mp[v]==1){
        ans=d;
        break;
    }
        for(auto [u,w] : adj[v]){
            if(d+w<di[u]) di[u]=d+w,pq.push({-di[u],u});
        }
    }
    for(ll i : z){
        mp[i]=-1;
        di[i]=di[0];
    }
    return ans;
}

Compilation message

factories.cpp: In function 'll Query(int, int*, int, int*)':
factories.cpp:82:42: warning: no return statement in function returning non-void [-Wreturn-type]
   82 | ll Query(int S, int X[], int T, int Y[]){}
      |                                          ^
factories.cpp: At global scope:
factories.cpp:12:11: error: 'second' was not declared in this scope
   12 | #define S second
      |           ^~~~~~
factories.cpp:83:10: note: in expansion of macro 'S'
   83 |     ll x=S,y=T,ans;
      |          ^
factories.cpp:84:5: error: 'z' does not name a type
   84 |     z.clear();
      |     ^
factories.cpp:85:5: error: expected unqualified-id before 'while'
   85 |     while(!pq.empty()) pq.pop();
      |     ^~~~~
factories.cpp:86:5: error: expected unqualified-id before 'while'
   86 |     while(!s.empty()) s.pop();
      |     ^~~~~
factories.cpp:87:5: error: expected unqualified-id before 'for'
   87 |     for(ll i=0; i<x; i++){
      |     ^~~
factories.cpp:87:17: error: 'i' does not name a type
   87 |     for(ll i=0; i<x; i++){
      |                 ^
factories.cpp:87:22: error: 'i' does not name a type
   87 |     for(ll i=0; i<x; i++){
      |                      ^
factories.cpp:93:5: error: expected unqualified-id before 'for'
   93 |     for(ll i=0; i<y; i++){
      |     ^~~
factories.cpp:93:17: error: 'i' does not name a type
   93 |     for(ll i=0; i<y; i++){
      |                 ^
factories.cpp:93:22: error: 'i' does not name a type
   93 |     for(ll i=0; i<y; i++){
      |                      ^
factories.cpp:99:9: error: expected constructor, destructor, or type conversion before '(' token
   99 |     sort(z.begin(),z.end(),cmp);
      |         ^
factories.cpp:100:5: error: expected unqualified-id before 'for'
  100 |     for(ll i=0; i<x+y-1; i++) z.pb(LCA(z[i],z[i+1]));
      |     ^~~
factories.cpp:100:17: error: 'i' does not name a type
  100 |     for(ll i=0; i<x+y-1; i++) z.pb(LCA(z[i],z[i+1]));
      |                 ^
factories.cpp:100:26: error: 'i' does not name a type
  100 |     for(ll i=0; i<x+y-1; i++) z.pb(LCA(z[i],z[i+1]));
      |                          ^
factories.cpp:101:5: error: 'z' does not name a type
  101 |     z.pb(LCA(z[0],z[x+y-1]));
      |     ^
factories.cpp:102:9: error: expected constructor, destructor, or type conversion before '(' token
  102 |     sort(z.begin(),z.end(),cmp);
      |         ^
factories.cpp:103:5: error: 'z' does not name a type
  103 |     z.resize(unique(z.begin(),z.end())-z.begin());
      |     ^
factories.cpp:104:5: error: 's' does not name a type
  104 |     s.push(z[0]);
      |     ^
factories.cpp:105:5: error: expected unqualified-id before 'if'
  105 |     if(!mp[z[0]]) di[z[0]]=0,pq.push({0,z[0]});
      |     ^~
factories.cpp:105:46: error: expected unqualified-id before ')' token
  105 |     if(!mp[z[0]]) di[z[0]]=0,pq.push({0,z[0]});
      |                                              ^
factories.cpp:106:5: error: 'adj' does not name a type
  106 |     adj[z[0]].clear();
      |     ^~~
factories.cpp:107:5: error: expected unqualified-id before 'for'
  107 |     for(ll i=1; i<z.size(); i++){
      |     ^~~
factories.cpp:107:17: error: 'i' does not name a type
  107 |     for(ll i=1; i<z.size(); i++){
      |                 ^
factories.cpp:107:29: error: 'i' does not name a type
  107 |     for(ll i=1; i<z.size(); i++){
      |                             ^
factories.cpp:116:5: error: expected unqualified-id before 'while'
  116 |     while(!pq.empty()){
      |     ^~~~~
factories.cpp:129:5: error: expected unqualified-id before 'for'
  129 |     for(ll i : z){
      |     ^~~
factories.cpp:133:5: error: expected unqualified-id before 'return'
  133 |     return ans;
      |     ^~~~~~
factories.cpp:134:1: error: expected declaration before '}' token
  134 | }
      | ^