QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#325441 | #5613. Road To Savings | ape_pack | WA | 1ms | 3872kb | C++14 | 2.7kb | 2024-02-11 12:53:36 | 2024-02-11 12:53:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = a; i >= b; i--)
#define F0Rd(i,a) for (int i = a; i >= 0; i--)
#define FORit(it,a) for (auto it = a.begin(); it != a.end(); it++)
#define trav(a,x) for (auto& a: x)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define alla(arr, sz) arr, arr + sz
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 }; // for every grid problem!!
const ll linf = 4*1e18;
const int inf = 1000000007;
namespace io {
void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}
}
using namespace io;
#define DEBUG 0
int start, finish;
vector<vector<pii>> parent;
vector<bool> visited;
int sum_pave;
void dfs(int v) {
if (v == start) return;
visited[v] = 1;
trav(x,parent[v]) {
sum_pave += x.ss;
if (!visited[x.ff]) dfs(x.ff);
}
}
void solve() {
int n, m; cin >> n >> m >> start >> finish; start--; finish--;
vector<pii> adj[n];
int sum_all_edges = 0;
F0R(i,m) {
int a, b, c; cin>> a >> b >> c;
a--; b--;
sum_all_edges += c;
adj[a].pb(mp(b,c));
adj[b].pb(mp(a,c));
}
parent.resize(n);
ll dist[n];
dist[0] = 0;
FOR(i,1,n) dist[i] = linf;
set<pll> s; // (cost, to)
s.insert(mp(0,0));
while (s.size() != 0) {
pll p = *s.begin();
s.erase(s.begin());
ll v = p.ss, c = p.ff;
trav(x, adj[v]) {
int to = x.ff, cost = x.ss;
ll new_price = c + cost;
if (new_price < dist[to]) {
s.erase(mp(dist[to], to));
dist[to] = new_price;
s.insert(mp(dist[to], to));
parent[to].clear();
parent[to].pb(mp(v,cost));
}
else if (new_price == dist[to]) {
parent[to].pb(mp(v,cost));
}
}
}
visited.assign(n,0);
sum_pave = 0;
dfs(finish);
cout << sum_all_edges - sum_pave;
}
int main() {
#if DEBUG
setIn("test.in");
#else
setIO();
#endif
int t;
t= 1;
//cin >> t;
while (t--)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
input:
4 5 1 4 1 2 1 1 3 2 1 4 2 4 2 1 3 4 1
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
4 5 1 4 1 2 1 1 3 2 1 4 1 4 2 1 3 4 1
output:
5
result:
ok single line: '5'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
2 1 1 2 1 2 10
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
3 3 1 2 1 2 10 2 3 10 3 1 10
output:
20
result:
ok single line: '20'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
3 3 1 2 1 2 10 2 3 5 3 1 5
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3684kb
input:
100 4950 74 24 1 2 8 1 3 6 1 4 5 1 5 6 1 6 2 1 7 6 1 8 1 1 9 10 1 10 1 1 11 10 1 12 9 1 13 4 1 14 4 1 15 1 1 16 4 1 17 7 1 18 8 1 19 1 1 20 7 1 21 2 1 22 9 1 23 9 1 24 7 1 25 6 1 26 5 1 27 4 1 28 3 1 29 4 1 30 6 1 31 8 1 32 10 1 33 10 1 34 3 1 35 6 1 36 10 1 37 5 1 38 4 1 39 1 1 40 10 1 41 9 1 42 7 ...
output:
27615
result:
ok single line: '27615'
Test #7:
score: -100
Wrong Answer
time: 0ms
memory: 3672kb
input:
40 780 6 12 1 2 100 1 3 100 1 4 100 1 5 100 1 6 100 1 7 100 1 8 100 1 9 100 1 10 100 1 11 100 1 12 100 1 13 100 1 14 100 1 15 100 1 16 100 1 17 100 1 18 100 1 19 100 1 20 1 1 21 100 1 22 100 1 23 100 1 24 100 1 25 100 1 26 1 1 27 100 1 28 100 1 29 100 1 30 100 1 31 100 1 32 100 1 33 100 1 34 100 1 3...
output:
74123
result:
wrong answer 1st lines differ - expected: '74100', found: '74123'