Submission #45643786
Source Code Expand
//Author : silenttkillerr
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<algorithm>
#include<iostream>
#include<math.h>
#include<string>
#include<bitset>
#include<stdio.h>
#include<utility>
#include<queue>
#include<stack>
#include<deque>
#include<iterator>
#include<list>
#include<iomanip>
#include<chrono>
#include<unordered_set>
#include<string>
#include<cmath>
#include<cstring>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fast ios_base::sync_with_stdio(0),cin.tie(0)
#define ll long long
#define cout std::cout
#define cin std::cin
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define pb push_back
#define sorta(vec) sort(vec.begin(),vec.end())
#define sortd(vec) sort(vec.begin(),vec.end(),greater<int>())
#define pb push_back
#define vll vector<long long int>
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>pbds; // find_by_order, order_of_key(0-indexed)
//less , less_equal , greater , greater_equal -> rule for insertion
#define start_execution auto start = std::chrono::high_resolution_clock::now();
#define stop_execution auto stop = std::chrono::high_resolution_clock::now();
#define execution_time auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start); cerr<<"Time taken : "<<((long double)duration.count())/((long double)1e9) <<"s"<<endl;
#define nline "\n"
#define all(v) (v).begin(),(v).end()
#define pii pair<ll int,ll int>
#define piii pair<ll int,pair<ll int,ll int>>
void entry_check(){cout<<"Entered"<<endl;}
void _debugger_printer(int x)
{
cerr<<"[ "<<x<<" ]";
}
void _debugger_printer(ll int x)
{
cerr<<"[ "<<x<<" ]";
}
void _debugger_printer(string x)
{
cerr<<"[ "<<x<<" ]";
}
void _debugger_printer(char x)
{
cerr<<"[ "<<x<<" ]";
}
template<class T>void _debugger_printer(vector<T>x)
{
cerr<<"[ ";
for(T y:x)
{
_debugger_printer(y);
}
cerr<<"]";
}
#ifndef ONLINE_JUDGE
#define debug(x) cerr<<#x<<" ";_debugger_printer(x);cerr<<endl;
#else
#define debug(x)
#endif
void yn(bool res){if(res==true){yes;}else{no;}}
const ll mod=1000000007;
//const ll mod=998244353;
ll mod_add(ll a, ll b) {a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;}
ll mod_mul(ll a, ll b) {a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;}
ll mod_sub(ll a, ll b) {a = a % mod; b = b % mod; return (((a - b) % mod) + mod) % mod;}
ll int inv(ll int r)
{
if(r==1) return 1;
return (mod-((mod/r)*inv(mod%r))%mod+mod)%mod;
}
ll mod_div(ll a,ll b){return (a*inv(b))%mod;}
ll int ceil_div(ll int a,ll int b)
{
ll int k=a%b;
if(k>0) return (a/b)+1;
return a/b;
}
ll gcd(ll a, ll b)
{
if (!a)
return b;
return gcd(b % a, a);
}
ll int lcm(ll int a,ll int b)
{
ll int g=__gcd(a,b);
return (1LL*a*b)/g;
}
ll int pwr(ll int a,ll int b)
{
if(b==0)
return 1;
if(b%2==0){ll int ans1=pwr(a,b/2);ll int ans2=(ans1*ans1)%mod;return ans2;}
ll int ans1=pwr(a,b/2);ll int ans2=(ans1*ans1)%mod;
ans2=(ans2*a)%mod;
return ans2;
}
vector<ll> sieve(int n)
{
int*arr = new int[n + 1]();
vector<ll> vect;
for (int i = 2; i <= n; i++)
if (arr[i] == 0)
{
vect.push_back(i);
for (int j = 2 * i; j <= n; j += i)
arr[j] = 1;
}
return vect;
}
template<class ForwardIterator>
void read(ForwardIterator first,ForwardIterator last)
{
while (first != last)
{
cin >> (*first);
++first;
}
}
template<class T>
void read(vector<T> &v)
{
read(v.begin(), v.end());
}
template<class T>
void read1(vector<T>&v)
{
for(int i=1;i<v.size();i++)
{
cin>>v[i];
}
}
bool cmp(vector<int>&v1,vector<int>&v2)
{
if(v1.size()<v2.size())
{
return true;
}
return false;
}
//code starts here
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
freopen("error.txt","w",stderr);
#endif
fast;
//start_execution
int tt=1;
//cin>>tt;
for(int tc=1;tc<=tt;tc++)
{
int n,m;
cin>>n>>m;
map<int,vector<vector<int>>>mp;
vector<vector<vector<int>>>graph(n+1);
while(m--)
{
int a,b,x,y;
cin>>a>>b>>x>>y;
//mp[a].push_back({b,x,y});
graph[a].push_back({b,x,y});
graph[b].push_back({a,-1*x,-1*y});
}
vector<int>dp(n+1,0);
dp[1]=1;
queue<int>q;
q.push(1);
bool res=true;
vector<pair<ll int,ll int>>ans(n+1,{1e11,1e11});
ans[1].first=0;
ans[1].second=0;
while(!q.empty())
{
auto node=q.front();
q.pop();
for(auto x:graph[node])
{
int cr=x[0];
if(dp[cr]==1)
{
continue;
}
if(ans[cr].first==1e18)
{
continue;
}
ll int nx=ans[node].first+x[1];
ll int ny=ans[node].second+x[2];
ans[cr].first=nx;
ans[cr].second=ny;
dp[cr]=1;
q.push(cr);
}
}
for(int i=1;i<=n;i++)
{
if(ans[i].first==1e11)
{
cout<<"undecidable"<<endl;
continue;
}
cout<<ans[i].first<<" "<<ans[i].second<<endl;
}
}
//stop_execution
//execution_time
return 0;
}
Submission Info
| Submission Time |
|
| Task |
D - Relative Position |
| User |
silenttkillerr |
| Language |
C++ 20 (gcc 12.2) |
| Score |
0 |
| Code Size |
5889 Byte |
| Status |
WA |
| Exec Time |
408 ms |
| Memory |
40652 KiB |
Compile Error
Main.cpp: In function ‘int main()’:
Main.cpp:193:14: warning: unused variable ‘res’ [-Wunused-variable]
193 | bool res=true;
| ^~~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
0 / 400 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
sample_01.txt, sample_02.txt, sample_03.txt |
| All |
random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, sample_01.txt, sample_02.txt, sample_03.txt |
| Case Name |
Status |
Exec Time |
Memory |
| random_01.txt |
AC |
408 ms |
38824 KiB |
| random_02.txt |
AC |
204 ms |
31544 KiB |
| random_03.txt |
AC |
395 ms |
38884 KiB |
| random_04.txt |
AC |
216 ms |
22844 KiB |
| random_05.txt |
AC |
373 ms |
38548 KiB |
| random_06.txt |
AC |
353 ms |
37400 KiB |
| random_07.txt |
AC |
254 ms |
25836 KiB |
| random_08.txt |
AC |
280 ms |
27400 KiB |
| random_09.txt |
AC |
362 ms |
40652 KiB |
| random_10.txt |
WA |
388 ms |
40312 KiB |
| random_11.txt |
AC |
2 ms |
3516 KiB |
| random_12.txt |
AC |
136 ms |
27824 KiB |
| sample_01.txt |
AC |
1 ms |
3368 KiB |
| sample_02.txt |
AC |
1 ms |
3516 KiB |
| sample_03.txt |
AC |
1 ms |
3508 KiB |