답안 #137087

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
137087 2019-07-27T05:05:38 Z ksmzzang2003 철도 요금 (JOI16_ho_t3) C++14
12 / 100
131 ms 20216 KB
#include <bits/stdc++.h>
#define maxn 100009
using namespace std;
typedef pair <int,int> pii;
int N,M,Q,query[maxn],ans[maxn],dp[maxn];
vector <int> adj[maxn];
vector <pii> adj2[maxn];
pii edge[maxn],dist[maxn];
int main() {
    scanf("%d%d%d",&N,&M,&Q);
    for(int i=1; i<=M; i++) {
        int u,v;
        scanf("%d%d",&u,&v);
        adj[u].push_back(v);
        adj[v].push_back(u);
        edge[i] = pii(u,v);
    }
    for(int i=1; i<=Q; i++) {
        int x;
        scanf("%d",&x) ;
        query[x] = i;
    }
    for(int i=1; i<=N; i++)
        dist[i] = pii(-1,i);
    queue <int> q;
    dist[1] .first=0 ;
    q.push(1);
    while(!q.empty()) {
        int x = q.front(); q.pop();
        for(int next:adj[x]){
            if(dist[next].first!=-1) continue;
            dist[next]. first = dist[x].first +1;
            q.push(next);
        }
    }
    for(int i=1;i<=M;i++){
        pii now = edge[i];
        int t = 1987654321;
        if(query[i]) t=query[i] ;
        if(dist[now.first].first+1 == dist[now.second].first) adj2[now.second].push_back(pii(now.first,t));
        else if(dist[now.second].first+1 == dist[now.first].first) adj2[now.first].push_back(pii(now.second,t));
    }
    sort(dist+1,dist+1+N);
    dp[1] = 1987654321;
    for(int i=2;i<=N;i++){
        int now = dist[i].second;
        for(pii next:adj2[now]) dp[now] = max(dp[now],min(dp[next.first],next.second));
        if(dp[now]<987654321) ans[dp[now]]++;
    }
    for(int i=1;i<=Q;i++) ans[i]+=ans[i-1],printf("%d\n",ans[i]);
}

Compilation message

2016_ho_t3.cpp: In function 'int main()':
2016_ho_t3.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d",&N,&M,&Q);
     ~~~~~^~~~~~~~~~~~~~~~~~~
2016_ho_t3.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&u,&v);
         ~~~~~^~~~~~~~~~~~~~
2016_ho_t3.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&x) ;
         ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 6 ms 5112 KB Output is correct
3 Correct 7 ms 5240 KB Output is correct
4 Correct 6 ms 4984 KB Output is correct
5 Correct 6 ms 5112 KB Output is correct
6 Correct 6 ms 4984 KB Output is correct
7 Correct 6 ms 5112 KB Output is correct
8 Correct 7 ms 5112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 6 ms 5112 KB Output is correct
3 Correct 7 ms 5240 KB Output is correct
4 Correct 6 ms 4984 KB Output is correct
5 Correct 6 ms 5112 KB Output is correct
6 Correct 6 ms 4984 KB Output is correct
7 Correct 6 ms 5112 KB Output is correct
8 Correct 7 ms 5112 KB Output is correct
9 Runtime error 124 ms 20216 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 131 ms 20128 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 6 ms 5112 KB Output is correct
3 Correct 7 ms 5240 KB Output is correct
4 Correct 6 ms 4984 KB Output is correct
5 Correct 6 ms 5112 KB Output is correct
6 Correct 6 ms 4984 KB Output is correct
7 Correct 6 ms 5112 KB Output is correct
8 Correct 7 ms 5112 KB Output is correct
9 Runtime error 124 ms 20216 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Halted 0 ms 0 KB -