답안 #29480

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
29480 2017-07-19T13:04:55 Z samir_droubi 관광 (NOI14_sightseeing) C++14
0 / 25
3500 ms 111232 KB
#include <bits/stdc++.h>
using namespace std;
int n,m,q;
const int mxn=(5e5)+5;
vector<pair<int,int> >gr[mxn];
int ans[mxn];
int mn=(1e9);
vector<int>e[mxn];
queue<int>qq;
void bfs()
{
    while(!qq.empty())
    {
        int v=qq.front();
        qq.pop();
        for(int i=0;i<gr[v].size();++i)
        {
            int u=gr[v][i].first;
            int w=gr[v][i].second;
            if(ans[u]!=-1)continue;
            if(w>=mn)ans[u]=mn,qq.push(u);
            else e[w].push_back(u);
        }
    }
}
int main()
{
    scanf("%d%d%d",&n,&m,&q);
    for(int i=0;i<m;++i)
    {
        int x,y,w;
        scanf("%d%d%d",&x,&y,&w);
        gr[x].push_back({y,w});
        gr[y].push_back({x,w});
    }
    memset(ans,-1,sizeof ans);
    return 0;
    ans[1]=(1e9);
    qq.push(1);
    bfs();

    for(int i=(1e5);i>=0;--i)
    {
        mn=i;
        for(int j=0;j<e[i].size();++j)
        {
            int v=e[i][j];
            if(ans[v]!=-1)continue;
            ans[v]=i;
            qq.push(v);
        }
        bfs();
    }
    while(q--)
    {
        int x;
        scanf("%d",&x);
        printf("%d\n",ans[x]);
    }
    return 0;
}

Compilation message

sightseeing.cpp: In function 'void bfs()':
sightseeing.cpp:16:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<gr[v].size();++i)
                      ^
sightseeing.cpp: In function 'int main()':
sightseeing.cpp:45:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<e[i].size();++j)
                      ^
sightseeing.cpp:28:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d",&n,&m,&q);
                             ^
sightseeing.cpp:32:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d",&x,&y,&w);
                                 ^
sightseeing.cpp:57:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&x);
                       ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 27412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 27544 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 49 ms 29128 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3500 ms 111232 KB Execution timed out
2 Halted 0 ms 0 KB -