# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
447908 |
2021-07-28T06:55:13 Z |
idas |
Toll (BOI17_toll) |
C++11 |
|
3000 ms |
2124 KB |
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define SZ(x) ((int)((x).size()))
#define LE(vec) vec[vec.size()-1]
#define TSTS int t; cin >> t; while(t--)solve()
const int INF = 1e9;
const long long LINF = 1e18;
const long double PI = asin(1)*2;
const int MOD = 1e9+7;
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef long long ll;
typedef long double ld;
void setIO()
{
FAST_IO;
}
void setIO (string s) {
setIO();
freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str(),"w",stdout);
}
const int N=1e4+10;
int k, n, m, o, ans[N];
vector<pii> ad[N];
vi que[N];
void dfs(int u, int tot, vi ar)
{
int in=0;
vi nw;
set<int> tmp;
FOR(i, 0, (int)que[u].size())
{
int x=que[u][i], y=-1;
tmp.insert(x);
while(in<(int)ar.size() && ar[in]<x){
tmp.insert(ar[in]);
in++;
}
if(in<(int)ar.size()) y=ar[in];
if(x==y){
ans[x]=min(ans[x], tot);
}
}
while(in<(int)ar.size()){
tmp.insert(ar[in]);
in++;
}
for(auto x : tmp){
nw.PB(x);
}
for(auto [x, w]: ad[u]){
dfs(x, tot+w, nw);
}
}
int main()
{
setIO();
cin >> k >> n >> m >> o;
FOR(i, 0, m)
{
int a, b, c;
cin >> a >> b >> c;
ad[a].PB({b, c});
}
set<int> st;
FOR(i, 0, o)
{
int a, b;
cin >> a >> b;
que[a].PB(i+1);
que[b].PB(i+1);
st.insert(a);
}
FOR(i, 0, n) sort(que[i].begin(), que[i].end());
fill(ans, ans+o+1, INF);
for(auto it : st){
dfs(it, 0, {0});
}
FOR(i, 1, o+1)
{
cout << (ans[i]==INF?-1:ans[i]) << " ";
}
}
Compilation message
toll.cpp: In function 'void dfs(int, int, vi)':
toll.cpp:69:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
69 | for(auto [x, w]: ad[u]){
| ^
toll.cpp: In function 'void setIO(std::string)':
toll.cpp:31:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | freopen((s+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:32:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen((s+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
1356 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
1356 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
716 KB |
Output is correct |
2 |
Correct |
1 ms |
716 KB |
Output is correct |
3 |
Correct |
1 ms |
716 KB |
Output is correct |
4 |
Correct |
1 ms |
716 KB |
Output is correct |
5 |
Correct |
1 ms |
716 KB |
Output is correct |
6 |
Correct |
4 ms |
844 KB |
Output is correct |
7 |
Execution timed out |
3076 ms |
2124 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
716 KB |
Output is correct |
2 |
Correct |
1 ms |
716 KB |
Output is correct |
3 |
Correct |
1 ms |
716 KB |
Output is correct |
4 |
Correct |
1 ms |
716 KB |
Output is correct |
5 |
Correct |
1 ms |
716 KB |
Output is correct |
6 |
Correct |
4 ms |
844 KB |
Output is correct |
7 |
Execution timed out |
3076 ms |
2124 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
1356 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |