Submission #522672

# Submission time Handle Problem Language Result Execution time Memory
522672 2022-02-05T11:25:10 Z lucri Sightseeing (NOI14_sightseeing) C++17
0 / 25
3500 ms 145868 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long n,m,q,x,y,c,ans[500010],t[500010];
vector<pair<long long,pair<long long,long long>>>a;
vector<vector<int>>f;
bool ok[500010];
int tata(int x)
{
    if(x==t[x]) return t[x];
    t[x]=tata(t[x]);
    return t[x];
}
void atribuire(int nod)
{
    ans[nod]=ans[1];
    for(auto z:f[nod])
    {
        if(ok[z]==false)
        {
            ok[z]=true;
            atribuire(z);
        }
    }
}
void combinare(int x,int y,int c)
{
    if(tata(x)==1&&tata(y)!=1)
    {
        t[y]=1;
        f[1].push_back(y);
        ans[1]=c;
        atribuire(t[y]);
        return;
    }
    swap(x,y);
    if(tata(x)==1&&tata(y)!=1)
    {
        t[y]=1;
        f[1].push_back(y);
        ans[1]=c;
        atribuire(t[y]);
        return;
    }
    t[x]=t[y];
    f[t[x]].push_back(x);
}
int main()
{
    cin>>n>>m>>q;
    a.resize(n+5);
    f.resize(n+5);
    for(long long i=1;i<=m;++i)
    {
        cin>>x>>y>>c;
        a.push_back(make_pair(-c,make_pair(x,y)));
    }
    for(int i=1;i<=n;++i)
    {
        t[i]=i;
    }
    sort(a.begin(),a.end());
    for(int i=0;i<m;++i)
    {
        combinare(a[i].second.first,a[i].second.second,-a[i].first);
    }
    for(long long i=1;i<=q;++i)
    {
        cin>>x;
        cout<<ans[x]<<'\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 59 ms 4432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3570 ms 145868 KB Time limit exceeded
2 Halted 0 ms 0 KB -