It's been a long time and it seems like they have completely forgotten that they need to rollback and recalculate ratings after plag check.Its been a month.
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 160 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | Dominater069 | 154 |
8 | awoo | 154 |
10 | luogu_official | 150 |
It's been a long time and it seems like they have completely forgotten that they need to rollback and recalculate ratings after plag check.Its been a month.
// this code doesnt work unless you comment the lines 71-73 part...
// proof:
/*
input
5 5
1 2 1
2 3 1
3 4 1
4 5 1
1 5 1000
1
then input
5 5
1 5 1000
1 2 1
2 3 1
3 4 1
4 5 1
1
if you un-comment the lines, both output differently.
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v) (v).begin(), (v).end()
#define endl '\n'
#define MOD 1000000007
ll mod(ll a) {
return (a%MOD + MOD)%MOD;
}
ll binpow(ll x, ll n) {
if (n == 0) {
return 1;
}
if (x == 0) {
return 0;
}
if (n%2 == 0) {
ll temp = binpow(x,n/2);
return mod(temp*temp);
}
return mod(mod(x)*binpow(x,n-1));
}
void print(bool& ans) { cout << (ans ? "YES" : "NO") << endl; }
// now we have weights(positive). Had weights were negative, we couldnot have used it.
#define f first
#define s second
vector<vector<pair<ll,ll>>> adj;
vector<ll> vis, dis;
void sssp(int src) {
dis[src] = 0;
queue<ll> q;
q.push(src);
while (!q.empty()) {
int node = q.front();
q.pop();
// if (vis[node]) { // the code works when you comment this part, because now for every time a node is pushed, it checks for distance.
// continue;
// }
vis[node] = 1;
for (auto &x:adj[node]) {
if (dis[x.f] > dis[node] + x.s) {
dis[x.f] = dis[node] + x.s;
q.push(x.f);
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
adj = vector<vector<pair<ll,ll>>> (n+1);
vis = vector<ll> (n+1,0);
dis = vector<ll> (n+1,1e9);
for (int i = 0; i < m; i++) {
int a, b, w;
cin >> a >> b >> w;
adj[a].push_back({b,w});
adj[b].push_back({a,w});
}
int src;
cin >> src;
sssp(src);
for (int i = 1; i <= n; i++) {
cout << i << ": " << dis[i] << endl;
}
return 0;
}
WHAT IS THE TIME COMPLEXITY OF THIS APPROACH? IS THIS BETTER THAN OTHER SSSP ALGORITHMS?
Name |
---|