# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
447923 |
2021-07-28T07:54:27 Z |
idas |
Toll (BOI17_toll) |
C++17 |
|
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];
set<int> que[N];
void dfs(int u, int tot, set<int> ar)
{
for(auto it : que[u]){
if(ar.count(it)){
ans[it]=min(ans[it], tot);
}
else{
ar.insert(it);
}
}
for(auto [x, w]: ad[u]){
dfs(x, tot+w, ar);
}
}
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].insert(i+1);
que[b].insert(i+1);
st.insert(a);
}
fill(ans, ans+o+1, INF);
for(auto it : st){
set<int> mt;
dfs(it, 0, mt);
}
FOR(i, 1, o+1)
{
cout << (ans[i]==INF?-1:ans[i]) << "\n";
}
}
Compilation message
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 |
1868 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
1868 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
972 KB |
Output is correct |
2 |
Correct |
1 ms |
972 KB |
Output is correct |
3 |
Correct |
1 ms |
972 KB |
Output is correct |
4 |
Correct |
1 ms |
972 KB |
Output is correct |
5 |
Correct |
1 ms |
972 KB |
Output is correct |
6 |
Correct |
2 ms |
1100 KB |
Output is correct |
7 |
Execution timed out |
3079 ms |
2124 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
972 KB |
Output is correct |
2 |
Correct |
1 ms |
972 KB |
Output is correct |
3 |
Correct |
1 ms |
972 KB |
Output is correct |
4 |
Correct |
1 ms |
972 KB |
Output is correct |
5 |
Correct |
1 ms |
972 KB |
Output is correct |
6 |
Correct |
2 ms |
1100 KB |
Output is correct |
7 |
Execution timed out |
3079 ms |
2124 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
1868 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |