답안 #472581

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
472581 2021-09-13T18:35:09 Z ZaZo_ Toll (BOI17_toll) C++14
25 / 100
3000 ms 7064 KB
#include <bits/stdc++.h>
#define ZAZO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
using namespace std;
vector<pair<int,int>>edges[50001];
int k , n , m , o ;
int dist[50001];
void prepare()
{
  for(int i = 0 ; i < n+1 ; i ++) dist[i]=1e15;
}
void djk(int s , int e)
{
  priority_queue<pair<int,int>>pq;
  dist[s]=0;
  pq.push({0,s});
  while(!pq.empty())
  {
    int c = -pq.top().first , u = pq.top().second;
    pq.pop();
    for(int i = 0 ; i < edges[u].size() ; i++)
    {
      if(dist[edges[u][i].first] > dist[u] + edges[u][i].second)
      {
        dist[edges[u][i].first] = dist[u] + edges[u][i].second;
        pq.push({-dist[edges[u][i].first],edges[u][i].first});
      }
    }
  }
}
int32_t main() {
  ZAZO
  cin >> k >> n >> m >> o ;
  int pref[50011];
  for(int i = 0 ; i <= 50001 ; i ++) pref[i]=-1e9;
  for(int i = 0 ; i < m ; i ++)
  {
    int a , b , t;
    cin >> a >> b >> t;
    edges[a].push_back({b,t});
    pref[b]=t;
  }
  if(k!=1){
  vector<pair<int,pair<int,int>>>v;
  for(int i = 0 ; i < o ; i ++)
  {
    int a , b;
    cin >> a >> b;
    v.push_back({i,{min(a,b),max(a,b)}});
  }
  sort(v.begin(),v.end());
  int ans[o];
  for(int i = 0 ; i < o ; i ++) ans[i]=-1;
  for(int i = 0 ; i < v.size() ; i++)
  {
    if(i && v[i].second.first == v[i-1].second.first)
    {
      if(dist[v[i].second.second] != 1e15) ans[v[i].first]=dist[v[i].second.second];
    }
    else
    {
      prepare();
      djk(v[i].second.first , v[i].second.second);
      if(dist[v[i].second.second]!=1e15)
        ans[v[i].first] = dist[v[i].second.second];
    }
  }
  for(int i = 0 ; i < o ; i++)
  cout<<ans[i]<<endl;
  }
  else
  {
      for(int i = 1  ; i <= 50001 ; i++)
      {
        pref[i]+=pref[i-1];
      }
      for(int i = 0 ; i < o ; i ++)
      {
        int a , b;
        cin>>a>>b;
        if(pref[b]-pref[a]<=0) cout<<"-1"<<endl;
        else cout<<pref[b]-pref[a]<<endl;
      }
  }
}

Compilation message

toll.cpp: In function 'void djk(long long int, long long int)':
toll.cpp:21:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(int i = 0 ; i < edges[u].size() ; i++)
      |                     ~~^~~~~~~~~~~~~~~~~
toll.cpp:19:9: warning: unused variable 'c' [-Wunused-variable]
   19 |     int c = -pq.top().first , u = pq.top().second;
      |         ^
toll.cpp: In function 'int32_t main()':
toll.cpp:54:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   for(int i = 0 ; i < v.size() ; i++)
      |                   ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 3532 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 2 ms 1868 KB Output is correct
5 Correct 4 ms 1868 KB Output is correct
6 Correct 3 ms 1868 KB Output is correct
7 Correct 4 ms 1896 KB Output is correct
8 Correct 49 ms 4284 KB Output is correct
9 Correct 40 ms 4172 KB Output is correct
10 Correct 19 ms 2008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 5220 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 2 ms 1868 KB Output is correct
4 Correct 1 ms 1868 KB Output is correct
5 Correct 1 ms 1868 KB Output is correct
6 Correct 1 ms 1868 KB Output is correct
7 Correct 19 ms 1932 KB Output is correct
8 Correct 20 ms 2448 KB Output is correct
9 Correct 38 ms 3380 KB Output is correct
10 Correct 81 ms 6664 KB Output is correct
11 Correct 68 ms 5384 KB Output is correct
12 Correct 51 ms 4740 KB Output is correct
13 Correct 75 ms 7064 KB Output is correct
14 Correct 46 ms 4840 KB Output is correct
15 Correct 39 ms 4300 KB Output is correct
16 Correct 40 ms 4304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1868 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 1 ms 1868 KB Output is correct
5 Correct 1 ms 1868 KB Output is correct
6 Correct 2 ms 1868 KB Output is correct
7 Correct 7 ms 1868 KB Output is correct
8 Correct 14 ms 1996 KB Output is correct
9 Correct 10 ms 1996 KB Output is correct
10 Correct 26 ms 3392 KB Output is correct
11 Correct 345 ms 4652 KB Output is correct
12 Correct 416 ms 6188 KB Output is correct
13 Correct 511 ms 6624 KB Output is correct
14 Correct 386 ms 5424 KB Output is correct
15 Correct 276 ms 4108 KB Output is correct
16 Correct 246 ms 4096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1868 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 1 ms 1868 KB Output is correct
5 Correct 1 ms 1868 KB Output is correct
6 Correct 2 ms 1868 KB Output is correct
7 Correct 7 ms 1868 KB Output is correct
8 Correct 14 ms 1996 KB Output is correct
9 Correct 10 ms 1996 KB Output is correct
10 Correct 26 ms 3392 KB Output is correct
11 Correct 345 ms 4652 KB Output is correct
12 Correct 416 ms 6188 KB Output is correct
13 Correct 511 ms 6624 KB Output is correct
14 Correct 386 ms 5424 KB Output is correct
15 Correct 276 ms 4108 KB Output is correct
16 Correct 246 ms 4096 KB Output is correct
17 Execution timed out 3061 ms 4952 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 3532 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 2 ms 1868 KB Output is correct
5 Correct 4 ms 1868 KB Output is correct
6 Correct 3 ms 1868 KB Output is correct
7 Correct 4 ms 1896 KB Output is correct
8 Correct 49 ms 4284 KB Output is correct
9 Correct 40 ms 4172 KB Output is correct
10 Correct 19 ms 2008 KB Output is correct
11 Correct 60 ms 5220 KB Output is correct
12 Correct 1 ms 1868 KB Output is correct
13 Correct 2 ms 1868 KB Output is correct
14 Correct 1 ms 1868 KB Output is correct
15 Correct 1 ms 1868 KB Output is correct
16 Correct 1 ms 1868 KB Output is correct
17 Correct 19 ms 1932 KB Output is correct
18 Correct 20 ms 2448 KB Output is correct
19 Correct 38 ms 3380 KB Output is correct
20 Correct 81 ms 6664 KB Output is correct
21 Correct 68 ms 5384 KB Output is correct
22 Correct 51 ms 4740 KB Output is correct
23 Correct 75 ms 7064 KB Output is correct
24 Correct 46 ms 4840 KB Output is correct
25 Correct 39 ms 4300 KB Output is correct
26 Correct 40 ms 4304 KB Output is correct
27 Correct 1 ms 1868 KB Output is correct
28 Correct 1 ms 1868 KB Output is correct
29 Correct 1 ms 1868 KB Output is correct
30 Correct 1 ms 1868 KB Output is correct
31 Correct 1 ms 1868 KB Output is correct
32 Correct 2 ms 1868 KB Output is correct
33 Correct 7 ms 1868 KB Output is correct
34 Correct 14 ms 1996 KB Output is correct
35 Correct 10 ms 1996 KB Output is correct
36 Correct 26 ms 3392 KB Output is correct
37 Correct 345 ms 4652 KB Output is correct
38 Correct 416 ms 6188 KB Output is correct
39 Correct 511 ms 6624 KB Output is correct
40 Correct 386 ms 5424 KB Output is correct
41 Correct 276 ms 4108 KB Output is correct
42 Correct 246 ms 4096 KB Output is correct
43 Execution timed out 3061 ms 4952 KB Time limit exceeded
44 Halted 0 ms 0 KB -