답안 #909471

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
909471 2024-01-17T08:21:12 Z Faisal_Saqib 통행료 (APIO13_toll) C++17
16 / 100
3 ms 8796 KB
#include <iostream>
#include <vector>
#include <algorithm>
#define pb push_back
#define int long long
using namespace std;
const int N=1e5+10;
int par[N],mx_sz=0,mx_we=0;
pair<int,int> par1[N];
int h[N],sz1[N],val[N];
vector<pair<int,int>> ma[N],ch[N];
void root_at(int x,int p=-1)
{
    sz1[x]=val[x];
    for(auto [w,y]:ma[x])
    {
        if(y!=p)
        {
            h[y]=h[x]+1;
            par1[y]={w,x};
            root_at(y,x);
            sz1[x]+=sz1[y];
        }
    }
}
// void find_mx(int x,int r,int mx=0,int p=-1)
// {
//     if(x==r)
//     {
//         // We fc
//         sz=0;
//         return;
//     }
//     for(auto [w,y]:ma[x])
//     {
//         if(y!=p)
//         {
//             find_mx(y,r,max(mx,w),x);
//         }
//     }
// }
int root(int x)
{
    return (par[x]==x?x:par[x]=root(par[x]));
}
bool join(int x,int y)
{
    x=root(x);
    y=root(y);
    if(x!=y)
    {
        par[x]=y;
        return 1;
    }
    return 0;
}
signed main()
{
    int n,m,k;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)
        par[i]=i;
    vector<vector<int>> edg;
    for(int j=0;j<m;j++)
    {
        int w,x,y;
        cin>>x>>y>>w;
        edg.pb({w,x,y});
    }
    sort(begin(edg),end(edg));
    for(auto fp:edg)
    {
        if(join(fp[1],fp[2]))
        {
            ma[fp[1]].push_back({fp[0],fp[2]});
            ma[fp[2]].push_back({fp[0],fp[1]});
        }
    }
    vector<pair<int,int>> st;
    while(k--)
    {
        int x,y;
        cin>>x>>y;
        st.pb({x,y});
    }
    for(int i=1;i<=n;i++)
        cin>>val[i];
    root_at(1);
    mx_sz=0;
    mx_we=-1e9;
    for(auto [x,y]:st)
    {
        while(x!=y)
        {
            if(h[x]<h[y])
            {
                if(par1[y].first>mx_we)
                {
                    mx_we=par1[y].first;
                    mx_sz=sz1[y];
                }
                else if(par1[y].first==mx_we)
                {
                    mx_sz=max(mx_sz,sz1[y]);
                }
                y=par1[y].second;
            }
            else
            {
                if(par1[x].first>mx_we)
                {
                    mx_we=par1[x].first;
                    mx_sz=sz1[x];
                }
                else if(par1[x].first==mx_we)
                {
                    mx_sz=max(mx_sz,sz1[x]);
                }
                x=par1[x].second;
            }
        }
    }
    cout<<mx_we*mx_sz<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Incorrect 3 ms 8796 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Incorrect 3 ms 8796 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Incorrect 3 ms 8796 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Incorrect 3 ms 8796 KB Output isn't correct
4 Halted 0 ms 0 KB -